Skip to content

Commit db31088

Browse files
authored
[clang-offload-bundler] Do not add "llvm.used" to the .tgtsym section (#3896)
This patch changes clang-offload-bundler to skip special globals llvm.used and llvm.compiler.used when collecting names of symbols that are defined in the device object if it is a bitcode file. Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent e45408a commit db31088

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

clang/test/Driver/clang-offload-bundler-tgtsym.c

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// CHECK-DAG: sycl-spir64.bar
1919
// CHECK-NOT: undefined_func
2020
// CHECK-NOT: static_func
21+
// CHECK-NOT: static_used
22+
// CHECK-NOT: sycl-spir64.llvm.used
23+
// CHECK-NOT: sycl-spir64.llvm.compiler.used
2124

2225
extern void undefined_func(void);
2326

@@ -31,3 +34,6 @@ static void static_func(void) {}
3134
void bar(void) {
3235
static_func();
3336
}
37+
38+
static void static_used(void) __attribute__((used));
39+
static void static_used() {}

clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,19 @@ class ObjectFileHandler final : public FileHandler {
644644
if (Undefined || !Global)
645645
continue;
646646

647-
// Add symbol name with the target prefix to the buffer.
648-
SymbolsOS << TargetNames[I] << ".";
649-
if (Error Err = Symbol.printName(SymbolsOS))
647+
// Get symbol name.
648+
std::string Name;
649+
raw_string_ostream NameOS(Name);
650+
if (Error Err = Symbol.printName(NameOS))
650651
return std::move(Err);
651-
SymbolsOS << '\0';
652+
653+
// If we are dealing with a bitcode file do not add special globals
654+
// llvm.used and llvm.compiler.used to the list of defined symbols.
655+
if (SF->isIR() && (Name == "llvm.used" || Name == "llvm.compiler.used"))
656+
continue;
657+
658+
// Add symbol name with the target prefix to the buffer.
659+
SymbolsOS << TargetNames[I] << "." << Name << '\0';
652660
}
653661
}
654662
return SymbolsBuf;

0 commit comments

Comments
 (0)