[compiler-rt] fa87eac - Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (#104730)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 14:45:57 PDT 2024


Author: Vitaly Buka
Date: 2024-08-19T14:45:55-07:00
New Revision: fa87eac3bea5b9704522c6b553d0f4a421e8abc9

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

LOG: Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (#104730)

Re-land https://github.com/llvm/llvm-project/pull/104621

After https://github.com/llvm/llvm-project/pull/104729 this patch will
not create unused module names, failing some test checks.

This reverts commit 34f941a2f96b804dd24c2a25770d899b018339ff.

Added: 
    

Modified: 
    compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp
    llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
    llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp
index 50698b2a7d06fc..369449303f3e08 100644
--- a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp
+++ b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp
@@ -1,9 +1,6 @@
 // RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra.cpp -o %t
 // RUN: %env_asan_opts=check_initialization_order=true:strict_init_order=true not %run %t 2>&1 | FileCheck %s
 
-// Not implemented.
-// XFAIL: *
-
 // Do not test with optimization -- the error may be optimized away.
 
 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186

diff  --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 01dbdc156f698e..5de0a78d087968 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2538,8 +2538,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
   SmallVector<GlobalVariable *, 16> NewGlobals(n);
   SmallVector<Constant *, 16> Initializers(n);
 
-  bool HasDynamicallyInitializedGlobals = false;
-
   for (size_t i = 0; i < n; i++) {
     GlobalVariable *G = GlobalsToChange[i];
 
@@ -2645,9 +2643,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
         Constant::getNullValue(IntptrTy),
         ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));
 
-    if (ClInitializers && MD.IsDynInit)
-      HasDynamicallyInitializedGlobals = true;
-
     LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n");
 
     Initializers[i] = Initializer;
@@ -2686,7 +2681,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
   }
 
   // Create calls for poisoning before initializers run and unpoisoning after.
-  if (HasDynamicallyInitializedGlobals)
+  if (ClInitializers)
     createInitializerPoisonCalls();
 
   LLVM_DEBUG(dbgs() << M);

diff  --git a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll
index c8a6541bacfdfa..b20de3eb80b786 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll
@@ -18,7 +18,9 @@ define internal void @__late_ctor() sanitize_address section ".text.startup" {
 ; CHECK-LABEL: define internal void @__late_ctor(
 ; CHECK-SAME: ) #[[ATTR1:[0-9]+]] section ".text.startup" {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    call void @__asan_before_dynamic_init(i64 ptrtoint (ptr @___asan_gen_module to i64))
 ; CHECK-NEXT:    call void @initializer()
+; CHECK-NEXT:    call void @__asan_after_dynamic_init()
 ; CHECK-NEXT:    ret void
 ;
 ; NOINIT-LABEL: define internal void @__late_ctor(


        


More information about the llvm-commits mailing list