Move MSan lit-tests under test/msan
[blocksruntime.git] / lib / asan / lit_tests / TestCases / Linux / function-sections-are-bad.cc
blobcccd6ca1c52ae3aeb9e7e61e4a9344f6fbca5ff0
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
7 #ifndef BUILD_SO
8 #include <assert.h>
9 #include <dlfcn.h>
10 #include <stdio.h>
11 #include <stdlib.h>
13 int main(int argc, char *argv[]) {
14 char path[4096];
15 snprintf(path, sizeof(path), "%s-so.so", argv[0]);
17 void *handle = dlopen(path, RTLD_LAZY);
18 if (!handle) fprintf(stderr, "%s\n", dlerror());
19 assert(handle != 0);
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();
27 dlclose(handle);
28 return 0;
31 #else // BUILD_SO
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);
39 #endif // BUILD_SO