[PATCH] D14359: [elf2] Add support for R_X86_64_TLSLD.

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 16:45:04 PST 2015


Bigcheese created this revision.
Bigcheese added reviewers: ruiu, rafael.
Bigcheese added a subscriber: llvm-commits.

leaq symbol at tlsld(%rip), %rdi
call __tls_get_addr at plt

symbol at tlsld (R_X86_64_TLSLD) instructs the linker to generate a tls_index entry (two GOT slots) in the GOT for the entire module (shared object or executable) with an offset of 0. The symbol for this GOT entry doesn't matter (as long as it's either local to the module or null), and gold doesn't put a symbol in the dynamic R_X86_64_DTPMOD64 relocation for the GOT entry.

All other platforms defined in http://www.akkadia.org/drepper/tls.pdf except for Itanium use a similar model where global and local dynamic GOT entries take up 2 contiguous GOT slots, so we can handle this in a unified manner if we don't care about Itanium.

While scanning relocations we need to identify local dynamic relocations and generate a single tls_index entry in the GOT for the module and store the address of it somewhere so we can later statically resolve the offset for R_X86_64_TLSLD relocations. We also need to generate a R_X86_64_DTPMOD64 relocation in the RelaDyn relocation section.

This implementation is a bit hacky. It side steps the issue of GotSection and RelocationSection only handling SymbolBody entries by relying on a specific relocation type. The alternative to this seemed to be completely rewriting how GotSection and RelocationSection work, or using a different hacky signaling method.


http://reviews.llvm.org/D14359

Files:
  ELF/InputSection.cpp
  ELF/OutputSections.cpp
  ELF/OutputSections.h
  ELF/Target.cpp
  ELF/Target.h
  ELF/Writer.cpp
  test/elf2/tls-dynamic.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14359.39290.patch
Type: text/x-patch
Size: 6645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151105/b0ab5a23/attachment.bin>


More information about the llvm-commits mailing list