@@ -52,7 +52,7 @@ int32_t set_forward_by_index(int32_t symbol_idx, const void * addr, int32_t inte
5252 } else {
5353 (* exported_func64_addrs [symbol_idx ]) = addr ;
5454
55- // If we're on an RTLD_DEEPBINDless system and our workaround is activated,
55+ // If we're on an RTLD_DEEPBIND-less system and our workaround is activated,
5656 // we take over our own 32-bit symbols as well.
5757 if (deepbindless_interfaces_loaded & DEEPBINDLESS_INTERFACE_ILP64_LOADED ) {
5858 (* exported_func32_addrs [symbol_idx ]) = addr ;
@@ -230,7 +230,7 @@ LBT_DLLEXPORT int32_t lbt_forward(const char * libname, int32_t clear, int32_t v
230230 * attempts to load another one without setting the `clear` flag, we refuse to
231231 * load it on a deepbindless system, printing out to `stderr` if we're verbose.
232232 */
233- #if defined( LBT_DEEPBINDLESS )
233+
234234 // If `clear` is set, we clear our tracking
235235 if (clear ) {
236236 deepbindless_interfaces_loaded = 0x00 ;
@@ -240,13 +240,13 @@ LBT_DLLEXPORT int32_t lbt_forward(const char * libname, int32_t clear, int32_t v
240240 // we bind to the suffix-"" names, so even if the names of that library
241241 // internally are suffixed to something else, we ourselves will interfere with
242242 // a future suffix-"" ILP64 BLAS.
243- if (interface == LBT_INTERFACE_LP64 ) {
243+ if (( use_deepbind == 0x00 ) && ( interface == LBT_INTERFACE_LP64 ) ) {
244244 deepbindless_interfaces_loaded |= DEEPBINDLESS_INTERFACE_LP64_LOADED ;
245245 }
246246
247247 // We only mark a loaded ILP64 BLAS if it is a suffix-"" BLAS, since that is
248248 // the only case in which it will interfere with our LP64 BLAS symbols.
249- if (lib_suffix [0 ] == '\0' && interface == LBT_INTERFACE_ILP64 ) {
249+ if (( use_deepbind == 0x00 ) && ( lib_suffix [0 ] == '\0' && interface == LBT_INTERFACE_ILP64 ) ) {
250250 deepbindless_interfaces_loaded |= DEEPBINDLESS_INTERFACE_ILP64_LOADED ;
251251 }
252252
@@ -257,7 +257,6 @@ LBT_DLLEXPORT int32_t lbt_forward(const char * libname, int32_t clear, int32_t v
257257 }
258258 return 0 ;
259259 }
260- #endif
261260
262261 // If `clear` is set, drop all information about previously-loaded libraries
263262 if (clear ) {
@@ -307,6 +306,19 @@ __attribute__((constructor)) void init(void) {
307306 printf ("libblastrampoline initializing\n" );
308307 }
309308
309+ #if !defined(LBT_DEEPBINDLESS )
310+ // If LBT_USE_RTLD_DEEPBIND == "0", we avoid using RTLD_DEEPBIND on a
311+ // deepbind-capable system. This is mostly useful for sanitizers, which
312+ // abhor such library loading shenanigans.
313+ const char * deepbindless_str = getenv ("LBT_USE_RTLD_DEEPBIND" );
314+ if (deepbindless_str != NULL && strcmp (deepbindless_str , "0" ) == 0 ) {
315+ use_deepbind = 0x00 ;
316+ if (verbose ) {
317+ printf ("LBT_USE_RTLD_DEEPBIND=0 detected; avoiding usage of RTLD_DEEPBIND\n" );
318+ }
319+ }
320+ #endif // !defined(LBT_DEEPBINDLESS)
321+
310322 // LBT_DEFAULT_LIBS is a semicolon-separated list of paths that should be loaded as BLAS libraries
311323 const char * default_libs = getenv ("LBT_DEFAULT_LIBS" );
312324 if (default_libs != NULL ) {
0 commit comments