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

Commit 685852b

Browse files
committed
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
1 parent 3ddf92f commit 685852b

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/comgr/docs/ReleaseNotes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ prevented correct execution of
4949
COMPILE\_SOURCE\_WITH\_DEVICE\_LIBS\_TO\_BC action.
5050
- Fixed a multi-threading bug where programs would hang when calling Comgr APIs
5151
like amd\_comgr\_iterate\_symbols() from multiple threads
52+
- Fixed an issue where providing DataObjects with an empty name to the bitcode
53+
linking action caused errors when AMD\_COMGR\_SAVE\_TEMPS was enabled, or when
54+
linking bitcode bundles.
5255

5356

5457
New APIs
@@ -104,6 +107,9 @@ metadata querys for code object v2 objects.
104107
deprecation of code object v3 in LLVM. However, we still test loading and
105108
metadata querys for code object v3 objects.
106109
- Revamp symbolizer test to fail on errors, among other improvments
110+
- Improve linking and unbundling log to correctly store temporary files in /tmp,
111+
and to output clang-offload-bundler command to allow users to re-create Comgr
112+
unbundling.
107113

108114
New Targets
109115
-----------

lib/comgr/src/comgr-compiler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383

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

86+
#include <csignal>
87+
8688
using namespace llvm;
8789
using namespace llvm::opt;
8890
using namespace llvm::sys;
@@ -1167,6 +1169,18 @@ amd_comgr_status_t AMDGPUCompiler::linkBitcodeToBitcode() {
11671169
// Collect bitcode memory buffers from bitcodes, bundles, and archives
11681170
for (auto *Input : InSet->DataObjects) {
11691171

1172+
if (!strcmp(Input->Name, "")) {
1173+
// If the calling API doesn't provide a DataObject name, generate a random
1174+
// string to assign. This string is used when the DataObject is written
1175+
// to the file system via SAVE_TEMPS, or if the object is a bundle which
1176+
// also needs a file system write for unpacking
1177+
1178+
char *buf = (char *) malloc(sizeof(char) * 30);
1179+
sprintf(buf,"comgr-anon-bitcode-%d.bc", std::rand() % 10000);
1180+
1181+
Input->Name = buf;
1182+
}
1183+
11701184
if (env::shouldSaveTemps()) {
11711185
if (auto Status = outputToFile(Input,
11721186
StringRef(std::string("./comgr_tmp_") + Input->Name))) {

lib/comgr/test/unbundle_hip_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int main(int Argc, char *Argv[]) {
103103
checkError(Status, "amd_comgr_create_data");
104104
Status = amd_comgr_set_data(DataBitcode2, SizeBitcode2, BufBitcode2);
105105
checkError(Status, "amd_comgr_set_data");
106-
Status = amd_comgr_set_data_name(DataBitcode2, "double");
106+
Status = amd_comgr_set_data_name(DataBitcode2, ""); // test blank name
107107
checkError(Status, "amd_comgr_set_data_name");
108108
Status = amd_comgr_data_set_add(DataSetBundled, DataBitcode2);
109109
checkError(Status, "amd_comgr_data_set_add");

0 commit comments

Comments
 (0)