[llvm] 5582a79 - [TargetMachine] Set dso_local if asan is detected

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 5 17:51:17 PST 2020


Author: Fangrui Song
Date: 2020-12-05T17:51:10-08:00
New Revision: 5582a7987662a92eda5d883b88fc4586e755acf5

URL: https://github.com/llvm/llvm-project/commit/5582a7987662a92eda5d883b88fc4586e755acf5
DIFF: https://github.com/llvm/llvm-project/commit/5582a7987662a92eda5d883b88fc4586e755acf5.diff

LOG: [TargetMachine] Set dso_local if asan is detected

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.

Added: 
    

Modified: 
    llvm/lib/Target/TargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index ad0e90125258..f214a47ba702 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -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,


        


More information about the llvm-commits mailing list