Skip to content

Rustc version 1.94.1 fails with error "fatal runtime error: out of TLS keys, aborting" #155758

@lordmulder

Description

@lordmulder

After the Rust toolchain got updated from 1.89.0 to 1.94.1 on Haiku OS, I noticed that my project now fails to build with error:

fatal runtime error: out of TLS keys, aborting

out of TLS keys, aborting (screenshot) Image

I suppose here "TLS" refers to thread-local storage rather than transport layer security 🤔

So, it would seem that the new version of rustc attempts to use more TLS slots (keys) than the operating system can provide.

From what I understand, the maximum number of TLS (thread-local storage) keys is equal to PTHREAD_KEYS_MAX, i.e., the "Maximum number of data keys that can be created by a process". It appears that this constant is platform-specific, but the POSIX standard defines the "Minimum Acceptable Value" as another constant called _POSIX_THREAD_KEYS_MAX – which is defined as 128.

See here:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html


So, this means that rustc probably should be very conservative with the number of TLS keys that it uses, because one must not assume that more than 128 TLS keys are available on any operating system. Nonetheless, it appears that Rust 1.94.1 violates the limit, whereas older Rust versions, such as 1.89.0, have been working flawlessly 😕

To make it clear, the exactly same code used to compile just fine with Rust 1.89.0 on Haiku OS. Also, my code does not even use thread_local! at all! So, I think, this must be a problem with the excessive use of thread_local! in rustc itself, not in my own code. Furthermore, the problem only started after Haiku OS updated their Rust toolchain from 1.89.0 to 1.94.1, so the "problematic" change must be anywhere in between these versions. I cannot say which version exactly broke the build, since rustup does not support Haiku OS yet, so I can only use the Rust version that Haiko OS itself provides (via pkgman).

Best regards.


Might be related:
#147590

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-thread-localsArea: Thread local storage (TLS)C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.O-haikuTarget: Be extant; from mouldering old leaves; spring arrives againT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions