From 685852bc27113baeb45862dbf71b556e5be74290 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 15 May 2023 10:35:35 -0700 Subject: [PATCH] Generate a random name for bitcode linking when none is provided Comgr currently uses the DataObject name to write bitcodes to the file system, which happens whenever saving temporary files or unbundling files. If the name provided by the caller was empty, this led to errors. We now generate a "comgr-anon-bitcode-XXXX.bc" string, where XXXX is a randomly generated 3-digit number. Change-Id: Ia701fd17acfdc07fe5569a4e1bb25b2313ded20a --- lib/comgr/docs/ReleaseNotes.md | 6 ++++++ lib/comgr/src/comgr-compiler.cpp | 14 ++++++++++++++ lib/comgr/test/unbundle_hip_test.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/comgr/docs/ReleaseNotes.md b/lib/comgr/docs/ReleaseNotes.md index 45475f3..55e56df 100644 --- a/lib/comgr/docs/ReleaseNotes.md +++ b/lib/comgr/docs/ReleaseNotes.md @@ -49,6 +49,9 @@ prevented correct execution of COMPILE\_SOURCE\_WITH\_DEVICE\_LIBS\_TO\_BC action. - Fixed a multi-threading bug where programs would hang when calling Comgr APIs like amd\_comgr\_iterate\_symbols() from multiple threads +- Fixed an issue where providing DataObjects with an empty name to the bitcode +linking action caused errors when AMD\_COMGR\_SAVE\_TEMPS was enabled, or when +linking bitcode bundles. New APIs @@ -104,6 +107,9 @@ metadata querys for code object v2 objects. deprecation of code object v3 in LLVM. However, we still test loading and metadata querys for code object v3 objects. - Revamp symbolizer test to fail on errors, among other improvments +- Improve linking and unbundling log to correctly store temporary files in /tmp, +and to output clang-offload-bundler command to allow users to re-create Comgr +unbundling. New Targets ----------- diff --git a/lib/comgr/src/comgr-compiler.cpp b/lib/comgr/src/comgr-compiler.cpp index 8a5d600..d7cd401 100644 --- a/lib/comgr/src/comgr-compiler.cpp +++ b/lib/comgr/src/comgr-compiler.cpp @@ -83,6 +83,8 @@ #include "time-stat/ts-interface.h" +#include + using namespace llvm; using namespace llvm::opt; using namespace llvm::sys; @@ -1167,6 +1169,18 @@ amd_comgr_status_t AMDGPUCompiler::linkBitcodeToBitcode() { // Collect bitcode memory buffers from bitcodes, bundles, and archives for (auto *Input : InSet->DataObjects) { + if (!strcmp(Input->Name, "")) { + // If the calling API doesn't provide a DataObject name, generate a random + // string to assign. This string is used when the DataObject is written + // to the file system via SAVE_TEMPS, or if the object is a bundle which + // also needs a file system write for unpacking + + char *buf = (char *) malloc(sizeof(char) * 30); + sprintf(buf,"comgr-anon-bitcode-%d.bc", std::rand() % 10000); + + Input->Name = buf; + } + if (env::shouldSaveTemps()) { if (auto Status = outputToFile(Input, StringRef(std::string("./comgr_tmp_") + Input->Name))) { diff --git a/lib/comgr/test/unbundle_hip_test.c b/lib/comgr/test/unbundle_hip_test.c index 2e43542..5fca916 100644 --- a/lib/comgr/test/unbundle_hip_test.c +++ b/lib/comgr/test/unbundle_hip_test.c @@ -103,7 +103,7 @@ int main(int Argc, char *Argv[]) { checkError(Status, "amd_comgr_create_data"); Status = amd_comgr_set_data(DataBitcode2, SizeBitcode2, BufBitcode2); checkError(Status, "amd_comgr_set_data"); - Status = amd_comgr_set_data_name(DataBitcode2, "double"); + Status = amd_comgr_set_data_name(DataBitcode2, ""); // test blank name checkError(Status, "amd_comgr_set_data_name"); Status = amd_comgr_data_set_add(DataSetBundled, DataBitcode2); checkError(Status, "amd_comgr_data_set_add");