[PATCH] D51671: [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tables

Ryan Prichard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 21:32:17 PDT 2018


rprichard created this revision.
rprichard added reviewers: ruiu, pcc, chh.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: javed.absar.
Herald added a reviewer: espindola.

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.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51671

Files:
  ELF/Symbols.cpp
  ELF/Writer.cpp
  test/ELF/pack-dyn-relocs-tls-aarch64.s
  test/ELF/pack-dyn-relocs-tls-x86-64.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51671.163972.patch
Type: text/x-patch
Size: 3424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180905/815ebe4b/attachment.bin>


More information about the llvm-commits mailing list