This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add an option to get the TLS pointer from software
Needs ReviewPublic

Authored by Thog on Apr 27 2019, 8:44 AM.

Details

Reviewers
t.p.northover
Summary

This patch adds an option to get the TLS pointer via a call to aarch64_read_tp() (similar to aeabi_read_tp on AArch32).

Necessary on Nintendo Horizon OS, which puts the TLS pointer at a calculated offset from TPIDR_EL0.

Diff Detail

Event Timeline

Thog created this revision.Apr 27 2019, 8:44 AM

How did you come up with the name __aarch64_read_tp? I guess it's okay.

which puts the TLS pointer at a calculated offset from TPIDR_EL0

I don't really understand how this is different from normal ELF TLS; does the offset vary at runtime somehow?

lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
525

Is this addReg necessary? The definition of X0 is an implicit definition, so it should be copied by transferImpOps, unless I'm missing something.

RegState::Dead doesn't make any sense.

test/CodeGen/AArch64/readtp.ll
11

Would it make sense to modify one of the existing tests for this, like arm64-tls-dynamics.ll, instead of adding a separate test file?

t.p.northover added inline comments.May 1 2019, 4:42 AM
lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
525

It's also non-implicit (which I'm surprised MCInstrDesc doesn't complain about), and a use rather than a def.

lib/Target/AArch64/AArch64Subtarget.h
379

Functions start lower case.

Thog added a comment.May 1 2019, 10:35 AM

How did you come up with the name __aarch64_read_tp? I guess it's okay.

That is how devkitPro's fork of GCC calls it.
There is no standard name for it since AArch64 ABI doesn't define a soft-tp interface.

I don't really understand how this is different from normal ELF TLS; does the offset vary at runtime somehow?

With HardTp model, TPIDR_EL0 points to the TLS region.
With SoftTp model, the TLS region can be anywhere (the __aarch64_read_tp function is ran to find out where it is).
Under the Horizon kernel and with devkitPro's runtime, the TLS region is at *(TPIDR_EL0 + 0x1F8).
More generally, this allows supporting non-standard TLS regions.