This is an archive of the discontinued LLVM Phabricator instance.

[ARM][LLD] Initial support for ARM TLS
ClosedPublic

Authored by peter.smith on Jul 18 2016, 6:55 AM.

Details

Summary

Add relocations and identification functions for the Initial Exec, Local Exec, and Global Dynamic TLS model defined in Addenda to, and Errata in, the ABI for the ARM Architecture.

ARM uses variant 1 of the thread local storage data structures as defined in ELF Handling for Thread-Local Storage. The implementation fits into to the existing TLS model so the lld change is largely just identifying relocations.

Limitations:

  • The "experimental" descriptor based model that can be selected in gcc, but not clang with -mtls-dialect=gnu2 is not supported.
  • The relocations R_ARM_TLS_LE12 and R_ARM_TLS_IE12GP are not supported, I know of no ARM Toolchain that generates these relocations as they are an optimization that limits the size of the TLS block too much.
  • No code relaxation is supported as the standard ARM TLS model puts the TLS relocations on literal data and not code.
  • Support for the local dynamic model will come in a follow up patch. The test cases depend on adding symbol(tlsldm) support to llvm-mc (https://reviews.llvm.org/D22461).

References:

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith retitled this revision from to [ARM][LLD] Initial support for ARM TLS.
peter.smith updated this object.
peter.smith added reviewers: ruiu, rafael.
peter.smith added subscribers: llvm-commits, rengolin.
ruiu edited edge metadata.Jul 18 2016, 8:05 AM

Code LGTM, but these tests seems too long to me. As a comparison, test/ELF/aarch64-tls-gdie.s is just 34 lines. Can you reduce the test assembly so that you really test the feature that you are adding?

ELF/Target.cpp
1522 ↗(On Diff #64312)

+ -?

Thanks for the review. My intention was to have the tests closely follow the structure that a compiler would output for simple accesses to TLS variables. I'll cut the tests down a bit more and will post an update tomorrow.

peter.smith edited edge metadata.

Changes since last revision:

  • Rewrite the test cases to limit the amount of unnecessary code. The code-sequences now closely match the TLS examples in the ABI for the ARM Architecture [1].
  • Add a test case for local-exec

It could be possible to streamline the tests further to just the literals but I think that this would make it hard for a human to interpret the test and what it is checking for.

[1] http://infocenter.arm.com/help/topic/com.arm.doc.ihi0045e/IHI0045E_ABI_addenda.pdf

ruiu added a comment.Jul 18 2016, 4:35 PM

I still don't think that testing with relatively large mocked compiler outputs is a good idea since, well, it is out of scope of this patch. Large tests tend to be updated in the future for unrelated changes because they contain unrelated stuff. I'd appreciate if you test only the feature you are focusing on with this patch.

Changes since last version:
Removed all code-sequences from tests. Leaving just literals and some nop instructions used to provide some separation between labels.

Corrected mistake in R_ARM_TLS_LE32 implementation in relocateOne and test. It should include the Thread Control Block Size in the offset from thread pointer.

ruiu accepted this revision.Jul 19 2016, 10:42 AM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 19 2016, 10:42 AM
This revision was automatically updated to reflect the committed changes.

Thanks for the review, committed r276095

ELF/Target.cpp
1522 ↗(On Diff #64312)

The comment GOT(S) + - Got_ORG is wrong. In fact the above line is also wrong as it is missing A. It should be GOT(S) + A - P.