hanchenye-llvm-project/lld/ELF
Ryan Prichard 1c33d14bcd [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tables
Summary:
For --pack-dyn-relocs=android, finalizeSections calls
LinkerScript::assignAddresses and
AndroidPackedRelocationSection::updateAllocSize in a loop,
where assignAddresses lays out the ELF image, then updateAllocSize
determines the size of the Android packed relocation table by encoding it.
Encoding the table requires knowing the values of relocation addends.

To get the addend of a TLS relocation, updateAllocSize can call getSymVA
on a TLS symbol before setPhdrs has initialized Out::TlsPhdr, producing an
error:

    <file> has an STT_TLS symbol but doesn't have an SHF_TLS section

Fix the problem by initializing Out::TlsPhdr immediately after the program
headers are created. The segment's p_vaddr field isn't initialized until
setPhdrs, so use FirstSec->Addr, which is what setPhdrs would use.
FirstSec will typically refer to the .tdata or .tbss output section, whose
(tentative) address was computed by assignAddresses.

Android currently avoids this problem because it uses emutls and doesn't
support ELF TLS. This problem doesn't apply to --pack-dyn-relocs=relr
because SHR_RELR only handles relative relocations without explicit addends
or info.

Fixes https://bugs.llvm.org/show_bug.cgi?id=37841.

Reviewers: ruiu, pcc, chh, javed.absar, espindola

Subscribers: emaste, arichardson, llvm-commits, srhines

Differential Revision: https://reviews.llvm.org/D51671

llvm-svn: 342432
2018-09-18 00:24:48 +00:00
..
Arch [PPC64] Support relaxing R_PPC64_TLSGD16 in TlsGdtoLe relaxation. 2018-09-17 20:27:02 +00:00
AArch64ErrataFix.cpp [ELF] Guard --fix-cortex-a53-843419 against --just-syms 2018-09-13 15:49:13 +00:00
AArch64ErrataFix.h
Bits.h
CMakeLists.txt Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}. 2018-09-14 23:51:05 +00:00
CallGraphSort.cpp [LLD][ELF] - Simplify Call-Chain Clustering implementation a bit. 2018-08-28 08:49:40 +00:00
CallGraphSort.h [ELF] Add profile guided section layout 2018-04-17 23:30:05 +00:00
Config.h lld: add -z interpose support 2018-09-14 14:25:37 +00:00
DWARF.cpp Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}. 2018-09-14 23:51:05 +00:00
DWARF.h Style fix. NFC. 2018-09-14 23:51:17 +00:00
Driver.cpp lld: add -z interpose support 2018-09-14 14:25:37 +00:00
Driver.h Add TARGET(foo) linker script directive. 2018-08-06 21:29:41 +00:00
DriverUtils.cpp [ELF] Use search paths for --version-script= 2018-07-25 21:53:18 +00:00
EhFrame.cpp [ELF] Simplify read32. NFC 2018-03-30 23:13:00 +00:00
EhFrame.h
Filesystem.cpp s/LLVM_ON_WIN32/_WIN32/, lld 2018-04-10 13:15:21 +00:00
Filesystem.h
ICF.cpp ELF: Don't examine values of linker script symbols during ICF. 2018-08-29 23:43:38 +00:00
ICF.h Consistent use of header file for ICF and MarkLive 2018-02-20 22:09:59 +00:00
InputFiles.cpp [ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sections 2018-09-07 00:18:07 +00:00
InputFiles.h Change how we handle -wrap. 2018-08-22 07:02:26 +00:00
InputSection.cpp When a relocation to an undefined symbol is an R_X86_64_PC32, an input 2018-09-04 21:06:59 +00:00
InputSection.h Revert r342297: Discard uncompressed buffer after creating .gdb_index contents. 2018-09-14 23:28:13 +00:00
LTO.cpp Simplify. 2018-09-11 14:37:27 +00:00
LTO.h Simplify. 2018-09-11 14:37:27 +00:00
LinkerScript.cpp ELF: Don't examine values of linker script symbols during ICF. 2018-08-29 23:43:38 +00:00
LinkerScript.h [ELF] - Eliminate the AssertCommand. 2018-04-25 11:16:31 +00:00
MapFile.cpp [ELF] - Change dyn_cast to cast. NFC. 2018-07-02 08:26:20 +00:00
MapFile.h Implement --cref. 2018-03-14 20:29:45 +00:00
MarkLive.cpp [ELF] Pass callables by function_ref 2018-06-16 12:11:34 +00:00
MarkLive.h Consistent use of header file for ICF and MarkLive 2018-02-20 22:09:59 +00:00
Options.td [docs] Update ld.lld.1 2018-07-30 17:36:38 +00:00
OutputSections.cpp [ELF] Pass callables by function_ref 2018-06-16 12:11:34 +00:00
OutputSections.h [ELF] - Implement linker script OVERLAYs. 2018-06-27 08:08:12 +00:00
README.md
Relocations.cpp [PPC64] Add TLS initial exec to local exec relaxation 2018-08-21 15:13:53 +00:00
Relocations.h [PPC64] Add TLS initial exec to local exec relaxation 2018-08-21 15:13:53 +00:00
ScriptLexer.cpp [LLD][ELD] - Do not reject INFO output section type when used with a start address. 2018-08-28 08:39:21 +00:00
ScriptLexer.h [LLD][ELD] - Do not reject INFO output section type when used with a start address. 2018-08-28 08:39:21 +00:00
ScriptParser.cpp [LLD][ELD] - Do not reject INFO output section type when used with a start address. 2018-08-28 08:39:21 +00:00
ScriptParser.h
SymbolTable.cpp Change how we handle -wrap. 2018-08-22 07:02:26 +00:00
SymbolTable.h Change how we handle -wrap. 2018-08-22 07:02:26 +00:00
Symbols.cpp [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tables 2018-09-18 00:24:48 +00:00
Symbols.h [ELF] Revert "Also demote lazy symbols." 2018-09-11 23:00:36 +00:00
SyntheticSections.cpp [ELF] Use llvm::toLower instead of libc call tolower 2018-09-15 23:59:13 +00:00
SyntheticSections.h Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}. 2018-09-14 23:51:05 +00:00
Target.cpp Support RISC-V 2018-08-09 17:59:56 +00:00
Target.h [ELF] Add support for Armv5 and Armv6 compatible Thunks 2018-08-20 09:37:50 +00:00
Thunks.cpp [ELF] [ARM] Don't mix 'ip' and 'r12' as names for the same register in comments. NFC. 2018-08-31 08:03:33 +00:00
Thunks.h ELF: Allow thunks to change size. NFCI. 2018-03-29 22:32:13 +00:00
Writer.cpp [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tables 2018-09-18 00:24:48 +00:00
Writer.h ELF: Do not ICF two sections with different output sections. 2018-05-23 01:58:43 +00:00

README.md

See docs/NewLLD.rst