xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Check that when having a DYLD_ROOT_PATH set, the symbolizer still works.
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t
3*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=verbosity=2 DYLD_ROOT_PATH="/" ASAN_SYMBOLIZER_PATH=$(which atos) \
4*7c3d14c8STreehugger Robot // RUN:   not %run %t 2>&1 | FileCheck %s
5*7c3d14c8STreehugger Robot //
6*7c3d14c8STreehugger Robot // Due to a bug in atos, this only works on x86_64.
7*7c3d14c8STreehugger Robot // REQUIRES: asan-64-bits
8*7c3d14c8STreehugger Robot 
9*7c3d14c8STreehugger Robot #include <stdlib.h>
10*7c3d14c8STreehugger Robot #include <string.h>
main(int argc,char ** argv)11*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
12*7c3d14c8STreehugger Robot   char *x = (char*)malloc(10 * sizeof(char));
13*7c3d14c8STreehugger Robot   memset(x, 0, 10);
14*7c3d14c8STreehugger Robot   int res = x[argc];
15*7c3d14c8STreehugger Robot   free(x);
16*7c3d14c8STreehugger Robot   free(x + argc - 1);  // BOOM
17*7c3d14c8STreehugger Robot   // CHECK: Using atos at user-specified path:
18*7c3d14c8STreehugger Robot   // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
19*7c3d14c8STreehugger Robot   // CHECK: #0 0x{{.*}} in {{.*}}free
20*7c3d14c8STreehugger Robot   // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.cc:[[@LINE-4]]
21*7c3d14c8STreehugger Robot   // CHECK: freed by thread T0 here:
22*7c3d14c8STreehugger Robot   // CHECK: #0 0x{{.*}} in {{.*}}free
23*7c3d14c8STreehugger Robot   // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.cc:[[@LINE-8]]
24*7c3d14c8STreehugger Robot   // CHECK: allocated by thread T0 here:
25*7c3d14c8STreehugger Robot   // CHECK: atos-symbolizer-dyld-root-path.cc:[[@LINE-13]]
26*7c3d14c8STreehugger Robot   return res;
27*7c3d14c8STreehugger Robot }
28