Skip to content

Commit fa87eac

Browse files
authored
Reland "[asan] Catch initialization-order-fiasco in modules without…" (#104730)
Re-land #104621 After #104729 this patch will not create unused module names, failing some test checks. This reverts commit 34f941a.
1 parent 5af3dfb commit fa87eac

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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-
74
// Do not test with optimization -- the error may be optimized away.
85

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

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,8 +2538,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
25382538
SmallVector<GlobalVariable *, 16> NewGlobals(n);
25392539
SmallVector<Constant *, 16> Initializers(n);
25402540

2541-
bool HasDynamicallyInitializedGlobals = false;
2542-
25432541
for (size_t i = 0; i < n; i++) {
25442542
GlobalVariable *G = GlobalsToChange[i];
25452543

@@ -2645,9 +2643,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26452643
Constant::getNullValue(IntptrTy),
26462644
ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));
26472645

2648-
if (ClInitializers && MD.IsDynInit)
2649-
HasDynamicallyInitializedGlobals = true;
2650-
26512646
LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n");
26522647

26532648
Initializers[i] = Initializer;
@@ -2686,7 +2681,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26862681
}
26872682

26882683
// Create calls for poisoning before initializers run and unpoisoning after.
2689-
if (HasDynamicallyInitializedGlobals)
2684+
if (ClInitializers)
26902685
createInitializerPoisonCalls();
26912686

26922687
LLVM_DEBUG(dbgs() << M);

llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ 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_module to i64))
2122
; CHECK-NEXT: call void @initializer()
23+
; CHECK-NEXT: call void @__asan_after_dynamic_init()
2224
; CHECK-NEXT: ret void
2325
;
2426
; NOINIT-LABEL: define internal void @__late_ctor(

0 commit comments

Comments
 (0)