xref: /llvm-project/compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp (revision 6f21401ae969eb3cdf66c7c84b52c90ca71c21bd)
1 // Test that gc-sections-friendly instrumentation of globals does not introduce
2 // false negatives with the BFD linker.
3 // RUN: %clangxx_asan -fuse-ld=bfd -Wl,-gc-sections -ffunction-sections -fdata-sections -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
4 
5 // Android does not use bfd.
6 // UNSUPPORTED: android
7 
8 #include <string.h>
9 int main(int argc, char **argv) {
10   static char XXX[10];
11   static char YYY[10];
12   static char ZZZ[10];
13   memset(XXX, 0, 10);
14   memset(YYY, 0, 10);
15   memset(ZZZ, 0, 10);
16   int res = YYY[argc * 10];  // BOOOM
17   // CHECK: {{READ of size 1 at}}
18   // CHECK: {{located 0 bytes after global variable}}
19   res += XXX[argc] + ZZZ[argc];
20   return res;
21 }
22