Skip to content

Stack overflow when tls_callback called on x86_64-pc-windows-gnu #140798

Open
@Berrysoft

Description

@Berrysoft

Recently the CI of libloading could not pass. I tested it and found this issue. It only occurs on *-gnu target, not *-msvc or *-gnullvm target. I have noticed that *-msvc and *-gnullvm has native thread local support, but *-gnu does not. Is it the cause?

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (10fa3c449 2025-04-26)
binary: rustc
commit-hash: 10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81
commit-date: 2025-04-26
host: x86_64-pc-windows-msvc
release: 1.88.0-nightly
LLVM version: 20.1.2
Backtrace

    frame #19175: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19176: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19177: 0x00007ffd8d3a6fb0 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:92:21
    frame #19178: 0x00007ffd8d392b0b libtest_helpers.module`std::panicking::panic_count::increase::hfd0da68402c75e3a at windows.rs:64:27
    frame #19179: 0x00007ffd8d393489 libtest_helpers.module`std::panicking::rust_panic_with_hook::hbc6c43d9ad374d65 at panicking.rs:801:22
    frame #19180: 0x00007ffd8d39324b libtest_helpers.module`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5b6ff7969aa6723e at panicking.rs:699:13
    frame #19181: 0x00007ffd8d38e24f libtest_helpers.module`std::sys::backtrace::__rust_end_short_backtrace::hb7b70c0f3a6d4258 at backtrace.rs:168:18
    frame #19182: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19183: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19184: 0x00007ffd8d3a6fb0 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:92:21
    frame #19185: 0x00007ffd8d392b0b libtest_helpers.module`std::panicking::panic_count::increase::hfd0da68402c75e3a at windows.rs:64:27
    frame #19186: 0x00007ffd8d393489 libtest_helpers.module`std::panicking::rust_panic_with_hook::hbc6c43d9ad374d65 at panicking.rs:801:22
    frame #19187: 0x00007ffd8d39324b libtest_helpers.module`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5b6ff7969aa6723e at panicking.rs:699:13
    frame #19188: 0x00007ffd8d38e24f libtest_helpers.module`std::sys::backtrace::__rust_end_short_backtrace::hb7b70c0f3a6d4258 at backtrace.rs:168:18
    frame #19189: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19190: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19191: 0x00007ffd8d3a6fb0 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:92:21
    frame #19192: 0x00007ffd8d392b0b libtest_helpers.module`std::panicking::panic_count::increase::hfd0da68402c75e3a at windows.rs:64:27
    frame #19193: 0x00007ffd8d393489 libtest_helpers.module`std::panicking::rust_panic_with_hook::hbc6c43d9ad374d65 at panicking.rs:801:22
    frame #19194: 0x00007ffd8d39324b libtest_helpers.module`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5b6ff7969aa6723e at panicking.rs:699:13
    frame #19195: 0x00007ffd8d38e24f libtest_helpers.module`std::sys::backtrace::__rust_end_short_backtrace::hb7b70c0f3a6d4258 at backtrace.rs:168:18
    frame #19196: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19197: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19198: 0x00007ffd8d3a6fb0 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:92:21
    frame #19199: 0x00007ffd8d392b0b libtest_helpers.module`std::panicking::panic_count::increase::hfd0da68402c75e3a at windows.rs:64:27
    frame #19200: 0x00007ffd8d393489 libtest_helpers.module`std::panicking::rust_panic_with_hook::hbc6c43d9ad374d65 at panicking.rs:801:22
    frame #19201: 0x00007ffd8d39324b libtest_helpers.module`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5b6ff7969aa6723e at panicking.rs:699:13
    frame #19202: 0x00007ffd8d38e24f libtest_helpers.module`std::sys::backtrace::__rust_end_short_backtrace::hb7b70c0f3a6d4258 at backtrace.rs:168:18
    frame #19203: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19204: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19205: 0x00007ffd8d3a6fb0 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:92:21
    frame #19206: 0x00007ffd8d392b0b libtest_helpers.module`std::panicking::panic_count::increase::hfd0da68402c75e3a at windows.rs:64:27
    frame #19207: 0x00007ffd8d393489 libtest_helpers.module`std::panicking::rust_panic_with_hook::hbc6c43d9ad374d65 at panicking.rs:801:22
    frame #19208: 0x00007ffd8d393282 libtest_helpers.module`std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h5b6ff7969aa6723e at panicking.rs:706:13
    frame #19209: 0x00007ffd8d38e24f libtest_helpers.module`std::sys::backtrace::__rust_end_short_backtrace::hb7b70c0f3a6d4258 at backtrace.rs:168:18
    frame #19210: 0x00007ffd8d392efe libtest_helpers.module`__rustc::rust_begin_unwind at panicking.rs:697:5
    frame #19211: 0x00007ffd8d3d6461 libtest_helpers.module`core::panicking::panic_fmt::hf3da1af663b61a8d at panicking.rs:75:14
    frame #19212: 0x00007ffd8d3d699a libtest_helpers.module`core::panicking::assert_failed_inner::h42d3026cd4391138 at panicking.rs:0
    frame #19213: 0x00007ffd8d35de4a libtest_helpers.module`core::panicking::assert_failed::h3c4a6a625213a78c at panicking.rs:380:5
    frame #19214: 0x00007ffd8d3a6ff4 libtest_helpers.module`std::sys::thread_local::key::windows::LazyKey::init::h27769e3038b4ecac at windows.rs:115:13
    frame #19215: 0x00007ffd8d3a6ddf libtest_helpers.module`std::sys::thread_local::guard::windows::tls_callback::h295e5d63f45f6d01 at windows.rs:64:27
    frame #19216: 0x00007ffde207296f ntdll.dll`RtlDeactivateActivationContext + 3519
    frame #19217: 0x00007ffde207265e ntdll.dll`RtlDeactivateActivationContext + 2734
    frame #19218: 0x00007ffde20ea209 ntdll.dll`ShipAssert + 2089
    frame #19219: 0x00007ffde200484e ntdll.dll`TpAllocTimer + 1022
    frame #19220: 0x00007ffde2004694 ntdll.dll`TpAllocTimer + 580
    frame #19221: 0x00007ffde2005b30 ntdll.dll`LdrUnloadDll + 496
    frame #19222: 0x00007ffddf802979 KernelBase.dll`FreeLibrary + 25
    frame #19223: 0x00007ff79b670d76 functions-bc6b1e7bfc14d1a7.exe`libloading::os::windows::Library::close::_$u7b$$u7b$closure$u7d$$u7d$::h6569003bd33c340f at mod.rs:248:25
    frame #19224: 0x00007ff79b670dfa functions-bc6b1e7bfc14d1a7.exe`libloading::os::windows::with_get_last_error::h05288a6ff5b11dcc(wrap=(functions-bc6b1e7bfc14d1a7.exe`core::ops::function::FnOnce::call_once::h3e274d6b7eeffe13 at function.rs:250), closure={closure_env#1} @ 0x000000e3643ff600) at mod.rs:384:5
    frame #19225: 0x00007ff79b6704cc functions-bc6b1e7bfc14d1a7.exe`libloading::os::windows::Library::close::hdbc65720515e50c7(self=(__0 = 140726972514304)) at mod.rs:247:22
    frame #19226: 0x00007ff79b670fa6 functions-bc6b1e7bfc14d1a7.exe`libloading::safe::Library::close::h60ce41f0bf5a34d0(self=Library @ 0x000000e3643ff6e0) at safe.rs:163:9
    frame #19227: 0x00007ff79b624894 functions-bc6b1e7bfc14d1a7.exe`functions::manual_close_many_times::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h61f718895dea9fc6((null)={closure_env#0} @ 0x000000e3643ff7b7) at functions.rs:205:21
    frame #19228: 0x00007ff79b614b39 functions-bc6b1e7bfc14d1a7.exe`std::sys::backtrace::__rust_begin_short_backtrace::h2b7c386dc932afd5(f={closure_env#0} @ 0x000000e3643ff7f6) at backtrace.rs:152:18
    frame #19229: 0x00007ff79b61f9e9 functions-bc6b1e7bfc14d1a7.exe`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h34b33b572d25be08 at mod.rs:559:17
    frame #19230: 0x00007ff79b6214e1 functions-bc6b1e7bfc14d1a7.exe`_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hda80a62a80afd918(self=<unavailable>, (null)=<unavailable>) at unwind_safe.rs:272:9
    frame #19231: 0x00007ff79b61fd90 functions-bc6b1e7bfc14d1a7.exe`std::panicking::try::do_call::h7f5123721e4e2c12(data="\U00000004") at panicking.rs:589:40
    frame #19232: 0x00007ff79b61fcf8 functions-bc6b1e7bfc14d1a7.exe`__rust_try + 24
    frame #19233: 0x00007ff79b61f621 functions-bc6b1e7bfc14d1a7.exe`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h06b588143189d0f0 [inlined] std::panicking::try::h5c8446479547f809(f=AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<functions::manual_close_many_times::{closure#0}::{closure_env#0}, ()>> @ 0x000000e3643ffa38) at panicking.rs:552:19
    frame #19234: 0x00007ff79b61f576 functions-bc6b1e7bfc14d1a7.exe`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h06b588143189d0f0 [inlined] std::panic::catch_unwind::h0f3613ed9cdfbdf9(f=AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<functions::manual_close_many_times::{closure#0}::{closure_env#0}, ()>> @ 0x000000e3643ffa38) at panic.rs:359:14
    frame #19235: 0x00007ff79b61f576 functions-bc6b1e7bfc14d1a7.exe`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h06b588143189d0f0 at mod.rs:557:30
    frame #19236: 0x00007ff79b61649e functions-bc6b1e7bfc14d1a7.exe`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h063d282d3b2d4b0a((null)=0x000001f2722d3cf0, (null)=<unavailable>) at function.rs:250:5
    frame #19237: 0x00007ff79b6ba82d functions-bc6b1e7bfc14d1a7.exe`std::sys::pal::windows::thread::Thread::new::thread_start::h008373d82c2d2513 at boxed.rs:1966:9
    frame #19238: 0x00007ffde121e8d7 kernel32.dll`BaseThreadInitThunk + 23
    frame #19239: 0x00007ffde203c34c ntdll.dll`RtlUserThreadStart + 44

Metadata

Metadata

Assignees

Labels

A-panicArea: Panicking machineryA-thread-localsArea: Thread local storage (TLS)C-bugCategory: This is a bug.O-windows-gnuToolchain: GNU, Operating system: WindowsS-has-bisectionStatus: A bisection has been found for this issueT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions