Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify the TLS dialect (Traditional TLS vs. TLSDESC) #805

Open
1 of 3 tasks
ilovepi opened this issue Nov 6, 2024 · 1 comment
Open
1 of 3 tasks
Labels
major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team to-announce Announce this issue on triage meeting

Comments

@ilovepi
Copy link

ilovepi commented Nov 6, 2024

Proposal

Today the Rust compiler doesn't allow users to choose the ELF TLS dialect used to compile their programs. Instead, they get the target defaults set in the backend (LLVM, GCC, etc.), which, while useful, may not always be ideal. ELF TLS supports two variants: traditional TLS, whereby the address of thread local variables is provided through the __tls_get_addr() API, and TLS Descriptors (TLSDESC) that use a custom calling convention to supply the TP offset in a GOT slot filled in by the dynamic linker. TLSDESC is generally more performant than traditional TLS, since it caches results and uses a custom calling convention that avoids most of the overhead of a normal function call.

When using TLSDESC, the compiler emits an instruction sequence with a set of special TLSDESC relocations, and the static linker either fully resolves them (in the case of initial exec or local exec), or supplies the requisite dynamic relocations for the dynamic linker to resolve at runtime.

While the TLS dialect is an important part of a platform's ABI, in most libc implementations it is safe to mix traditional TLS and TLSDESC accesses. This compatibility was part of the design rationale for TLS Descriptors.

To support this code generation option, rustc should support a new flag tls-dialect={trad,desc}. This option name and values were chosen to match existing practices in other compilers. The option's purpose is to configure the code generation backend to emit the correct instruction sequences and relocations. For LLVM, this is the EnableTLSDESC codegen option, which was added in LLVM 18. This option does not change the output LLVM IR, but will affect how LLVM lowers TLS accesses. As of LLVM 19, LLVM supports TLSDESC for x86, x86_64, Aarch64, ARM, and RISC-V. We propose that the the flag start as an unstable -Z option, but should later be stabilized as a -C option.

Mentors or Reviewers

@tmandry @nikic

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@ilovepi ilovepi added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Nov 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2024

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team to-announce Announce this issue on triage meeting
Projects
None yet
Development

No branches or pull requests

2 participants