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