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>
9int main(int argc, char **argv) {
10 static char XXX[10];
11 static char YYY[10];
12 static char ZZZ[10];
13 memset(s: XXX, c: 0, n: 10);
14 memset(s: YYY, c: 0, n: 10);
15 memset(s: ZZZ, c: 0, n: 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

source code of compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp