Skip to content

Commit 8c6f8c2

Browse files
authored
Reland "[asan] Remove debug tracing from report_globals (#104404)" (#105601)
This reverts commit 2704b80 and relands #104404. The Darwin should not fail after #105599.
1 parent 24740ec commit 8c6f8c2

10 files changed

+24
-30
lines changed

compiler-rt/lib/asan/asan_flags.inc

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ ASAN_FLAG(int, max_redzone, 2048,
3636
ASAN_FLAG(
3737
bool, debug, false,
3838
"If set, prints some debugging information and does additional checks.")
39-
ASAN_FLAG(
40-
int, report_globals, 1,
41-
"Controls the way to handle globals (0 - don't detect buffer overflow on "
42-
"globals, 1 - detect buffer overflow, 2 - print data about registered "
43-
"globals).")
39+
ASAN_FLAG(bool, report_globals, true,
40+
"If set, detect and report errors on globals .")
4441
ASAN_FLAG(bool, check_initialization_order, false,
4542
"If set, attempts to catch initialization order issues.")
4643
ASAN_FLAG(

compiler-rt/lib/asan/asan_globals.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "asan_thread.h"
2323
#include "sanitizer_common/sanitizer_common.h"
2424
#include "sanitizer_common/sanitizer_dense_map.h"
25+
#include "sanitizer_common/sanitizer_internal_defs.h"
2526
#include "sanitizer_common/sanitizer_list.h"
2627
#include "sanitizer_common/sanitizer_mutex.h"
2728
#include "sanitizer_common/sanitizer_placement_new.h"
@@ -179,7 +180,7 @@ int GetGlobalsForAddress(uptr addr, Global *globals, u32 *reg_sites,
179180
int res = 0;
180181
for (const auto &l : list_of_all_globals) {
181182
const Global &g = *l.g;
182-
if (flags()->report_globals >= 2)
183+
if (UNLIKELY(common_flags()->verbosity >= 3))
183184
ReportGlobal(g, "Search");
184185
if (IsAddressNearGlobal(addr, g)) {
185186
internal_memcpy(&globals[res], &g, sizeof(g));
@@ -270,7 +271,7 @@ static inline bool UseODRIndicator(const Global *g) {
270271
// so we store the globals in a map.
271272
static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
272273
CHECK(AsanInited());
273-
if (flags()->report_globals >= 2)
274+
if (UNLIKELY(common_flags()->verbosity >= 3))
274275
ReportGlobal(*g, "Added");
275276
CHECK(flags()->report_globals);
276277
CHECK(AddrIsInMem(g->beg));
@@ -307,7 +308,7 @@ static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
307308
static void UnregisterGlobal(const Global *g)
308309
SANITIZER_REQUIRES(mu_for_globals) {
309310
CHECK(AsanInited());
310-
if (flags()->report_globals >= 2)
311+
if (UNLIKELY(common_flags()->verbosity >= 3))
311312
ReportGlobal(*g, "Removed");
312313
CHECK(flags()->report_globals);
313314
CHECK(AddrIsInMem(g->beg));
@@ -438,7 +439,7 @@ void __asan_register_globals(__asan_global *globals, uptr n) {
438439
}
439440
GlobalRegistrationSite site = {stack_id, &globals[0], &globals[n - 1]};
440441
global_registration_site_vector->push_back(site);
441-
if (flags()->report_globals >= 2) {
442+
if (UNLIKELY(common_flags()->verbosity >= 3)) {
442443
PRINT_CURRENT_STACK();
443444
Printf("=== ID %d; %p %p\n", stack_id, (void *)&globals[0],
444445
(void *)&globals[n - 1]);
@@ -497,9 +498,7 @@ void __asan_before_dynamic_init(const char *module_name) {
497498
Lock lock(&mu_for_globals);
498499
if (current_dynamic_init_module_name == module_name)
499500
return;
500-
if (flags()->report_globals >= 3)
501-
Printf("DynInitPoison module: %s\n", module_name);
502-
501+
VPrintf(2, "DynInitPoison module: %s\n", module_name);
503502
if (current_dynamic_init_module_name == nullptr) {
504503
// First call, poison all globals from other modules.
505504
DynInitGlobals().forEach([&](auto &kv) {
@@ -545,8 +544,7 @@ static void UnpoisonBeforeMain(void) {
545544
return;
546545
allow_after_dynamic_init = true;
547546
}
548-
if (flags()->report_globals >= 3)
549-
Printf("UnpoisonBeforeMain\n");
547+
VPrintf(2, "UnpoisonBeforeMain\n");
550548
__asan_after_dynamic_init();
551549
}
552550

@@ -570,8 +568,7 @@ void __asan_after_dynamic_init() {
570568
if (!current_dynamic_init_module_name)
571569
return;
572570

573-
if (flags()->report_globals >= 3)
574-
Printf("DynInitUnpoison\n");
571+
VPrintf(2, "DynInitUnpoison\n");
575572

576573
DynInitGlobals().forEach([&](auto &kv) {
577574
UnpoisonDynamicGlobals(kv.second, /*mark_initialized=*/false);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx_asan -O3 %S/../initialization-nobug.cpp %S/../Helpers/initialization-nobug-extra.cpp -fuse-ld=lld -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
1+
// RUN: %clangxx_asan -O3 %S/../initialization-nobug.cpp %S/../Helpers/initialization-nobug-extra.cpp -fuse-ld=lld -o %t && %env_asan_opts=check_initialization_order=true:report_globals=1:verbosity=2 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInit"
22

33
// Same as initialization-nobug.cpp, but with lld we expect just one
44
// `DynInitUnpoison` executed after `AfterDynamicInit` at the end.

compiler-rt/test/asan/TestCases/Linux/odr_indicator_unregister.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %clangxx_asan -g -O0 -DSHARED_LIB -DSIZE=1 %s -fPIC -shared -o %t-so-1.so
55
// RUN: %clangxx_asan -g -O0 -DSHARED_LIB -DSIZE=2 %s -fPIC -shared -o %t-so-2.so
66
// RUN: %clangxx_asan -g -O0 %s %libdl -Wl,--export-dynamic -o %t
7-
// RUN: %env_asan_opts=report_globals=2:detect_odr_violation=1 %run %t 2>&1 | FileCheck %s
7+
// RUN: %env_asan_opts=report_globals=1:detect_odr_violation=1:verbosity=3 %run %t 2>&1 | FileCheck %s
88

99
// FIXME: Checks do not match on Android.
1010
// UNSUPPORTED: android

compiler-rt/test/asan/TestCases/Linux/odr_indicators.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %clangxx_asan -fno-sanitize-address-use-odr-indicator -fPIC %s -o %t
2-
// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR0
2+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR0
33

44
// RUN: %clangxx_asan -fsanitize-address-use-odr-indicator -fPIC %s -o %t
5-
// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR1
5+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR1
66

77
#include <stdio.h>
88

compiler-rt/test/asan/TestCases/Windows/dll_global_dead_strip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
22
//
33
// RUN: %clang_cl_nocxx_asan %Gw %LD %Od %s %Fe%t.dll
4-
// RUN: %env_asan_opts=report_globals=2 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=NOSTRIP
4+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=NOSTRIP
55
// RUN: %clang_cl_nocxx_asan %Gw %LD -O2 %s %Fe%t.dll \
66
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections %} \
77
// RUN: %else %{ -link -opt:ref %}
8-
// RUN: %env_asan_opts=report_globals=2 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=STRIP
8+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=STRIP
99

1010
#include <stdio.h>
1111

compiler-rt/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll \
22
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t.lib %}
33
// RUN: %clang_cl_asan %Od -DEXE %s %t.lib %Fe%te.exe
4-
// RUN: %env_asan_opts=report_globals=2 %run %te.exe 2>&1 | FileCheck %s
4+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %te.exe 2>&1 | FileCheck %s
55

66
// FIXME: Currently, the MT runtime build crashes on startup due to dbghelp.dll
77
// initialization failure.

compiler-rt/test/asan/TestCases/Windows/global_dead_strip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %clang_cl_nocxx_asan %Gw %Od %s %Fe%t.exe
2-
// RUN: %env_asan_opts=report_globals=2 %t.exe 2>&1 | FileCheck %s --check-prefix=NOSTRIP
2+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %t.exe 2>&1 | FileCheck %s --check-prefix=NOSTRIP
33
// RUN: %clang_cl_nocxx_asan %Gw -O2 %s %Fe%t.exe \
44
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections %} \
55
// RUN: %else %{ -link -opt:ref %}
6-
// RUN: %env_asan_opts=report_globals=2 %t.exe 2>&1 | FileCheck %s --check-prefix=STRIP
6+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %t.exe 2>&1 | FileCheck %s --check-prefix=STRIP
77

88
#include <stdio.h>
99
int dead_global = 42;

compiler-rt/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll
22
// RUN: %clang_cl_asan %Od -DEXE %s %Fe%te.exe
3-
// RUN: %env_asan_opts=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s
3+
// RUN: %env_asan_opts=report_globals=1:verbosity=3 %run %te.exe %t.dll 2>&1 | FileCheck %s
44

55
#include <windows.h>
66
#include <stdio.h>

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

+4-4
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=1:verbosity=2 %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=1:verbosity=2 %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=1:verbosity=2 %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=1:verbosity=2 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
88

99
// Simple access:
1010
// Make sure that accessing a global in the same TU is safe

0 commit comments

Comments
 (0)