42 lines · cpp
1// Check that --gc-sections does not throw away (or localize) parts of sanitizer2// interface.3// RUN: %clang_asan %s -Wl,--gc-sections -ldl -o %t4// RUN: %clang_asan %s -DBUILD_SO -fPIC -o %t-so.so -shared5// RUN: %run %t 2>&16 7// REQUIRES: asan-64-bits8 9#ifndef BUILD_SO10#include <assert.h>11#include <dlfcn.h>12#include <stdio.h>13#include <stdlib.h>14 15int 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_SO34 35#include <sanitizer/asan_interface.h>36extern "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_SO42