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 // RUN: %clang_asan -mllvm -asan-globals-live-support -Xlinker -dead_strip -o %t %s
10 // RUN: llvm-nm -format=posix %t | FileCheck --check-prefix NM-CHECK %s
11 // RUN: not %run %t 2>&1 | FileCheck --check-prefix ASAN-CHECK %s
12 
13 int alive[1] = {};
14 int dead[1] = {};
15 // NM-CHECK: {{^_alive }}
16 // NM-CHECK-NOT: {{^_dead }}
17 
main(int argc,char * argv[])18 int main(int argc, char *argv[]) {
19   alive[argc] = 0;
20   // ASAN-CHECK: {{0x.* is located 0 bytes to the right of global variable}}
21   return 0;
22 }
23