summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2018-04-26 20:46:50 +0000
committerReid Kleckner <rnk@google.com>2018-04-26 20:46:50 +0000
commit824eb0e6a0585e647e20fdc4314b251cffdc241f (patch)
tree7805a088da74b09214e54d62c2501fd9057c641d /compiler-rt
parent8e19bd45a9bbd7db58fe61cc327892f81fb71285 (diff)
downloadbcm5719-llvm-824eb0e6a0585e647e20fdc4314b251cffdc241f.tar.gz
bcm5719-llvm-824eb0e6a0585e647e20fdc4314b251cffdc241f.zip
[asan] Align __asan_global_start so that it works with LLD
Otherwise LLD will not align the .ASAN$GA section start, and &__asan_globals + 1 will not be the start of the next real ASan global metadata in .ASAN$GL. We discovered this issue when attempting to use LLD on Windows in Chromium: https://crbug.com/837090 llvm-svn: 330990
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/asan/asan_globals_win.cc4
-rw-r--r--compiler-rt/test/asan/TestCases/Windows/fuse-lld-globals.cc18
2 files changed, 20 insertions, 2 deletions
diff --git a/compiler-rt/lib/asan/asan_globals_win.cc b/compiler-rt/lib/asan/asan_globals_win.cc
index 261762b63e2..29ab5ebf16d 100644
--- a/compiler-rt/lib/asan/asan_globals_win.cc
+++ b/compiler-rt/lib/asan/asan_globals_win.cc
@@ -19,9 +19,9 @@ namespace __asan {
#pragma section(".ASAN$GA", read, write) // NOLINT
#pragma section(".ASAN$GZ", read, write) // NOLINT
extern "C" __declspec(allocate(".ASAN$GA"))
-__asan_global __asan_globals_start = {};
+ ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {};
extern "C" __declspec(allocate(".ASAN$GZ"))
-__asan_global __asan_globals_end = {};
+ ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_end = {};
#pragma comment(linker, "/merge:.ASAN=.data")
static void call_on_globals(void (*hook)(__asan_global *, uptr)) {
diff --git a/compiler-rt/test/asan/TestCases/Windows/fuse-lld-globals.cc b/compiler-rt/test/asan/TestCases/Windows/fuse-lld-globals.cc
new file mode 100644
index 00000000000..4148d562fb4
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Windows/fuse-lld-globals.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -fuse-ld=lld -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <string.h>
+int main(int argc, char **argv) {
+ static char XXX[10];
+ static char YYY[10];
+ static char ZZZ[10];
+ memset(XXX, 0, 10);
+ memset(YYY, 0, 10);
+ memset(ZZZ, 0, 10);
+ int res = YYY[argc * 10]; // BOOOM
+ // CHECK: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK: {{ #0 0x.* in main .*fuse-lld-globals.cc:}}[[@LINE-2]]
+ // CHECK: {{0x.* is located 0 bytes to the right of global variable}}
+ // CHECK: {{.*YYY.* of size 10}}
+ res += XXX[argc] + ZZZ[argc];
+ return res;
+}
OpenPOWER on IntegriCloud