Skip to content

Commit 34f941a

Browse files
authored
Revert "[asan] Catch initialization-order-fiasco in modules without globals" (#104665)
Reverts #104621 To many bots are broken, see #104621.
1 parent c51578e commit 34f941a

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra.cpp -o %t
22
// RUN: %env_asan_opts=check_initialization_order=true:strict_init_order=true not %run %t 2>&1 | FileCheck %s
33

4+
// Not implemented.
5+
// XFAIL: *
6+
47
// Do not test with optimization -- the error may be optimized away.
58

69
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,10 +2531,15 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Module &M,
25312531
SmallVector<GlobalVariable *, 16> NewGlobals(n);
25322532
SmallVector<Constant *, 16> Initializers(n);
25332533

2534+
bool HasDynamicallyInitializedGlobals = false;
2535+
25342536
// We shouldn't merge same module names, as this string serves as unique
25352537
// module ID in runtime.
2536-
GlobalVariable *ModuleName = createPrivateGlobalForString(
2537-
M, M.getModuleIdentifier(), /*AllowMerging*/ false, kAsanGenPrefix);
2538+
GlobalVariable *ModuleName =
2539+
n != 0
2540+
? createPrivateGlobalForString(M, M.getModuleIdentifier(),
2541+
/*AllowMerging*/ false, kAsanGenPrefix)
2542+
: nullptr;
25382543

25392544
for (size_t i = 0; i < n; i++) {
25402545
GlobalVariable *G = GlobalsToChange[i];
@@ -2641,6 +2646,9 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Module &M,
26412646
Constant::getNullValue(IntptrTy),
26422647
ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));
26432648

2649+
if (ClInitializers && MD.IsDynInit)
2650+
HasDynamicallyInitializedGlobals = true;
2651+
26442652
LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n");
26452653

26462654
Initializers[i] = Initializer;
@@ -2680,7 +2688,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Module &M,
26802688
}
26812689

26822690
// Create calls for poisoning before initializers run and unpoisoning after.
2683-
if (ClInitializers)
2691+
if (HasDynamicallyInitializedGlobals)
26842692
createInitializerPoisonCalls(M, ModuleName);
26852693

26862694
LLVM_DEBUG(dbgs() << M);

llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ define internal void @__late_ctor() sanitize_address section ".text.startup" {
1818
; CHECK-LABEL: define internal void @__late_ctor(
1919
; CHECK-SAME: ) #[[ATTR1:[0-9]+]] section ".text.startup" {
2020
; CHECK-NEXT: [[ENTRY:.*:]]
21-
; CHECK-NEXT: call void @__asan_before_dynamic_init(i64 ptrtoint (ptr @___asan_gen_ to i64))
2221
; CHECK-NEXT: call void @initializer()
23-
; CHECK-NEXT: call void @__asan_after_dynamic_init()
2422
; CHECK-NEXT: ret void
2523
;
2624
; NOINIT-LABEL: define internal void @__late_ctor(

0 commit comments

Comments
 (0)