Skip to content

[rtabi64?] Add method for Software-based TLS Pointer Retrieval #316

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

Open
xerpi opened this issue Mar 19, 2025 · 3 comments
Open

[rtabi64?] Add method for Software-based TLS Pointer Retrieval #316

xerpi opened this issue Mar 19, 2025 · 3 comments

Comments

@xerpi
Copy link

xerpi commented Mar 19, 2025

This proposal requests the addition of a method for software-based TLS pointer retrieval in the AArch64 ABI. A proposed implementation, similar to the approach used in AArch32 with __aeabi_read_tp(), is outlined in llvm/llvm-project#130932.

In that implementation, an option is provided to obtain the TLS pointer via a call to a user/libc-defined __aarch64_read_tp() (enabled with the -mtp=soft flag in clang), which is necessary for platforms like Nintendo Switch Horizon OS. On such systems, the TLS pointer is determined by a calculated offset from TPIDR_EL0 rather than being directly accessible from a dedicated register.

@smithp35
Copy link
Contributor

Thanks for raising the issue. I've started a discussion internally. There looks to be some precedent for using __arch64_ as a prefix for runtime functions as compiler-rt already has __aarch64_sme_accessible(void)

For now I'm planning to add to #311 which describes thread local storage.

Strictly speaking this is runtime abi (not specific to sysvabi) but we don't have a 64-bit equivalent to the rtabi32 yet. If we create one, then I expect the description to move.

@xerpi xerpi changed the title [sysvabi64] Add method for Software-based TLS Pointer Retrieval [rtabi64?] Add method for Software-based TLS Pointer Retrieval Mar 19, 2025
@Wilco1
Copy link
Contributor

Wilco1 commented Mar 26, 2025

What is the actual sequence to get the TLS pointer? If it's an indirection at a fixed offset from TPIDR_EL0 then that could be emitted by compilers to avoid the overhead of a call.

@kitlith
Copy link

kitlith commented Mar 28, 2025

When using devkitA64 (i.e. patched GCC including -mtp=soft for aarch64 using the above proposed scheme), libnx implements __aarch64_read_tp() here:

https://github.com/switchbrew/libnx/blob/2e2b110668633169bb97f938d219cca0cfc0831d/nx/source/runtime/readtp.s#L6-L9

Minor note, it's pulling from TPIDRRO_EL0, not TPIDR_EL0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants