Skip to content

Commit 6a8f738

Browse files
committed
Revert "Reland "[asan] Remove debug tracing from report_globals (#104404)" (#105601)"
that change still breaks SanitizerCommon-asan-x86_64-Darwin :: Darwin/print-stack-trace-in-code-loaded-after-fork.cpp > This reverts commit 2704b80 > and relands #104404. > > The Darwin should not fail after #105599. This reverts commit 8c6f8c2.
1 parent 885c436 commit 6a8f738

10 files changed

+30
-24
lines changed

compiler-rt/lib/asan/asan_flags.inc

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ 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(bool, report_globals, true,
40-
"If set, detect and report errors on globals .")
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).")
4144
ASAN_FLAG(bool, check_initialization_order, false,
4245
"If set, attempts to catch initialization order issues.")
4346
ASAN_FLAG(

compiler-rt/lib/asan/asan_globals.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
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"
2625
#include "sanitizer_common/sanitizer_list.h"
2726
#include "sanitizer_common/sanitizer_mutex.h"
2827
#include "sanitizer_common/sanitizer_placement_new.h"
@@ -180,7 +179,7 @@ int GetGlobalsForAddress(uptr addr, Global *globals, u32 *reg_sites,
180179
int res = 0;
181180
for (const auto &l : list_of_all_globals) {
182181
const Global &g = *l.g;
183-
if (UNLIKELY(common_flags()->verbosity >= 3))
182+
if (flags()->report_globals >= 2)
184183
ReportGlobal(g, "Search");
185184
if (IsAddressNearGlobal(addr, g)) {
186185
internal_memcpy(&globals[res], &g, sizeof(g));
@@ -271,7 +270,7 @@ static inline bool UseODRIndicator(const Global *g) {
271270
// so we store the globals in a map.
272271
static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
273272
CHECK(AsanInited());
274-
if (UNLIKELY(common_flags()->verbosity >= 3))
273+
if (flags()->report_globals >= 2)
275274
ReportGlobal(*g, "Added");
276275
CHECK(flags()->report_globals);
277276
CHECK(AddrIsInMem(g->beg));
@@ -308,7 +307,7 @@ static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
308307
static void UnregisterGlobal(const Global *g)
309308
SANITIZER_REQUIRES(mu_for_globals) {
310309
CHECK(AsanInited());
311-
if (UNLIKELY(common_flags()->verbosity >= 3))
310+
if (flags()->report_globals >= 2)
312311
ReportGlobal(*g, "Removed");
313312
CHECK(flags()->report_globals);
314313
CHECK(AddrIsInMem(g->beg));
@@ -439,7 +438,7 @@ void __asan_register_globals(__asan_global *globals, uptr n) {
439438
}
440439
GlobalRegistrationSite site = {stack_id, &globals[0], &globals[n - 1]};
441440
global_registration_site_vector->push_back(site);
442-
if (UNLIKELY(common_flags()->verbosity >= 3)) {
441+
if (flags()->report_globals >= 2) {
443442
PRINT_CURRENT_STACK();
444443
Printf("=== ID %d; %p %p\n", stack_id, (void *)&globals[0],
445444
(void *)&globals[n - 1]);
@@ -498,7 +497,9 @@ void __asan_before_dynamic_init(const char *module_name) {
498497
Lock lock(&mu_for_globals);
499498
if (current_dynamic_init_module_name == module_name)
500499
return;
501-
VPrintf(2, "DynInitPoison module: %s\n", module_name);
500+
if (flags()->report_globals >= 3)
501+
Printf("DynInitPoison module: %s\n", module_name);
502+
502503
if (current_dynamic_init_module_name == nullptr) {
503504
// First call, poison all globals from other modules.
504505
DynInitGlobals().forEach([&](auto &kv) {
@@ -544,7 +545,8 @@ static void UnpoisonBeforeMain(void) {
544545
return;
545546
allow_after_dynamic_init = true;
546547
}
547-
VPrintf(2, "UnpoisonBeforeMain\n");
548+
if (flags()->report_globals >= 3)
549+
Printf("UnpoisonBeforeMain\n");
548550
__asan_after_dynamic_init();
549551
}
550552

@@ -568,7 +570,8 @@ void __asan_after_dynamic_init() {
568570
if (!current_dynamic_init_module_name)
569571
return;
570572

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

573576
DynInitGlobals().forEach([&](auto &kv) {
574577
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=1:verbosity=2 %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=3 %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=1:detect_odr_violation=1:verbosity=3 %run %t 2>&1 | FileCheck %s
7+
// RUN: %env_asan_opts=report_globals=2:detect_odr_violation=1 %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=1:verbosity=3 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR0
2+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR1
5+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=NOSTRIP
4+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=STRIP
8+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %run %te.exe 2>&1 | FileCheck %s
4+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %t.exe 2>&1 | FileCheck %s --check-prefix=NOSTRIP
2+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %t.exe 2>&1 | FileCheck %s --check-prefix=STRIP
6+
// RUN: %env_asan_opts=report_globals=2 %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=1:verbosity=3 %run %te.exe %t.dll 2>&1 | FileCheck %s
3+
// RUN: %env_asan_opts=report_globals=2 %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=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"
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"
88

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

0 commit comments

Comments
 (0)