[lld-macho] Support dynamic linking of thread-locals
authorJez Ng <jezng@fb.com>
Thu, 13 Aug 2020 02:50:09 +0000 (19:50 -0700)
committerJez Ng <jezng@fb.com>
Thu, 13 Aug 2020 02:50:09 +0000 (19:50 -0700)
commit3c9100fb785c400c457ce83ba724a3b762b2348a
treeede95054724e56a6d29535bb1fbb4e64602c2697
parent65277126bf90401436e018fcce0fc636d34ea771
[lld-macho] Support dynamic linking of thread-locals

References to symbols in dylibs work very similarly regardless of
whether the symbol is a TLV. The main difference is that we have a
separate `__thread_ptrs` section that acts as the GOT for these
thread-locals.

We can identify thread-locals in dylibs by a flag in their export trie
entries, and we cross-check it with the relocations that refer to them
to ensure that we are not using a GOT relocation to reference a
thread-local (or vice versa).

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D85081
15 files changed:
lld/MachO/Arch/X86_64.cpp
lld/MachO/ExportTrie.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/SymbolTable.cpp
lld/MachO/SymbolTable.h
lld/MachO/Symbols.h
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Writer.cpp
lld/test/MachO/invalid/bad-got-to-dylib-tlv-reference.s [new file with mode: 0644]
lld/test/MachO/invalid/bad-got-to-tlv-reference.s [new file with mode: 0644]
lld/test/MachO/invalid/bad-tlv-relocation.s [new file with mode: 0644]
lld/test/MachO/tlv-dylib.s [new file with mode: 0644]