Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 19c4576

Browse files
author
Ryan Govostes
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@273464 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent af56780 commit 19c4576

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Test that globals from different shared objects all get registered.
2+
3+
// This source file is compiled into three different source object files. Each
4+
// object file declares a global buffer. The first two are linked together, and
5+
// the third is loaded at runtime. We make sure that out-of-bounds accesses
6+
// are caught for all three buffers.
7+
8+
// RUN: %clang_asan -c -o %t-one.o -DDYNAMICLIB=\"%t-dynamic.so\" -DMAIN_FILE %s
9+
// RUN: %clang_asan -c -o %t-two.o -DSECONDARY_FILE %s
10+
// RUN: %clang_asan -o %t %t-one.o %t-two.o
11+
// RUN: %clang_asan -shared -o %t-dynamic.so -DSHARED_LIBRARY_FILE %s
12+
// RUN: not %run %t 1 2>&1 | FileCheck --check-prefix ASAN-CHECK-1 %s
13+
// RUN: not %run %t 2 2>&1 | FileCheck --check-prefix ASAN-CHECK-2 %s
14+
// RUN: not %run %t 3 2>&1 | FileCheck --check-prefix ASAN-CHECK-3 %s
15+
16+
#if MAIN_FILE
17+
18+
#include <dlfcn.h>
19+
#include <stdlib.h>
20+
21+
extern char buffer2[1];
22+
char buffer1[1] = { };
23+
24+
int main(int argc, char *argv[]) {
25+
int n = atoi(argv[1]);
26+
if (n == 1) {
27+
buffer1[argc] = 0;
28+
// ASAN-CHECK-1: {{0x.* is located 1 bytes .* 'buffer1'}}
29+
} else if (n == 2) {
30+
buffer2[argc] = 0;
31+
// ASAN-CHECK-2: {{0x.* is located 1 bytes .* 'buffer2'}}
32+
} else if (n == 3) {
33+
void *handle = dlopen(DYNAMICLIB, RTLD_NOW);
34+
if (!handle)
35+
return 1;
36+
37+
char *buffer = (char *)dlsym(handle, "buffer3");
38+
if (!buffer)
39+
return 1;
40+
41+
buffer[argc] = 0;
42+
// ASAN-CHECK-3: {{0x.* is located 1 bytes .* 'buffer3'}}
43+
}
44+
45+
return 0;
46+
}
47+
48+
#elif SECONDARY_FILE
49+
50+
char buffer2[1] = { };
51+
52+
#elif SHARED_LIBRARY_FILE
53+
54+
char buffer3[1] = { };
55+
56+
#endif

0 commit comments

Comments
 (0)