Skip to content

Commit 622216f

Browse files
Implemented Update to Symbolizer Tools list after user defined function
becomes available on Windows.
1 parent 5ecbf46 commit 622216f

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

compiler-rt/lib/asan/asan_flags.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ void InitializeFlags() {
247247
// See GH issue 'https://github.com/llvm/llvm-project/issues/117925' for
248248
// details.
249249
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
250-
});
250+
Symbolizer::UpdateSymbolizerTools();
251+
});
251252

252253
# if CAN_SANITIZE_UB
253254
AddRegisterWeakFunctionCallback(

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class Symbolizer final {
136136
/// (if it wasn't already initialized).
137137
static Symbolizer *GetOrInit();
138138
static void LateInitialize();
139+
#if SANITIZER_WINDOWS
140+
static void UpdateSymbolizerTools();
141+
#endif
139142
// Returns a list of symbolized frames for a given address (containing
140143
// all inlined functions, if necessary).
141144
SymbolizedStack *SymbolizePC(uptr address);

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ Symbolizer *Symbolizer::GetOrInit() {
2626
return symbolizer_;
2727
}
2828

29+
#if SANITIZER_WINDOWS
30+
// If the 'symbolize' flag is set to 0, it clears the tools
31+
// associated with the symbolizer to prevent unnecessary symbolization and
32+
// resource usage. This is necessary because of the late binding of the
33+
// overridden method, __asan_default_options().
34+
void Symbolizer::UpdateSymbolizerTools() {
35+
SpinMutexLock l(&init_mu_);
36+
if (!common_flags()->symbolize) {
37+
symbolizer_->tools_.clear();
38+
}
39+
}
40+
#endif
41+
2942
// See sanitizer_symbolizer_markup.cpp.
3043
#if !SANITIZER_SYMBOLIZER_MARKUP
3144

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %clangxx_asan -O0 %s -o %t
2+
// RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-OFF
3+
// RUN: %env_asan_opts=symbolize=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-ON
4+
5+
// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION_OFF
6+
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-OFF
7+
// RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-OFF
8+
// RUN: %env_asan_opts=symbolize=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-ON
9+
10+
// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION_ON
11+
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-ON
12+
// RUN: %env_asan_opts=symbolize=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-OFF
13+
// RUN: %env_asan_opts=symbolize=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SYMBOLIZE-ON
14+
#if USER_FUNCTION_OFF
15+
16+
extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
17+
return "symbolize=0";
18+
}
19+
20+
#endif
21+
22+
#if USER_FUNCTION_ON
23+
24+
extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
25+
return "symbolize=1";
26+
}
27+
28+
#endif
29+
30+
#include <cstdio>
31+
#include <cstdlib>
32+
33+
volatile static int heapBufferOverflowValue = 10;
34+
int main() {
35+
int *array = new int[10];
36+
heapBufferOverflowValue = array[10]; // CHECK-SYMBOLIZE-ON: symbolize.cpp:36
37+
return 0; // CHECK-SYMBOLIZE-OFF: symbolize.cpp.tmp+0x
38+
}

0 commit comments

Comments
 (0)