Skip to content
Open
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
25 changes: 18 additions & 7 deletions clang/lib/Driver/OffloadBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ using namespace clang;

#define DEBUG_TYPE "clang-offload-bundler"

/// Return true if \p Name is a special bitcode symbol that must not be listed
/// in the target symbol table. Device sanitizer metadata globals carry a
/// per-module unique id suffix (e.g. "__AsanKernelMetadata_<id>"), so they are
/// matched by prefix.
static bool isSpecialBitcodeSymbol(StringRef Name) {
if (Name == "llvm.used" || Name == "llvm.compiler.used")
return true;

static constexpr StringRef SanitizerMetadataPrefixes[] = {
"__AsanDeviceGlobalMetadata", "__MsanDeviceGlobalMetadata",
"__TsanDeviceGlobalMetadata", "__AsanKernelMetadata",
"__MsanKernelMetadata", "__TsanKernelMetadata"};
return llvm::any_of(SanitizerMetadataPrefixes, [Name](StringRef Prefix) {
return Name.starts_with(Prefix);
});
}

OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
const OffloadBundlerConfig &BC)
: BundlerConfig(BC) {
Expand Down Expand Up @@ -751,13 +768,7 @@ class ObjectFileHandler final : public FileHandler {

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

// Add symbol name with the target prefix to the buffer.
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Driver/clang-offload-bundler-skip-for-symtbl.c.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
@__TsanDeviceGlobalMetadata = global i64 0
;CHECK-NOT: __TsanDeviceGlobalMetadata

; The sanitizer metadata globals carry a per-module unique id suffix, so the
; suffixed names must be skipped as well.
@__AsanKernelMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __AsanKernelMetadata_0123456789abcdef0123456789abcdef
@__MsanKernelMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __MsanKernelMetadata_0123456789abcdef0123456789abcdef
@__TsanKernelMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __TsanKernelMetadata_0123456789abcdef0123456789abcdef
@__AsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __AsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef
@__MsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __MsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef
@__TsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef = global i64 0
;CHECK-NOT: __TsanDeviceGlobalMetadata_0123456789abcdef0123456789abcdef

@not_skipping = global i64 0
;CHECK: not_skipping

Expand Down
Loading