diff options
author | Andres Villegas <andresvi@google.com> | 2024-03-11 11:37:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-11 11:37:21 -0700 |
commit | 41fa0ea366318ecad79eba55c2f7877e1ea060f9 (patch) | |
tree | db9d746e5e1ff95d9e1533986a78721a4cd05ed7 | |
parent | c0839a54b20164a1f0f6c4307b992f1152b21c98 (diff) | |
download | llvm-41fa0ea366318ecad79eba55c2f7877e1ea060f9.zip llvm-41fa0ea366318ecad79eba55c2f7877e1ea060f9.tar.gz llvm-41fa0ea366318ecad79eba55c2f7877e1ea060f9.tar.bz2 |
[sanitizer_symbolizer] Add end to end test for symbolizer markup. (#77702)users/avillega/main.sanitizer_symbolizer-add-end-to-end-test-for-symbolizer-markup
Add more tests for sanitizer symbolizer markup, that make sure
the output of the symbolizer markup can be symbolized by
llvm-symbolizer.
-rw-r--r-- | compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp | 35 | ||||
-rw-r--r-- | compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 58 |
2 files changed, 93 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp new file mode 100644 index 0000000..03e7fde --- /dev/null +++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp @@ -0,0 +1,35 @@ +/// End to end test for the sanitizer symbolizer markup. +/// Since it uses debug info to do offline symbolization we only check that the +/// current module is correctly symbolized. +// REQUIRES: linux +// RUN: rm -rf %t +// RUN: mkdir -p %t/.build-id/12 +// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t/main +// RUN: cp %t/main %t/.build-id/12/345678.debug +// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t/main 2>%t/sanitizer.out +// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s + +#include <stdlib.h> + +[[gnu::noinline]] char *alloc() { + char *x = (char *)malloc(10 * sizeof(char)); + return x; +} +int main() { + char *x = alloc(); + free(x); + return x[5]; +} +// CHECK: ERROR: AddressSanitizer: heap-use-after-free on address +// CHECK: {{0x.*}} at pc {{0x.*}} bp {{0x.*}} sp {{0x.*}} +// CHECK: READ of size 1 at {{0x.*}} thread T0 +// CHECK: #0 {{0x.*}} main{{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 5]] +// CHECK: {{0x.*}} is located 5 bytes inside of 10-byte region {{.0x.*,0x.*}} +// CHECK: freed by thread T0 here: +// CHECK: #1 {{0x.*}} main{{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 9]] +// CHECK: previously allocated by thread T0 here: +// CHECK: #1 {{0x.*}} alloc{{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 16]] +// CHECK: #2 {{0x.*}} main {{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 13]] +// CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes): +// CHECK: Global redzone: +// CHECK: ASan internal: diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp new file mode 100644 index 0000000..ebd816e --- /dev/null +++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp @@ -0,0 +1,58 @@ +// REQUIRES: linux +// RUN: rm -rf %t +// RUN: mkdir -p %t/.build-id/12 +// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t/main +// RUN: cp %t/main %t/.build-id/12/345678.debug +// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t/main >%t/sanitizer.out +// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s + +#include "test.h" + +int Global; + +[[gnu::noinline]] void foo1() { Global = 42; } + +[[gnu::noinline]] void bar1() { + volatile int tmp = 42; + int tmp2 = tmp; + (void)tmp2; + foo1(); +} + +[[gnu::noinline]] void foo2() { + volatile int tmp = Global; + int tmp2 = tmp; + (void)tmp2; +} + +[[gnu::noinline]] void bar2() { + volatile int tmp = 42; + int tmp2 = tmp; + (void)tmp2; + foo2(); +} + +void *Thread1(void *x) { + barrier_wait(&barrier); + bar1(); + return NULL; +} + +int main() { + barrier_init(&barrier, 2); + pthread_t t; + pthread_create(&t, NULL, Thread1, NULL); + bar2(); + barrier_wait(&barrier); + pthread_join(t, NULL); +} + +// CHECK: WARNING: ThreadSanitizer: data race +// CHECK: Write of size 4 at {{0x.*}} by thread T1: +// CHECK: #0 {{0x.*}} foo1{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 39]] +// CHECK-NEXT: #1 {{0x.*}} bar1{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 34]] +// CHECK-NEXT: #2 {{0x.*}} Thread1{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 17]] +// CHECK: Previous read of size 4 at {{.*}} by main thread: +// CHECK-NEXT: #0 {{0x.*}} foo2{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 33]] +// CHECK-NEXT: #1 {{0x.*}} bar2{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 25]] +// CHECK-NEXT: #2 {{0x.*}} main{{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 13]] |