Skip to content

doctest panics on android #147590

Open
Open

Description

@franklaranja

The panic happens when i run cargo test after the regular test when starting doc tests

Code

see https://github.com/franklaranja/ratatui-garnish/

Meta

This happens on android (termux) tests ok on github. I can only run stable on android

rustc 1.90.0 (1159e78 2025-09-14) (built from a source tarball)
binary: rustc
commit-hash: 1159e78
commit-date: 2025-09-14
host: aarch64-linux-android
release: 1.90.0
LLVM version: 20.1.8

Error output


Doc-tests ratatui_garnish

thread 'rustc' panicked at /home/runner/.termux-build/rust/src/compiler/rustc_data_structures/src/sync/worker_local.rs:28:51:
Unable to verify registry association
stack backtrace:
   0:       0x7a8a46b4f4 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc3639b3aa7cfc006
   1:       0x7a8a4e7bd8 - core::fmt::write::h9abcbe2e3b8912c5
   2:       0x7a8a496948 - <unknown>
   3:       0x7a8a46b3a8 - <unknown>
   4:       0x7a8a49c5e0 - <unknown>
   5:       0x7a8a49c438 - std::panicking::default_hook::h6d511e236e3ee8d0
   6:       0x7a87434868 - <unknown>
   7:       0x7a8a49d008 - std::panicking::rust_panic_with_hook::hb74822548ee3fb9b
   8:       0x7a8a46bfa8 - <unknown>
   9:       0x7a8a46b9d4 - <unknown>
  10:       0x7a8a49ca4c - __rustc[5affb39ba3b5f18]::rust_begin_unwind
  11:       0x7a8a4e640c - core::panicking::panic_fmt::h085f52b3d2bd7b4f
  12:       0x7a89e17474 - rustc_data_structures[6ea44ddc89345541]::outline::<<rustc_data_structures[6ea44ddc89345541]::sync::worker_local::RegistryId>::verify::{closure#1}, usize>
  13:       0x564c962264 - <unknown>
  14:       0x564c9304b0 - <unknown>
  15:       0x564c6c8ba4 - <unknown>
  16:       0x564c6800a0 - <unknown>
  17:       0x564c6cf61c - <unknown>
  18:       0x7a8a4862f4 - <unknown>
  19:       0x7a8abc3a70 - _ZL15__pthread_startPv
  20:       0x7a8ab646e8 - __start_thread

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: rustc 1.90.0 (1159e78c4 2025-09-14) (built from a source tarball) running on aarch64-linux-android

note: compiler flags: --crate-type lib -C embed-bitcode=no

query stack during panic:
end of query stack
error: doctest failed, to rerun pass `--doc`

with backtrace set same output

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Oct 11, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 11, 2025
  3. added
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    O-androidOperating system: Android
    on Oct 11, 2025
  4. fmease commented on Oct 11, 2025

    @fmease
    Member

    Could you please clarify, what are the exact reproduction steps? Are they:

    1. Have host aarch64-linux-android, stable Rust 1.90
    2. Check out franklaranja/ratatui-garnish@087d800
    3. RUSTFLAGS=-Cembed-bitcode=no cargo test
  5. added
    S-needs-infoStatus: The issue lacks details necessary to triage or act on it.
    on Oct 11, 2025
  6. franklaranja commented on Oct 14, 2025

    @franklaranja
    Author

    That is correct, I run rust within termux, which has its own tust packages
    (not rustup). The bug happens when I run cargo test and the testing reaches
    doc_tests.

    To reproduce in termux:

    • install rust packages (apt install ...)
    • clone my repo
    • run cargo test --features=serde,decorated_widget
  7. added
    O-termuxOperating System: Termux on Android, usually referring to host tools
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 2, 2025
  8. Noratrieb commented on Nov 2, 2025

    @Noratrieb
    Member

    if id == self { index } else { outline(|| panic!("Unable to verify registry association")) }
    panic is here, so this looks related to the thread setup.. that's quite weird

  9. 7 remaining items

  10. fmease commented on Nov 12, 2025

    @fmease
    Member

    Could somebody that can reproduce this locally run a bisection please? That would be highly appreciated! I'm not sure if https://github.com/rust-lang/cargo-bisect-rustc is gonna help here since y'all's rustc seems to be built from source (built from a source tarball), so it would probably take too long?

    Even narrowing it down to a smaller nightly or commit range would be perfect!

  11. fnr1r commented on Nov 12, 2025

    @fnr1r

    Could somebody that can reproduce this locally run a bisection please? That would be highly appreciated! I'm not sure if https://github.com/rust-lang/cargo-bisect-rustc is gonna help here since y'all's rustc seems to be built from source (built from a source tarball), so it would probably take too long?

    Even narrowing it down to a smaller nightly or commit range would be perfect!

    I have never built Rust from source and I have only built one package for Termux, but I have some time so I guess I'll try.

    Just from looking at https://github.com/termux/termux-packages/tree/master/packages/rust one patch that might be causing issues is https://github.com/termux/termux-packages/blob/master/packages/rust/0007-use-emulated-tls-on-android.patch (due to being related to TLS) so maybe it's a downstream issue. I haven't ran cargo doc on Termux before (or at least I don't remember it), but that patch is 2 months old (rust 1.90 release) (termux/termux-packages#26733), so it might be it?

    Cargo doc and test are also not tested regularly. That might have caught the issue earlier.

    I'll comment if I find something more.

  12. fnr1r commented on Nov 12, 2025

    @fnr1r

    I updated to 1.91.1 and cargo doc now works? Can OP test this version too?

    EDIT: Actually, no. It worked only for some packages.

  13. robertkirkman commented on Nov 26, 2025

    @robertkirkman

    I have determined that the downstream patch https://github.com/termux/termux-packages/blob/1c8de6cbfb16473e3e2a7ce7835847846ae1f246/packages/rust/0007-use-emulated-tls-on-android.patch is what causes this error, because applying the patch to Rust 1.89.0, which doesn't normally have this error, causes the error to appear (when rustdoc --test testdoctest.rs is used on a file like this)

    /// ```rust
    /// let x = 5;
    /// ```
    fn main() {}

    However, Rust 1.90.0 and newer don't work on Android if https://github.com/termux/termux-packages/blob/1c8de6cbfb16473e3e2a7ce7835847846ae1f246/packages/rust/0007-use-emulated-tls-on-android.patch is removed, because then rustc has this other error when attempting to compile anything:

    fatal runtime error: out of TLS keys, aborting
    

    I don't know anything else right now, but I might continue trying to look for, for example, the exact commit at which https://github.com/termux/termux-packages/blob/1c8de6cbfb16473e3e2a7ce7835847846ae1f246/packages/rust/0007-use-emulated-tls-on-android.patch becomes required to prevent fatal runtime error: out of TLS keys, aborting.

  14. 12101111 commented on Nov 26, 2025

    @12101111
    Contributor

    I also get this error on aarch64-unknown-linux-ohos.

    1. without any patch
    fatal runtime error: out of TLS keys, aborting
    
    1. has_thread_local: true + tls_model: TlsModel::Emulated
    thread 'rustc' (56347) panicked at /rustc-dev/d8a7534127d3d91d42b86decfcd4ef20429ac480/compiler/rustc_data_structures/src/sync/worker_local.rs:28:51:
    Unable to verify registry association
    stack backtrace:
       0:       0x59e421bfa0 - std[cbc5d805ca13eeb3]::backtrace_rs::backtrace::libunwind::trace
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
       1:       0x59e421bfa0 - std[cbc5d805ca13eeb3]::backtrace_rs::backtrace::trace_unsynchronized::<std[cbc5d805ca13eeb3]::sys::backtrace::_print_fmt::{closure#1}>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
       2:       0x59e421bfa0 - std[cbc5d805ca13eeb3]::sys::backtrace::_print_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:66:9
       3:       0x59e421bfa0 - <<std[cbc5d805ca13eeb3]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d162060d7af4f0b6]::fmt::Display>::fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:39:26
       4:       0x59e425f354 - <core[d162060d7af4f0b6]::fmt::rt::Argument>::fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/fmt/rt.rs:152:76
       5:       0x59e425f354 - core[d162060d7af4f0b6]::fmt::write
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/fmt/mod.rs:1686:22
       6:       0x59e422e848 - std[cbc5d805ca13eeb3]::io::default_write_fmt::<std[cbc5d805ca13eeb3]::sys::stdio::unix::Stderr>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/io/mod.rs:639:11
       7:       0x59e422e848 - <std[cbc5d805ca13eeb3]::sys::stdio::unix::Stderr as std[cbc5d805ca13eeb3]::io::Write>::write_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/io/mod.rs:1994:13
       8:       0x59e41f1bfc - <std[cbc5d805ca13eeb3]::sys::backtrace::BacktraceLock>::print
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:42:9
       9:       0x59e41f1bfc - std[cbc5d805ca13eeb3]::panicking::default_hook::{closure#0}
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:293:27
      10:       0x59e4211708 - std[cbc5d805ca13eeb3]::panicking::default_hook
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:320:9
      11:       0x59dde7d634 - std[cbc5d805ca13eeb3]::panicking::update_hook::<alloc[7ad63f376f727987]::boxed::Box<rustc_driver_impl[8fe2940da699b314]::install_ice_hook::{closure#1}>>::{closure#0}
      12:       0x59e42119cc - <alloc[7ad63f376f727987]::boxed::Box<dyn for<'a, 'b> core[d162060d7af4f0b6]::ops::function::Fn<(&'a std[cbc5d805ca13eeb3]::panic::PanicHookInfo<'b>,), Output = ()> + core[d162060d7af4f0b6]::marker::Send + core[d162060d7af4f0b6]::marker::Sync> as core[d162060d7af4f0b6]::ops::function::Fn<(&std[cbc5d805ca13eeb3]::panic::PanicHookInfo,)>>::call
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/alloc/src/boxed.rs:2099:9
      13:       0x59e42119cc - std[cbc5d805ca13eeb3]::panicking::panic_with_hook
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:834:13
      14:       0x59e41f1cdc - std[cbc5d805ca13eeb3]::panicking::panic_handler::{closure#0}
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:692:13
      15:       0x59e41e9f0c - std[cbc5d805ca13eeb3]::sys::backtrace::__rust_end_short_backtrace::<std[cbc5d805ca13eeb3]::panicking::panic_handler::{closure#0}, !>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:174:18
      16:       0x59e41f351c - __rustc[21bce60f618d277c]::rust_begin_unwind
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:690:5
      17:       0x59e425fb7c - core[d162060d7af4f0b6]::panicking::panic_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/panicking.rs:80:14
      18:       0x59e3be1240 - rustc_data_structures[af341a7d1e2457bf]::outline::<<rustc_data_structures[af341a7d1e2457bf]::sync::worker_local::RegistryId>::verify::{closure#1}, usize>
      19:       0x55d278fb6c - <rustc_interface[289c6b373e50f06b]::passes::create_and_enter_global_ctxt<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}::{closure#0}>::{closure#2} as core[d162060d7af4f0b6]::ops::function::FnOnce<(&rustc_session[9a514b92e590e2fc]::session::Session, rustc_middle[2b4d2c4225f0e231]::ty::context::CurrentGcx, alloc[7ad63f376f727987]::sync::Arc<rustc_data_structures[af341a7d1e2457bf]::jobserver::Proxy>, &std[cbc5d805ca13eeb3]::sync::once_lock::OnceLock<rustc_middle[2b4d2c4225f0e231]::ty::context::GlobalCtxt>, &rustc_data_structures[af341a7d1e2457bf]::sync::worker_local::WorkerLocal<rustc_middle[2b4d2c4225f0e231]::arena::Arena>, &rustc_data_structures[af341a7d1e2457bf]::sync::worker_local::WorkerLocal<rustc_hir[3d988a60c0c5d2f2]::Arena>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}::{closure#0})>>::call_once::{shim:vtable#0}
      20:       0x55d2767668 - rustc_interface[289c6b373e50f06b]::passes::create_and_enter_global_ctxt::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}::{closure#0}>
      21:       0x55d25e48d0 - rustc_interface[289c6b373e50f06b]::interface::run_compiler::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}
      22:       0x55d25b6280 - <scoped_tls[c525e78f5bd7eef9]::ScopedKey<rustc_span[6cc4a76dac6090ee]::SessionGlobals>>::set::<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>
      23:       0x55d2562cf0 - rustc_span[6cc4a76dac6090ee]::create_session_globals_then::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}::{closure#0}>
      24:       0x55d25cb69c - std[cbc5d805ca13eeb3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>
      25:       0x55d25e84e4 - <<std[cbc5d805ca13eeb3]::thread::Builder>::spawn_unchecked_<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#1} as core[d162060d7af4f0b6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
      26:       0x59e421997c - <alloc[7ad63f376f727987]::boxed::Box<dyn core[d162060d7af4f0b6]::ops::function::FnOnce<(), Output = ()>> as core[d162060d7af4f0b6]::ops::function::FnOnce<()>>::call_once
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/alloc/src/boxed.rs:2085:9
      27:       0x59e421997c - <std[cbc5d805ca13eeb3]::sys::thread::unix::Thread>::new::thread_start
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/thread/unix.rs:124:17
      28:       0x59d71949b0 - <unknown>
    
    error: the compiler unexpectedly panicked. this is a bug.
    
    note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md
    
    note: please make sure that you have updated to the latest nightly
    
    note: please attach the file at `/storage/Users/currentUser/rustc-ice-2025-11-26T15_55_42-56345.txt` to your bug report
    
    query stack during panic:
    end of query stack
    
    1. has_thread_local: true + tls_model: TlsModel::GeneralDynamic
    thread 'rustc' (21531) panicked at /rustc-dev/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/thread/local.rs:474:25:
    cannot access a Thread Local Storage value during or after destruction: AccessError
    stack backtrace:
       0:       0x5a0f91c5f0 - std[cbc5d805ca13eeb3]::backtrace_rs::backtrace::libunwind::trace
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
       1:       0x5a0f91c5f0 - std[cbc5d805ca13eeb3]::backtrace_rs::backtrace::trace_unsynchronized::<std[cbc5d805ca13eeb3]::sys::backtrace::_print_fmt::{closure#1}>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
       2:       0x5a0f91c5f0 - std[cbc5d805ca13eeb3]::sys::backtrace::_print_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:66:9
       3:       0x5a0f91c5f0 - <<std[cbc5d805ca13eeb3]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d162060d7af4f0b6]::fmt::Display>::fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:39:26
       4:       0x5a0f95f9f8 - <core[d162060d7af4f0b6]::fmt::rt::Argument>::fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/fmt/rt.rs:152:76
       5:       0x5a0f95f9f8 - core[d162060d7af4f0b6]::fmt::write
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/fmt/mod.rs:1686:22
       6:       0x5a0f92eef8 - std[cbc5d805ca13eeb3]::io::default_write_fmt::<std[cbc5d805ca13eeb3]::sys::stdio::unix::Stderr>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/io/mod.rs:639:11
       7:       0x5a0f92eef8 - <std[cbc5d805ca13eeb3]::sys::stdio::unix::Stderr as std[cbc5d805ca13eeb3]::io::Write>::write_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/io/mod.rs:1994:13
       8:       0x5a0f8f2148 - <std[cbc5d805ca13eeb3]::sys::backtrace::BacktraceLock>::print
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:42:9
       9:       0x5a0f8f2148 - std[cbc5d805ca13eeb3]::panicking::default_hook::{closure#0}
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:293:27
      10:       0x5a0f911cac - std[cbc5d805ca13eeb3]::panicking::default_hook
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:320:9
      11:       0x5a09578524 - std[cbc5d805ca13eeb3]::panicking::update_hook::<alloc[7ad63f376f727987]::boxed::Box<rustc_driver_impl[8fe2940da699b314]::install_ice_hook::{closure#1}>>::{closure#0}
      12:       0x5a0f911f7c - <alloc[7ad63f376f727987]::boxed::Box<dyn for<'a, 'b> core[d162060d7af4f0b6]::ops::function::Fn<(&'a std[cbc5d805ca13eeb3]::panic::PanicHookInfo<'b>,), Output = ()> + core[d162060d7af4f0b6]::marker::Send + core[d162060d7af4f0b6]::marker::Sync> as core[d162060d7af4f0b6]::ops::function::Fn<(&std[cbc5d805ca13eeb3]::panic::PanicHookInfo,)>>::call
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/alloc/src/boxed.rs:2099:9
      13:       0x5a0f911f7c - std[cbc5d805ca13eeb3]::panicking::panic_with_hook
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:834:13
      14:       0x5a0f8f21fc - std[cbc5d805ca13eeb3]::panicking::panic_handler::{closure#0}
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:699:13
      15:       0x5a0f8ea444 - std[cbc5d805ca13eeb3]::sys::backtrace::__rust_end_short_backtrace::<std[cbc5d805ca13eeb3]::panicking::panic_handler::{closure#0}, !>
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/backtrace.rs:174:18
      16:       0x5a0f8f3a68 - __rustc[21bce60f618d277c]::rust_begin_unwind
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/panicking.rs:690:5
      17:       0x5a0f960220 - core[d162060d7af4f0b6]::panicking::panic_fmt
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/core/src/panicking.rs:80:14
      18:       0x5a0f914a34 - std[cbc5d805ca13eeb3]::thread::local::panic_access_error
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/thread/local.rs:430:5
      19:       0x5a0ee9d704 - rustc_attr_parsing[b8a4dba210d059e7]::context::early::ATTRIBUTE_PARSERS::{closure#0}::{closure#7}
      20:       0x5a0ef2a5c4 - <rustc_attr_parsing[b8a4dba210d059e7]::interface::AttributeParser<rustc_attr_parsing[b8a4dba210d059e7]::context::Early>>::parse_limited_all
      21:       0x5a0ef2a930 - <rustc_attr_parsing[b8a4dba210d059e7]::interface::AttributeParser<rustc_attr_parsing[b8a4dba210d059e7]::context::Early>>::parse_limited_should_emit
      22:       0x5a096e4db8 - rustc_interface[289c6b373e50f06b]::passes::get_crate_name
      23:       0x55a1984c28 - rustc_interface[289c6b373e50f06b]::passes::create_and_enter_global_ctxt::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}::{closure#0}>
      24:       0x55a18023c4 - rustc_interface[289c6b373e50f06b]::interface::run_compiler::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}
      25:       0x55a17d3d74 - <scoped_tls[c525e78f5bd7eef9]::ScopedKey<rustc_span[6cc4a76dac6090ee]::SessionGlobals>>::set::<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>
      26:       0x55a1780708 - rustc_span[6cc4a76dac6090ee]::create_session_globals_then::<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}::{closure#0}>
      27:       0x55a17e9190 - std[cbc5d805ca13eeb3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>
      28:       0x55a1805fd8 - <<std[cbc5d805ca13eeb3]::thread::Builder>::spawn_unchecked_<rustc_interface[289c6b373e50f06b]::util::run_in_thread_with_globals<rustc_interface[289c6b373e50f06b]::util::run_in_thread_pool_with_globals<rustc_interface[289c6b373e50f06b]::interface::run_compiler<core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>, rustdoc[324ecc7f413ae89b]::doctest::run::{closure#2}>::{closure#1}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#0}::{closure#0}, core[d162060d7af4f0b6]::result::Result<core[d162060d7af4f0b6]::option::Option<rustdoc[324ecc7f413ae89b]::doctest::CreateRunnableDocTests>, alloc[7ad63f376f727987]::string::String>>::{closure#1} as core[d162060d7af4f0b6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
      29:       0x5a0f919fb8 - <alloc[7ad63f376f727987]::boxed::Box<dyn core[d162060d7af4f0b6]::ops::function::FnOnce<(), Output = ()>> as core[d162060d7af4f0b6]::ops::function::FnOnce<()>>::call_once
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/alloc/src/boxed.rs:2085:9
      30:       0x5a0f919fb8 - <std[cbc5d805ca13eeb3]::sys::thread::unix::Thread>::new::thread_start
                                   at /rustc/d8a7534127d3d91d42b86decfcd4ef20429ac480/library/std/src/sys/thread/unix.rs:124:17
      31:       0x5a0288b9b0 - <unknown>
    
    error: the compiler unexpectedly panicked. this is a bug.
    
    note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md
    
    note: please make sure that you have updated to the latest nightly
    
    note: please attach the file at `/storage/Users/currentUser/rustc-ice-2025-11-26T16_42_49-21430.txt` to your bug report
    
    query stack during panic:
    end of query stack
    
  15. 12101111 commented on Nov 28, 2025

    @12101111
    Contributor

    tls-dylib-access.rs is failed on android and ohos target with has_thread_local: true + tls_model: TlsModel::Emulated.

    Reproduce it on termux:

    $ export RUSTC_BOOTSTRAP=1
    $ rustc tls-rlib.rs
    $ rustc tls-export.rs -Cprefer-dynamic -Crpath --crate-type dylib -L.
    $ rustc tls-dylib-access.rs -C prefer-dynamic -Crpath -L.
    $  ./tls-dylib-access
    
    thread 'main' (5758) panicked at tls-dylib-access.rs:10:9:
    assertion `left == right` failed
      left: 12970367466561078328
     right: 12970367466561077848
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

    Run the test in lldb:

    ~ $ lldb ./tls-dylib-access
    (lldb) target create "./tls-dylib-access"
    Current executable set to '/data/data/com.termux/files/home/tls-dylib-access' (aarch64).
    Cannot read termcap database;
    using dumb terminal settings.
    (lldb) b emutls_init
    Breakpoint 1: 2 locations.
    (lldb) b __emutls_get_address
    Breakpoint 2: 2 locations.
    (lldb) r
    Process 13945 launched: '/data/data/com.termux/files/home/tls-dylib-access' (aarch64)
    Process 13945 stopped
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 2.1
        frame #0: 0x0000005555556b4c tls-dylib-access`__emutls_get_address
    tls-dylib-access`__emutls_get_address:
    ->  0x5555556b4c <+0>:  str    x30, [sp, #-0x40]!
        0x5555556b50 <+4>:  stp    x24, x23, [sp, #0x10]
        0x5555556b54 <+8>:  add    x8, x0, #0x10
        0x5555556b58 <+12>: stp    x22, x21, [sp, #0x20]
    (lldb) bt
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 2.1
      * frame #0: 0x0000005555556b4c tls-dylib-access`__emutls_get_address
        frame #1: 0x0000005555556974 tls-dylib-access`tls_dylib_access::main::hd497eb13dbbca51d + 24
        frame #2: 0x0000005555556ac0 tls-dylib-access`core::ops::function::FnOnce::call_once::ha98823e438d8f2d7 + 16
        frame #3: 0x0000005555556a88 tls-dylib-access`std::sys::backtrace::__rust_begin_short_backtrace::heed4481fb75603b5 + 12
        frame #4: 0x0000005555556a6c tls-dylib-access`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h51efc2d3ab0b6722 + 16
        frame #5: 0x0000007ff2f4b360 libstd-fce350f671e5340e.so`rust_metadata_std_a3a449c00bfac023 + 791392
        frame #6: 0x0000005555556a50 tls-dylib-access`std::rt::lang_start::h320b62f640b565f5 + 60
        frame #7: 0x0000005555556b44 tls-dylib-access`main + 36
        frame #8: 0x0000007fef7248b0 libc.so`__libc_init + 128
    (lldb) c
    Process 13945 resuming
    Process 13945 stopped
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 1.1
        frame #0: 0x0000005555556d2c tls-dylib-access`emutls_init
    tls-dylib-access`emutls_init:
    ->  0x5555556d2c <+0>:  str    x30, [sp, #-0x10]!
        0x5555556d30 <+4>:  adrp   x0, 13
        0x5555556d34 <+8>:  add    x0, x0, #0x94 ; emutls_pthread_key
        0x5555556d38 <+12>: nop
    (lldb) bt
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 1.1
      * frame #0: 0x0000005555556d2c tls-dylib-access`emutls_init
        frame #1: 0x0000007fef73da10 libc.so`pthread_once + 144
        frame #2: 0x0000005555556be4 tls-dylib-access`__emutls_get_address + 152
        frame #3: 0x0000005555556974 tls-dylib-access`tls_dylib_access::main::hd497eb13dbbca51d + 24
        frame #4: 0x0000005555556ac0 tls-dylib-access`core::ops::function::FnOnce::call_once::ha98823e438d8f2d7 + 16
        frame #5: 0x0000005555556a88 tls-dylib-access`std::sys::backtrace::__rust_begin_short_backtrace::heed4481fb75603b5 + 12
        frame #6: 0x0000005555556a6c tls-dylib-access`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h51efc2d3ab0b6722 + 16
        frame #7: 0x0000007ff2f4b360 libstd-fce350f671e5340e.so`rust_metadata_std_a3a449c00bfac023 + 791392
        frame #8: 0x0000005555556a50 tls-dylib-access`std::rt::lang_start::h320b62f640b565f5 + 60
        frame #9: 0x0000005555556b44 tls-dylib-access`main + 36
        frame #10: 0x0000007fef7248b0 libc.so`__libc_init + 128
    (lldb) c
    Process 13945 resuming
    Process 13945 stopped
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 2.2
        frame #0: 0x0000007ff6aa9c34 libtls_export.so`__emutls_get_address
    libtls_export.so`__emutls_get_address:
    ->  0x7ff6aa9c34 <+0>:  str    x30, [sp, #-0x40]!
        0x7ff6aa9c38 <+4>:  stp    x24, x23, [sp, #0x10]
        0x7ff6aa9c3c <+8>:  add    x8, x0, #0x10
        0x7ff6aa9c40 <+12>: stp    x22, x21, [sp, #0x20]
    (lldb) bt
    * thread #1, name = 'tls-dylib-acces', stop reason = breakpoint 2.2
      * frame #0: 0x0000007ff6aa9c34 libtls_export.so`__emutls_get_address
        frame #1: 0x0000007ff6aa9c10 libtls_export.so`tls_export::foo_addr::h319c937fbca75710 + 20
        frame #2: 0x000000555555697c tls-dylib-access`tls_dylib_access::main::hd497eb13dbbca51d + 32
        frame #3: 0x0000005555556ac0 tls-dylib-access`core::ops::function::FnOnce::call_once::ha98823e438d8f2d7 + 16
        frame #4: 0x0000005555556a88 tls-dylib-access`std::sys::backtrace::__rust_begin_short_backtrace::heed4481fb75603b5 + 12
        frame #5: 0x0000005555556a6c tls-dylib-access`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h51efc2d3ab0b6722 + 16
        frame #6: 0x0000007ff2f4b360 libstd-fce350f671e5340e.so`rust_metadata_std_a3a449c00bfac023 + 791392
        frame #7: 0x0000005555556a50 tls-dylib-access`std::rt::lang_start::h320b62f640b565f5 + 60
        frame #8: 0x0000005555556b44 tls-dylib-access`main + 36
        frame #9: 0x0000007fef7248b0 libc.so`__libc_init + 128
    (lldb) c
    Process 13945 resuming
    
    thread 'main' (13945) panicked at tls-dylib-access.rs:10:9:
    assertion `left == right` failed
      left: 12970367467446330552
     right: 12970367467446330456
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    Process 13945 exited with status = 101 (0x00000065)

    What happend here?

    1. libstd.so, binary and dylib all contain a local copy of emutls.c

    Binary files from termux are stripped, so I use ohos to demonstrate.

    > readelf -s stage1/lib/rustlib/x86_64-unknown-linux-ohos/lib/libstd-523992909fa215f1.so | grep emutls | grep -v __emutls_v | grep -v __emutls_t
      1106: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS emutls.c
      1107: 0000000000135cdc     4 OBJECT  LOCAL  DEFAULT    23 emutls_pthread_key
      1108: 0000000000135cd8     4 OBJECT  LOCAL  DEFAULT    23 emutls_init_once.once
      1109: 0000000000122e20    31 FUNC    LOCAL  DEFAULT    12 emutls_init
      1110: 0000000000135ce0    40 OBJECT  LOCAL  DEFAULT    23 emutls_mutex
      1111: 0000000000135cd0     8 OBJECT  LOCAL  DEFAULT    23 emutls_num_object
      1112: 0000000000122e40   112 FUNC    LOCAL  DEFAULT    12 emutls_key_destructor
      1113: 0000000000122c60   437 FUNC    LOCAL  DEFAULT    12 __emutls_get_address
      1231: 00000000001298d0     6 FUNC    LOCAL  HIDDEN     12 __emutls_unregister_key
    > readelf -s x86_64-unknown-linux-ohos/stage2/bin/rustdoc | grep emutls | grep -v __emutls_v | grep -v __emutls_t
      1547: 0000000000afa2f0   437 FUNC    WEAK   DEFAULT    13 __emutls_get_address
     22518: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS emutls.c
     22519: 0000000000b69984     4 OBJECT  LOCAL  DEFAULT    24 emutls_pthread_key
     22520: 0000000000b69980     4 OBJECT  LOCAL  DEFAULT    24 emutls_init_once.once
     22521: 0000000000afa4b0    31 FUNC    LOCAL  DEFAULT    13 emutls_init
     22522: 0000000000b69988    40 OBJECT  LOCAL  DEFAULT    24 emutls_mutex
     22523: 0000000000b69978     8 OBJECT  LOCAL  DEFAULT    24 emutls_num_object
     22524: 0000000000afa4d0   112 FUNC    LOCAL  DEFAULT    13 emutls_key_destructor
     22529: 0000000000afa540     6 FUNC    LOCAL  HIDDEN     13 __emutls_unregister_key
     23409: 0000000000afa2f0   437 FUNC    WEAK   DEFAULT    13 __emutls_get_address
    > readelf -s x86_64-unknown-linux-ohos/stage2/lib/librustc_driver-225070c7305ef612.so | grep emutls | grep -v __emutls_v | grep -v __emutls_t
    375384: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS emutls.c
    375385: 000000000c0eaa1c     4 OBJECT  LOCAL  DEFAULT    23 emutls_pthread_key
    375386: 000000000c0eaa18     4 OBJECT  LOCAL  DEFAULT    23 emutls_init_once.once
    375387: 000000000bb964f0    31 FUNC    LOCAL  DEFAULT    12 emutls_init
    375388: 000000000c0eaa20    40 OBJECT  LOCAL  DEFAULT    23 emutls_mutex
    375389: 000000000c0eaa10     8 OBJECT  LOCAL  DEFAULT    23 emutls_num_object
    375390: 000000000bb96510   112 FUNC    LOCAL  DEFAULT    12 emutls_key_destructor
    375391: 000000000bb96330   437 FUNC    LOCAL  DEFAULT    12 __emutls_get_address
    375396: 000000000bb96580     6 FUNC    LOCAL  HIDDEN     12 __emutls_unregister_key
    > readelf -s test/ui/thread-local/tls-dylib-access/a | grep emutls | grep -v __emutls_v | grep -v __emutls_t
        18: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS emutls.c
        19: 000000000000470c     4 OBJECT  LOCAL  DEFAULT    23 emutls_pthread_key
        20: 0000000000004708     4 OBJECT  LOCAL  DEFAULT    23 emutls_init_once.once
        21: 0000000000002160    31 FUNC    LOCAL  DEFAULT    12 emutls_init
        22: 0000000000004710    40 OBJECT  LOCAL  DEFAULT    23 emutls_mutex
        23: 0000000000004700     8 OBJECT  LOCAL  DEFAULT    23 emutls_num_object
        24: 0000000000002180   112 FUNC    LOCAL  DEFAULT    12 emutls_key_destructor
        29: 00000000000021f0     6 FUNC    LOCAL  HIDDEN     12 __emutls_unregister_key
        43: 0000000000001fa0   437 FUNC    WEAK   DEFAULT    12 __emutls_get_address
    > readelf -s test/ui/thread-local/tls-dylib-access/auxiliary/libtls_export.so | grep emutls | grep -v __emutls_v | grep -v __emutls_t
        18: 0000000000000000     0 FILE    LOCAL  DEFAULT   ABS emutls.c
        19: 0000000000004304     4 OBJECT  LOCAL  DEFAULT    21 emutls_pthread_key
        20: 0000000000004300     4 OBJECT  LOCAL  DEFAULT    21 emutls_init_once.once
        21: 0000000000001e00    31 FUNC    LOCAL  DEFAULT    11 emutls_init
        22: 0000000000004308    40 OBJECT  LOCAL  DEFAULT    21 emutls_mutex
        23: 00000000000042f8     8 OBJECT  LOCAL  DEFAULT    21 emutls_num_object
        24: 0000000000001e20   112 FUNC    LOCAL  DEFAULT    11 emutls_key_destructor
        25: 0000000000001c40   437 FUNC    LOCAL  DEFAULT    11 __emutls_get_address
        30: 0000000000001e90     6 FUNC    LOCAL  HIDDEN     11 __emutls_unregister_key
    
    1. Binary accesses TLS by load the address of __emutls_control object and calling __emutls_get_address from binary. The __emutls_control object is stored in dylib and exported as a symbol. So binary and dylib will see the same address.
    > readelf -s test/ui/thread-local/tls-dylib-access/auxiliary/libtls_export.so | grep __emutls_v
        19: 0000000000004268    32 OBJECT  GLOBAL DEFAULT    20 __emutls_v._RNvCs1ZqgkrWgB2H_10tls_export3FOO
        21: 0000000000004288    32 OBJECT  GLOBAL DEFAULT    20 __emutls_v._RNvCskSH5uoIzYRr_8tls_rlib3BAR
        36: 0000000000004268    32 OBJECT  GLOBAL DEFAULT    20 __emutls_v._RNvCs1ZqgkrWgB2H_10tls_export3FOO
        38: 0000000000004288    32 OBJECT  GLOBAL DEFAULT    20 __emutls_v._RNvCskSH5uoIzYRr_8tls_rlib3BAR
    > readelf -s test/ui/thread-local/tls-dylib-access/a | grep __emutls_v
         7: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   UND __emutls_v._RNvCs1ZqgkrWgB2H_10tls_export3FOO
         9: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   UND __emutls_v._RNvCskSH5uoIzYRr_8tls_rlib3BAR
        42: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   UND __emutls_v._RNvCs1ZqgkrWgB2H_10tls_export3FOO
        45: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   UND __emutls_v._RNvCskSH5uoIzYRr_8tls_rlib3BAR
    1. __emutls_control->index is 0 and emutls_init_once is called. emutls_pthread_key from binary is initialized.
    2. Code from dylib tries to access the same variable, and __emutls_get_address from dylib is called.
    3. __emutls_control->index is not 0, and emutls_getspecific is called. But emutls_pthread_key from dylib is 0, so pthread_getspecific(0) is called, which is invalid.
    4. invalid address is used.

    How to fix this

    When building dylib and cdylib, __emutls_get_address should be a weak exported symbol, when emutls is used.

    ref:

  16. robertkirkman commented on Nov 29, 2025

    @robertkirkman

    Could somebody that can reproduce this locally run a bisection please?

    I have bisected the commit where the commands rustdoc --test testdoctest.rs (of a basic documentation comment) and cargo build (of a hello world) begin to have the error fatal runtime error: out of TLS keys, aborting on Android. It is this.

    ad635e5

    All commits before that commit (going back to rust 1.89) are able to run rustdoc and cargo build successfully, and that commit and all commits after that commit are not able to, and have the error fatal runtime error: out of TLS keys, aborting instead.

    The 0007-use-emulated-tls-on-android.patch fixes cargo build after that commit for the majority of projects, but does not fix rustdoc --test testdoctest.rs, which instead gets the crash reported in the initial comment here, instead of fatal runtime error: out of TLS keys, aborting.

  17. eggyal commented on Feb 24, 2026

    @eggyal
    Contributor

    Could somebody that can reproduce this locally run a bisection please?

    I have bisected the commit where the commands rustdoc --test testdoctest.rs (of a basic documentation comment) and cargo build (of a hello world) begin to have the error fatal runtime error: out of TLS keys, aborting on Android. It is this.

    ad635e5

    Regression in #143779 cc @JonathanBrouwer @oli-obk
    @rustbot label -E-needs-bisection

  18. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Feb 24, 2026
  19. kayabaNerve commented on Feb 24, 2026

    @kayabaNerve

    Anecdotally, and this isn't the right issue but it's a relevant issue and I want to leave the comment somewhere:

    Rust 1.90.0's rustc, when built with mrustc, also runs out of TLS keys when then used to compile itself on a x86_64-unknown-linux-musl target (where musl also only offers 128 keys, the only amount required to be present under POSIX standards). That isn't an official way to build Rust, and doesn't appear when rustc 1.89.0 builds rustc 1.90.0 nor when rustc 1.90.0 a built by a rustc proper builds rustc 1.91.1.

    While Rust 1.90.0, officially, is observed to fail on Android due to TLS issues, Rust 1.90.0 is borderline w.r.t. the amount of keys used for other targets too and can still cause such problems even on other targets if one bumps the table.

  20. JonathanBrouwer commented on Feb 24, 2026

    @JonathanBrouwer
    Member

    Could somebody that can reproduce this locally run a bisection please?

    I have bisected the commit where the commands rustdoc --test testdoctest.rs (of a basic documentation comment) and cargo build (of a hello world) begin to have the error fatal runtime error: out of TLS keys, aborting on Android. It is this.
    ad635e5

    Regression in #143779 cc @JonathanBrouwer @oli-obk @rustbot label -E-needs-bisection

    The PR just slightly increases the amount of threadlocal storage used, because attribute parsers live in thread-local storage. Changing this would be difficult.

  21. robertkirkman commented on Jul 2, 2026

    @robertkirkman

    In Rust version 1.96.0, I'm no longer able to reproduce this issue on my device, even when the 0007-use-emulated-tls-on-android.patch is removed, with any of the tests that could previously reproduce it. This could mean that the issue is no longer reproducible, or it could mean that it is still reproducible, but now requires a different setup that isn't known yet.

  22. robertkirkman commented on Jul 25, 2026

    @robertkirkman

    Update: after help from others in the equivalent issue for Haiku, I have again successfully reproduced this error in Android (only when the 0007-use-emulated-tls-on-android.patch currently used as a workaround by Termux is removed) using these commands:

    git clone  https://github.com/chitao1234/haiku-tls-key-trigger.git
    cd haiku-tls-key-trigger
    cargo build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️O-androidOperating system: AndroidO-termuxOperating System: Termux on Android, usually referring to host toolsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc 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