Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/deepbindless.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ LBT_DLLEXPORT uint8_t lbt_get_use_deepbind() {
return use_deepbind;
}

/*
* Returns whether AddressSanitizer is loaded in this process. RTLD_DEEPBIND is
* incompatible with the sanitizers' libc interposition
* (c.f. https://github.com/google/sanitizers/issues/611)
*/
uint8_t running_under_sanitizer(void) {
#if defined(LBT_DEEPBINDLESS) || !defined(RTLD_DEEPBIND)
return 0x00;
#else
return dlsym(RTLD_DEFAULT, "__asan_init") != NULL ? 0x01 : 0x00;
#endif
}


int lsame_idx = -1;
const void *old_lsame32 = NULL, *old_lsame64 = NULL;
Expand Down
17 changes: 12 additions & 5 deletions src/libblastrampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,20 @@ __attribute__((constructor)) void init(void) {
printf("libblastrampoline initializing from %s\n", lookup_self_path());
}

// If LBT_USE_RTLD_DEEPBIND == "0", we avoid using RTLD_DEEPBIND on a
// deepbind-capable system. This is mostly useful for sanitizers, which
// abhor such library loading shenanigans.
if (!env_match_bool("LBT_USE_RTLD_DEEPBIND", 1)) {
// If LBT_USE_RTLD_DEEPBIND == "0" or ASAN is auto-detected, we avoid using
// RTLD_DEEPBIND on a deepbind-capable system. This is mostly useful for
// sanitizers, which abhor such library loading shenanigans.
if (getenv("LBT_USE_RTLD_DEEPBIND") != NULL) {
if (!env_match_bool("LBT_USE_RTLD_DEEPBIND", 1)) {
use_deepbind = 0x00;
if (verbose) {
printf("LBT_USE_RTLD_DEEPBIND=0 detected; avoiding usage of RTLD_DEEPBIND\n");
}
}
} else if (running_under_sanitizer()) {
use_deepbind = 0x00;
if (verbose) {
printf("LBT_USE_RTLD_DEEPBIND=0 detected; avoiding usage of RTLD_DEEPBIND\n");
printf("AddressSanitizer detected; avoiding usage of RTLD_DEEPBIND\n");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libblastrampoline_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ int32_t autodetect_cblas_divergence(void * handle, const char * suffix);
uint8_t push_fake_lsame();
uint8_t pop_fake_lsame();
int fake_lsame(char * ca, char * cb);
uint8_t running_under_sanitizer(void);
extern uint8_t use_deepbind;
Loading