Skip to content

Commit a611814

Browse files
author
git apple-llvm automerger
committed
Merge commit 'cf5df40c4cf1' from llvm.org/master into apple/master
2 parents 05f5b41 + cf5df40 commit a611814

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,23 +2105,10 @@ void ModuleAddressSanitizer::InstrumentGlobalsELF(
21052105
SetComdatForGlobalMetadata(G, Metadata, UniqueModuleId);
21062106
}
21072107

2108-
// This should never be called when there are no globals, by the logic that
2109-
// computes the UniqueModuleId string, which is "" when there are no globals.
2110-
// It's important that this path is only used when there are actually some
2111-
// globals, because that means that there will certainly be a live
2112-
// `asan_globals` input section at link time and thus `__start_asan_globals`
2113-
// and `__stop_asan_globals` symbols will definitely be defined at link time.
2114-
// This means there's no need for the references to them to be weak, which
2115-
// enables better code generation because ExternalWeakLinkage implies
2116-
// isInterposable() and thus requires GOT indirection for PIC. Since these
2117-
// are known-defined hidden/dso_local symbols, direct PIC accesses without
2118-
// dynamic relocation are always sufficient.
2119-
assert(!MetadataGlobals.empty());
2120-
assert(!UniqueModuleId.empty());
2121-
21222108
// Update llvm.compiler.used, adding the new metadata globals. This is
21232109
// needed so that during LTO these variables stay alive.
2124-
appendToCompilerUsed(M, MetadataGlobals);
2110+
if (!MetadataGlobals.empty())
2111+
appendToCompilerUsed(M, MetadataGlobals);
21252112

21262113
// RegisteredFlag serves two purposes. First, we can pass it to dladdr()
21272114
// to look up the loaded image that contains it. Second, we can store in it
@@ -2134,18 +2121,15 @@ void ModuleAddressSanitizer::InstrumentGlobalsELF(
21342121
ConstantInt::get(IntptrTy, 0), kAsanGlobalsRegisteredFlagName);
21352122
RegisteredFlag->setVisibility(GlobalVariable::HiddenVisibility);
21362123

2137-
// Create start and stop symbols. These are known to be defined by
2138-
// the linker, see comment above.
2139-
auto MakeStartStopGV = [&](const char *Prefix) {
2140-
GlobalVariable *StartStop =
2141-
new GlobalVariable(M, IntptrTy, false, GlobalVariable::ExternalLinkage,
2142-
nullptr, Prefix + getGlobalMetadataSection());
2143-
StartStop->setVisibility(GlobalVariable::HiddenVisibility);
2144-
assert(StartStop->isImplicitDSOLocal());
2145-
return StartStop;
2146-
};
2147-
GlobalVariable *StartELFMetadata = MakeStartStopGV("__start_");
2148-
GlobalVariable *StopELFMetadata = MakeStartStopGV("__stop_");
2124+
// Create start and stop symbols.
2125+
GlobalVariable *StartELFMetadata = new GlobalVariable(
2126+
M, IntptrTy, false, GlobalVariable::ExternalWeakLinkage, nullptr,
2127+
"__start_" + getGlobalMetadataSection());
2128+
StartELFMetadata->setVisibility(GlobalVariable::HiddenVisibility);
2129+
GlobalVariable *StopELFMetadata = new GlobalVariable(
2130+
M, IntptrTy, false, GlobalVariable::ExternalWeakLinkage, nullptr,
2131+
"__stop_" + getGlobalMetadataSection());
2132+
StopELFMetadata->setVisibility(GlobalVariable::HiddenVisibility);
21492133

21502134
// Create a call to register the globals with the runtime.
21512135
IRB.CreateCall(AsanRegisterElfGlobals,

llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ target triple = "x86_64-unknown-linux-gnu"
2828
; during LTO.
2929
; CHECK: @llvm.compiler.used {{.*}} @__asan_global_global {{.*}} section "llvm.metadata"
3030

31-
; Check that start and stop symbols will be accessed as dso_local.
32-
; CHECK: @__start_asan_globals = external hidden global i64
33-
; CHECK: @__stop_asan_globals = external hidden global i64
34-
3531
; Check that location descriptors and global names were passed into __asan_register_globals:
3632
; CHECK: call void @__asan_register_elf_globals(i64 ptrtoint (i64* @___asan_globals_registered to i64), i64 ptrtoint (i64* @__start_asan_globals to i64), i64 ptrtoint (i64* @__stop_asan_globals to i64))
3733

0 commit comments

Comments
 (0)