Skip to content

[clang-offload-bundler] Do not add llvm.used to the .tgtsym section #3896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/test/Driver/clang-offload-bundler-tgtsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// CHECK-DAG: sycl-spir64.bar
// CHECK-NOT: undefined_func
// CHECK-NOT: static_func
// CHECK-NOT: static_used
// CHECK-NOT: sycl-spir64.llvm.used
// CHECK-NOT: sycl-spir64.llvm.compiler.used

extern void undefined_func(void);

Expand All @@ -31,3 +34,6 @@ static void static_func(void) {}
void bar(void) {
static_func();
}

static void static_used(void) __attribute__((used));
static void static_used() {}
16 changes: 12 additions & 4 deletions clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,19 @@ class ObjectFileHandler final : public FileHandler {
if (Undefined || !Global)
continue;

// Add symbol name with the target prefix to the buffer.
SymbolsOS << TargetNames[I] << ".";
if (Error Err = Symbol.printName(SymbolsOS))
// Get symbol name.
std::string Name;
raw_string_ostream NameOS(Name);
if (Error Err = Symbol.printName(NameOS))
return std::move(Err);
SymbolsOS << '\0';

// If we are dealing with a bitcode file do not add special globals
// llvm.used and llvm.compiler.used to the list of defined symbols.
if (SF->isIR() && (Name == "llvm.used" || Name == "llvm.compiler.used"))
continue;

// Add symbol name with the target prefix to the buffer.
SymbolsOS << TargetNames[I] << "." << Name << '\0';
}
}
return SymbolsBuf;
Expand Down