1 // Test that AddressSanitizer does not re-animate dead globals when dead
2 // stripping is turned on.
3 //
4 // This test verifies that an out-of-bounds access on a global variable is
5 // detected after dead stripping has been performed. This proves that the
6 // runtime is able to register globals in the __DATA,__asan_globals section.
7
8 // REQUIRES: osx-ld64-live_support
9
10 // RUN: %clang_asan %min_macos_deployment_target=10.11 -Xlinker -dead_strip -o %t %s
11 // RUN: llvm-nm -format=posix %t | FileCheck --check-prefix NM-CHECK %s
12 // RUN: not %run %t 2>&1 | FileCheck --check-prefix ASAN-CHECK %s
13
14 int alive[1] = {};
15 int dead[1] = {};
16 // NM-CHECK: {{^_alive }}
17 // NM-CHECK-NOT: {{^_dead }}
18
main(int argc,char * argv[])19 int main(int argc, char *argv[]) {
20 alive[argc] = 0;
21 // ASAN-CHECK: {{0x.* is located 0 bytes to the right of global variable}}
22 return 0;
23 }
24