Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit fab06eb

Browse files
committed
[sanitizer] Disable -ffunction-sections.
It breaks when a binary is linked with --gc-sections: parts of sanitizer interface get thrown away and inaccessible from dlopen-ed libs. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200683 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e1c437c commit fab06eb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ if (NOT MSVC)
142142
-fno-stack-protector
143143
-Wno-gnu # Variadic macros with 0 arguments for ...
144144
-fvisibility=hidden
145+
-fno-function-sections
145146
)
146147
if (NOT COMPILER_RT_DEBUG)
147148
list(APPEND SANITIZER_COMMON_CFLAGS -O3)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Check that --gc-sections does not throw away (or localize) parts of sanitizer
2+
// interface.
3+
// RUN: %clang_asan -m64 %s -Wl,--gc-sections -o %t
4+
// RUN: %clang_asan -m64 %s -DBUILD_SO -fPIC -o %t-so.so -shared
5+
// RUN: %t 2>&1
6+
7+
#ifndef BUILD_SO
8+
#include <assert.h>
9+
#include <dlfcn.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
13+
int main(int argc, char *argv[]) {
14+
char path[4096];
15+
snprintf(path, sizeof(path), "%s-so.so", argv[0]);
16+
17+
void *handle = dlopen(path, RTLD_LAZY);
18+
if (!handle) fprintf(stderr, "%s\n", dlerror());
19+
assert(handle != 0);
20+
21+
typedef void (*F)();
22+
F f = (F)dlsym(handle, "call_rtl_from_dso");
23+
printf("%s\n", dlerror());
24+
assert(dlerror() == 0);
25+
f();
26+
27+
dlclose(handle);
28+
return 0;
29+
}
30+
31+
#else // BUILD_SO
32+
33+
#include <sanitizer/msan_interface.h>
34+
extern "C" void call_rtl_from_dso() {
35+
volatile int32_t x;
36+
volatile int32_t y = __sanitizer_unaligned_load32((void *)&x);
37+
}
38+
39+
#endif // BUILD_SO

0 commit comments

Comments
 (0)