From 8979186e4a4d5dbc04bf182a2fe40e8d05abedfc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 19 Oct 2026 14:40:25 +0200 Subject: [PATCH] linux thread_atexit: fix use of __dso_handle --- library/std/src/sys/thread_local/destructors/linux_like.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 {