Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Generate a random name for bitcode linking when none is provided
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lamb-j committed Dec 8, 2023
1 parent 3ddf92f commit 685852b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/comgr/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-----------
Expand Down
14 changes: 14 additions & 0 deletions lib/comgr/src/comgr-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@

#include "time-stat/ts-interface.h"

#include <csignal>

using namespace llvm;
using namespace llvm::opt;
using namespace llvm::sys;
Expand Down Expand Up @@ -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))) {
Expand Down
2 changes: 1 addition & 1 deletion lib/comgr/test/unbundle_hip_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 685852b

Please sign in to comment.