[PATCH] [lld] [ELF] Support for general dynamic TLS relocations on X86_64

Rafael Auler rafaelauler at gmail.com
Fri Sep 26 11:38:41 PDT 2014


Hi ruiu, rafael, Bigcheese,

This patch adds support for the general dynamic TLS access model for X86_64 (see www.akkadia.org/drepper/tls.pdf).

To properly support TLS, the patch also changes the __tls_get_addr atom to be a shared library atom instead of a regularly defined atom (the previous lld approach). This closely models the reality of a function that will be resolved at runtime by the dynamic linker and loader itself (ld.so). I was tempted to force LLD to link against ld.so itself to resolve these symbols, but since GNU ld does not need the ld.so library to resolve this symbol, I decided to mimic its behavior and keep hardwired a definition of __tls_get_addr in the lld code.

This patch also moves some important logic that previously was only available to the MIPS lld backend to be used to all ELF backends. This logic, which now lives in the DefaultLayout class, will monitor which external (shared lib) symbols are really imported by the current module and will only populate the dynamic symbol table with used symbols, as opposed to the previous approach of dumping all shared lib symbols in the dynamic symbol table. This is important to this patch to avoid __tls_get_addr from getting injected into all dynamic symbol tables.

By solving the previous problem of always adding __tls_get_addr, now the produced symbol tables are slightly smaller. But this impacted several tests that relied on hardwired/predefined sizes of the symbol table, requiring this patch to update such tests.

http://reviews.llvm.org/D5505

Files:
  include/lld/ReaderWriter/ELFLinkingContext.h
  lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h
  lib/ReaderWriter/ELF/Atoms.h
  lib/ReaderWriter/ELF/DefaultLayout.h
  lib/ReaderWriter/ELF/DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/ELFLinkingContext.cpp
  lib/ReaderWriter/ELF/ExecutableWriter.h
  lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
  lib/ReaderWriter/ELF/OutputELFWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
  lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
  lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp
  test/elf/X86_64/Inputs/generaltls-so.o.yaml
  test/elf/X86_64/general-dynamic-tls.test
  test/elf/X86_64/omagic.test
  test/elf/X86_64/undef.test
  test/elf/X86_64/underscore-end.test
  test/elf/undef-from-main-dso.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5505.14126.patch
Type: text/x-patch
Size: 29513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140926/df51f42f/attachment.bin>


More information about the llvm-commits mailing list