summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Govostes <rzg@apple.com>2016-06-22 19:59:10 +0000
committerRyan Govostes <rzg@apple.com>2016-06-22 19:59:10 +0000
commitf66146914b98f818e7937a1b0ccc589f35173236 (patch)
tree85f3db4060f821631882513bcdf7eebcd575c230
parent049908b2969f56aba6daf6fb4eb98a4a518ef13a (diff)
downloadbcm5719-llvm-f66146914b98f818e7937a1b0ccc589f35173236.tar.gz
bcm5719-llvm-f66146914b98f818e7937a1b0ccc589f35173236.zip
[asan] Add a test case for global registration
This test case checks that globals from all object files are being registered after they've been linked together. It also checks that globals from libraries loaded at runtime are registered. llvm-svn: 273464
-rw-r--r--compiler-rt/test/asan/TestCases/Posix/global-registration.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Posix/global-registration.c b/compiler-rt/test/asan/TestCases/Posix/global-registration.c
new file mode 100644
index 00000000000..7c77eb5ef72
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Posix/global-registration.c
@@ -0,0 +1,56 @@
+// Test that globals from different shared objects all get registered.
+
+// This source file is compiled into three different source object files. Each
+// object file declares a global buffer. The first two are linked together, and
+// the third is loaded at runtime. We make sure that out-of-bounds accesses
+// are caught for all three buffers.
+
+// RUN: %clang_asan -c -o %t-one.o -DDYNAMICLIB=\"%t-dynamic.so\" -DMAIN_FILE %s
+// RUN: %clang_asan -c -o %t-two.o -DSECONDARY_FILE %s
+// RUN: %clang_asan -o %t %t-one.o %t-two.o
+// RUN: %clang_asan -shared -o %t-dynamic.so -DSHARED_LIBRARY_FILE %s
+// RUN: not %run %t 1 2>&1 | FileCheck --check-prefix ASAN-CHECK-1 %s
+// RUN: not %run %t 2 2>&1 | FileCheck --check-prefix ASAN-CHECK-2 %s
+// RUN: not %run %t 3 2>&1 | FileCheck --check-prefix ASAN-CHECK-3 %s
+
+#if MAIN_FILE
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+extern char buffer2[1];
+char buffer1[1] = { };
+
+int main(int argc, char *argv[]) {
+ int n = atoi(argv[1]);
+ if (n == 1) {
+ buffer1[argc] = 0;
+ // ASAN-CHECK-1: {{0x.* is located 1 bytes .* 'buffer1'}}
+ } else if (n == 2) {
+ buffer2[argc] = 0;
+ // ASAN-CHECK-2: {{0x.* is located 1 bytes .* 'buffer2'}}
+ } else if (n == 3) {
+ void *handle = dlopen(DYNAMICLIB, RTLD_NOW);
+ if (!handle)
+ return 1;
+
+ char *buffer = (char *)dlsym(handle, "buffer3");
+ if (!buffer)
+ return 1;
+
+ buffer[argc] = 0;
+ // ASAN-CHECK-3: {{0x.* is located 1 bytes .* 'buffer3'}}
+ }
+
+ return 0;
+}
+
+#elif SECONDARY_FILE
+
+char buffer2[1] = { };
+
+#elif SHARED_LIBRARY_FILE
+
+char buffer3[1] = { };
+
+#endif
OpenPOWER on IntegriCloud