Index: lib/asan/asan_interceptors.cc =================================================================== --- lib/asan/asan_interceptors.cc +++ lib/asan/asan_interceptors.cc @@ -228,9 +228,11 @@ // Strict init-order checking is dlopen-hostile: // https://github.com/google/sanitizers/issues/178 #define COMMON_INTERCEPTOR_ON_DLOPEN(filename, flag) \ - if (flags()->strict_init_order) { \ - StopInitOrderChecking(); \ - } + do { \ + if (flags()->strict_init_order) \ + StopInitOrderChecking(); \ + CheckNoDeepBind(flag); \ + } while (false) #define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit() #define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) \ CoverageUpdateMapping() Index: lib/sanitizer_common/sanitizer_common.cc =================================================================== --- lib/sanitizer_common/sanitizer_common.cc +++ lib/sanitizer_common/sanitizer_common.cc @@ -19,6 +19,7 @@ #include "sanitizer_placement_new.h" #include "sanitizer_stacktrace_printer.h" #include "sanitizer_symbolizer.h" +#include // For RTLD_DEEPBIND namespace __sanitizer { @@ -475,6 +476,17 @@ return 0; } +void CheckNoDeepBind(int flag) { + if (flag & RTLD_DEEPBIND) { + Report("You are trying to dlopen a shared library with RTLD_DEEPBIND flag" + " which is incompatibe with sanitizer runtime " + "(see https://github.com/google/sanitizers/issues/611 for details" + "). If you want to run your library under sanitizers please remove " + "RTLD_DEEPBIND from dlopen flags.\n"); + Die(); + } +} + } // namespace __sanitizer using namespace __sanitizer; // NOLINT Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -142,7 +142,7 @@ COMMON_INTERCEPTOR_READ_STRING_OF_LEN((ctx), (s), REAL(strlen)(s), (n)) #ifndef COMMON_INTERCEPTOR_ON_DLOPEN -#define COMMON_INTERCEPTOR_ON_DLOPEN(filename, flag) {} +#define COMMON_INTERCEPTOR_ON_DLOPEN(filename, flag) { CheckNoDeepBind(flag); } #endif #ifndef COMMON_INTERCEPTOR_GET_TLS_RANGE Index: test/sanitizer_common/TestCases/Posix/deepbind.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/deepbind.cc @@ -0,0 +1,33 @@ +// RUN: %clangxx -DSHARED_LIB %s -fPIC -shared -o %t-so.so +// RUN: %clangxx %s -o %t && %run %t 2>&1 +// RUN: %run not %t 1 2>&1 | FileCheck %s --check-prefix CHECK-DEEPBIND +// UNSUPPORTED: lsan, android + +#if !defined(SHARED_LIB) +#include +#include +#include + +using std::string; + +int main (int argc, char *argv[]) { + int flag = argc > 1 ? RTLD_NOW | RTLD_DEEPBIND : RTLD_NOW; + string path = string(argv[0]) + "-so.so"; + printf("opening %s ... \n", path.c_str()); + // CHECK-DEEPBIND: You are trying to dlopen a shared library with RTLD_DEEPBIND flag + void *lib = dlopen(path.c_str(), flag); + if (!lib) { + printf("error in dlopen(): %s\n", dlerror()); + return 1; + } + dlclose(lib); + return 0; +} +#else // SHARED_LIB +#include + +__attribute__((constructor)) +void at_dlopen() { + printf("%s: I am being dlopened\n", __FILE__); +} +#endif