[ASan] Explicitly specify -ldl/-lpthread in RUN-lines where needed
[blocksruntime.git] / test / asan / TestCases / Linux / function-sections-are-bad.cc
blob148113297862847ed0c063747b62b9d5a340f30c
1 // Check that --gc-sections does not throw away (or localize) parts of sanitizer
2 // interface.
3 // RUN: %clang_asan %s -Wl,--gc-sections -ldl -o %t
4 // RUN: %clang_asan %s -DBUILD_SO -fPIC -o %t-so.so -shared
5 // RUN: %t 2>&1
7 // REQUIRES: asan-64-bits
9 #ifndef BUILD_SO
10 #include <assert.h>
11 #include <dlfcn.h>
12 #include <stdio.h>
13 #include <stdlib.h>
15 int main(int argc, char *argv[]) {
16 char path[4096];
17 snprintf(path, sizeof(path), "%s-so.so", argv[0]);
19 void *handle = dlopen(path, RTLD_LAZY);
20 if (!handle) fprintf(stderr, "%s\n", dlerror());
21 assert(handle != 0);
23 typedef void (*F)();
24 F f = (F)dlsym(handle, "call_rtl_from_dso");
25 printf("%s\n", dlerror());
26 assert(dlerror() == 0);
27 f();
29 dlclose(handle);
30 return 0;
33 #else // BUILD_SO
35 #include <sanitizer/asan_interface.h>
36 extern "C" void call_rtl_from_dso() {
37 volatile int32_t x;
38 volatile int32_t y = __sanitizer_unaligned_load32((void *)&x);
41 #endif // BUILD_SO