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: %run %t 2>&1 6 7 // REQUIRES: asan-64-bits 8 9 #ifndef BUILD_SO 10 #include <assert.h> 11 #include <dlfcn.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 15 int main(int argc, char *argv[]) { 16 char path[4096]; 17 snprintf(path, sizeof(path), "%s-so.so", argv[0]); 18 19 void *handle = dlopen(path, RTLD_LAZY); 20 if (!handle) fprintf(stderr, "%s\n", dlerror()); 21 assert(handle != 0); 22 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(); 28 29 dlclose(handle); 30 return 0; 31 } 32 33 #else // BUILD_SO 34 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); 39 } 40 41 #endif // BUILD_SO 42