[llvm-branch-commits] [clang-tools-extra] [llvm] [clang] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 10 15:31:34 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Andres Villegas (avillega)

<details>
<summary>Changes</summary>

Add more tests for sanitizer symbolizer markup, that make sure
the output of the symbolizer markup can be symbolized by llvm-symbolizer.


---
Full diff: https://github.com/llvm/llvm-project/pull/77702.diff


2 Files Affected:

- (added) compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp (+34) 
- (added) compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp (+59) 


``````````diff
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 00000000000000..548ae57b5c3797
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -0,0 +1,34 @@
+// COM: End to end test for the sanitizer symbolizer markup. Since it uses debug info
+// COM: to do offline symbolization we only check that the current module correctly is correctly symbolized  
+// REQUIRES: linux
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: mkdir -p %t/.build-id/12
+// 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 00000000000000..5798986d73839e
--- /dev/null
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -0,0 +1,59 @@
+// REQUIRES: linux
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main 
+// RUN: mkdir -p %t/.build-id/12
+// 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 --dump-input=always
+
+#include "test.h"
+
+int Global;
+
+void __attribute__((noinline)) foo1() {
+  Global = 42;
+}
+
+void __attribute__((noinline)) bar1() {
+  volatile int tmp = 42;
+  int tmp2 = tmp;
+  (void)tmp2;
+  foo1();
+}
+
+void __attribute__((noinline)) foo2() {
+  volatile int tmp = Global;
+  int tmp2 = tmp;
+  (void)tmp2;
+}
+
+void __attribute__((noinline)) 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 {{.*}} by thread T1:
+//      CHECK:     #0 {{0x.*}} foo1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-40]]
+// 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:     #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]]

``````````

</details>


https://github.com/llvm/llvm-project/pull/77702


More information about the llvm-branch-commits mailing list