[lld] r361084 - [ELF] Fix TP offset of TLS Variant I after D62059

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 17:43:11 PDT 2019


Author: maskray
Date: Fri May 17 17:43:10 2019
New Revision: 361084

URL: http://llvm.org/viewvc/llvm-project?rev=361084&view=rev
Log:
[ELF] Fix TP offset of TLS Variant I after D62059

As Ryan Prichard pointed out, after D62059, the TP offset is incorrect.

Add x86-64-tls-le-align.s to check this.  Better formulae for both
variants should take p_vaddr%p_align into account (offset%p_align =
p_vaddr%p_align is a basic ELF requirement), but I can't find a way to
test the behavior.

Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=361084&r1=361083&r2=361084&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri May 17 17:43:10 2019
@@ -598,7 +598,7 @@ static int64_t getTlsTpOffset() {
   case EM_386:
   case EM_X86_64:
     // Variant 2. The TLS segment is located just before the thread pointer.
-    return -Out::TlsPhdr->p_memsz;
+    return -alignTo(Out::TlsPhdr->p_memsz, Out::TlsPhdr->p_align);
   case EM_PPC64:
     // The thread pointer points to a fixed offset from the start of the
     // executable's TLS segment. An offset of 0x7000 allows a signed 16-bit




More information about the llvm-commits mailing list