Skip to content

Commit

Permalink
[TargetMachine] Set dso_local if asan is detected
Browse files Browse the repository at this point in the history
AddressSanitizer instrumentation does not set dso_local on non-thread-local
global variables in -fno-pic and it seems to rely on implied dso_local to work.
Add a hack until we have fixed AddressSanitizer to call setDSOLocal() as
appropriate.

Thanks to Vitaly Buka for reporting the issue and suggesting the way to detect asan.
  • Loading branch information
MaskRay committed Dec 6, 2020
1 parent ee607ed commit 5582a79
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/TargetMachine.cpp
Expand Up @@ -163,6 +163,11 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
// If the symbol is defined, it cannot be preempted.
if (!GV->isDeclarationForLinker())
return true;
// FIXME asan does not call setDSOLocal appropriately. Fix asan and delete
// the hack.
if (RM == Reloc::Static && !GV->isThreadLocal() &&
M.getFunction("asan.module_ctor"))
return true;
} else if (TT.isOSBinFormatELF()) {
// If dso_local allows AsmPrinter::getSymbolPreferLocal to use a local
// alias, set the flag. We cannot set dso_local for other global values,
Expand Down

0 comments on commit 5582a79

Please sign in to comment.