[PATCH] D26238: [LLD][ARM] Correct ARM TLS GOT entries without dynamic relocations.

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 04:24:52 PDT 2016


peter.smith created this revision.
peter.smith added reviewers: ruiu, rafael.
peter.smith added a subscriber: llvm-commits.
Herald added subscribers: rengolin, aemerson.

ARM has three dynamic relocations for TLS:

- R_ARM_TPOFF32 (Offset of S from Thread Pointer)
- R_ARM_DTPMOD32 (Module-Id, always 1 for executables)
- R_ARM_DTPOFF32 (Offset of S from TLS block)

When static linking we must resolve these relocations statically by writing the values directly into the .got. In many ways ARM is similar to Mips:

- TLS is not relaxable so the linker can't rely on relaxing global and local dynamic away.
- ARM is type 1 TLS (TLS block is immediately after Thread Pointer and precedes TLS data) so the TCB size has to be accounted for when resolving R_ARM_TPOFF32.
- The R_ARM_DTPMOD32 needs to be hard coded to 1 in applications.

To implement this I've:

- Removed the fixme in handleNoRelaxTlsRelocation() which always added dynamic relocations for ARM TLS
- Recorded where symbols have been relocated by a Target->TlsGotRel, R_ARM_TLS_TPOFF32 for ARM
- Introduce a writeARMGot(), similar to writeMipsGot() to isolate the special cases from the other Targets.
  - Write the module index to be 1 (from Global Dynamic or Local Dynamic)
  - Account for the Target->TcbSize when writing the value of a symbol that has been recorded as being referenced by R_ARM_TPOFF32.

The changes show up in the existing tests. As we no longer need the dynamic relocation for the module index and the GOT entries that  are statically resolved R_ARM_TLS_TPOFF32 relocations include the ARM TcbSize of 8.

The implementation of writeARMGot() is similar to writeMipsGot() in the way it handles TLS.

The Mips implementation uses Config->Pic consistently to use dynamic relocations. For ARM I've used Config->Shared as an executable can still use Pic, and can still be statically linked with Pic.


https://reviews.llvm.org/D26238

Files:
  ELF/OutputSections.cpp
  ELF/OutputSections.h
  ELF/Relocations.cpp
  ELF/Symbols.h
  test/ELF/arm-tls-norelax-gd-le.s
  test/ELF/arm-tls-norelax-ie-le.s
  test/ELF/arm-tls-norelax-ld-le.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26238.76688.patch
Type: text/x-patch
Size: 6966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161102/dd8c9d37/attachment.bin>


More information about the llvm-commits mailing list