Skip to content

Commit b968a02

Browse files
authored
Revert "[asan] Optimize initialization order checking (#101837)"
This reverts commit 29e849b.
1 parent 3287a2e commit b968a02

File tree

3 files changed

+5
-62
lines changed

3 files changed

+5
-62
lines changed

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -520,43 +520,6 @@ void __asan_before_dynamic_init(const char *module_name) {
520520
current_dynamic_init_module_name = module_name;
521521
}
522522

523-
// Maybe SANITIZER_CAN_USE_PREINIT_ARRAY is to conservative for `.init_array`,
524-
// however we should not make mistake here. If `UnpoisonBeforeMain` was not
525-
// executed at all we will have false reports on globals.
526-
#if SANITIZER_CAN_USE_PREINIT_ARRAY
527-
// This optimization aims to reduce the overhead of `__asan_after_dynamic_init`
528-
// calls by leveraging incremental unpoisoning/poisoning in
529-
// `__asan_before_dynamic_init`. We expect most `__asan_after_dynamic_init
530-
// calls` to be no-ops. However, to ensure all globals are unpoisoned before the
531-
// `main`, we force `UnpoisonBeforeMain` to fully execute
532-
// `__asan_after_dynamic_init`.
533-
534-
// With lld, `UnpoisonBeforeMain` runs after standard `.init_array`, making it
535-
// the final `__asan_after_dynamic_init` call for the static runtime. In
536-
// contrast, GNU ld executes it earlier, causing subsequent
537-
// `__asan_after_dynamic_init` calls to perform full unpoisoning, losing the
538-
// optimization.
539-
bool allow_after_dynamic_init SANITIZER_GUARDED_BY(mu_for_globals) = false;
540-
541-
static void UnpoisonBeforeMain(void) {
542-
{
543-
Lock lock(&mu_for_globals);
544-
if (allow_after_dynamic_init)
545-
return;
546-
allow_after_dynamic_init = true;
547-
}
548-
if (flags()->report_globals >= 3)
549-
Printf("UnpoisonBeforeMain\n");
550-
__asan_after_dynamic_init();
551-
}
552-
553-
__attribute__((section(".init_array.65537"), used)) static void (
554-
*asan_after_init_array)(void) = UnpoisonBeforeMain;
555-
#else
556-
// Incremental poisoning is disabled, unpoison globals immediately.
557-
static constexpr bool allow_after_dynamic_init = true;
558-
#endif // SANITIZER_CAN_USE_PREINIT_ARRAY
559-
560523
// This method runs immediately after dynamic initialization in each TU, when
561524
// all dynamically initialized globals except for those defined in the current
562525
// TU are poisoned. It simply unpoisons all dynamically initialized globals.
@@ -565,8 +528,6 @@ void __asan_after_dynamic_init() {
565528
return;
566529
CHECK(AsanInited());
567530
Lock lock(&mu_for_globals);
568-
if (!allow_after_dynamic_init)
569-
return;
570531
if (!current_dynamic_init_module_name)
571532
return;
572533

compiler-rt/test/asan/TestCases/Linux/initialization-nobug-lld.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

compiler-rt/test/asan/TestCases/initialization-nobug.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// A collection of various initializers which shouldn't trip up initialization
22
// order checking. If successful, this will just return 0.
33

4-
// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
5-
// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
6-
// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
7-
// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
4+
// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
5+
// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
6+
// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
7+
// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
88

99
// Simple access:
1010
// Make sure that accessing a global in the same TU is safe
@@ -44,10 +44,6 @@ int getStructWithDtorValue() { return struct_with_dtor.value; }
4444
int main() { return 0; }
4545

4646
// CHECK: DynInitPoison
47+
// CHECK: DynInitUnpoison
4748
// CHECK: DynInitPoison
48-
49-
// In general case entire set of DynInitPoison must be followed by at lest one
50-
// DynInitUnpoison. In some cases we can limit the number of DynInitUnpoison,
51-
// see initialization-nobug-lld.cpp.
52-
5349
// CHECK: DynInitUnpoison

0 commit comments

Comments
 (0)