diff --git a/library/std/src/sys/thread_local/destructors/linux_like.rs b/library/std/src/sys/thread_local/destructors/linux_like.rs index d7cbaeb89f42e..5f2e454b99e9e 100644 --- a/library/std/src/sys/thread_local/destructors/linux_like.rs +++ b/library/std/src/sys/thread_local/destructors/linux_like.rs @@ -37,14 +37,17 @@ pub unsafe fn register(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { >; } - if let Some(f) = unsafe { __cxa_thread_atexit_impl } { + if let Some(f) = unsafe { __cxa_thread_atexit_impl } + && let dso = unsafe { __dso_handle } + && !dso.is_null() + { unsafe { f( transmute::( dtor, ), t.cast(), - (&raw const __dso_handle) as *mut _, + dso as *mut _, ); } } else {