<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 4, 2015 at 6:00 PM, Michael J. Spencer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mspencer<br>
Date: Wed Nov  4 20:00:35 2015<br>
New Revision: 252131<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252131&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252131&view=rev</a><br>
Log:<br>
[elf2] Fix R_X86_64_TPOFF32 handling.<br>
<br>
For x86-64 the initial executable TLS block is placed directly before the<br>
thread specific data register so compilers can directly access it via<br>
R_X86_64_TPOFF32. Generate the correct (negative) offset for this case.<br>
<br>
Modified:<br>
    lld/trunk/ELF/OutputSections.h<br>
    lld/trunk/ELF/Target.cpp<br>
    lld/trunk/ELF/Writer.cpp<br>
    lld/trunk/test/elf2/tls.s<br>
<br>
Modified: lld/trunk/ELF/OutputSections.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=252131&r1=252130&r2=252131&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=252131&r1=252130&r2=252131&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.h (original)<br>
+++ lld/trunk/ELF/OutputSections.h Wed Nov  4 20:00:35 2015<br>
@@ -372,6 +372,7 @@ template <class ELFT> struct Out {<br>
   static SymbolTableSection<ELFT> *DynSymTab;<br>
   static SymbolTableSection<ELFT> *SymTab;<br>
   static uintX_t TlsInitImageVA;<br>
+  static size_t TlsInitImageAlignedSize;<br>
 };<br>
<br>
 template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;<br>
@@ -392,6 +393,7 @@ template <class ELFT> StringTableSection<br>
 template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;<br>
 template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;<br>
 template <class ELFT> typename Out<ELFT>::uintX_t Out<ELFT>::TlsInitImageVA;<br>
+template <class ELFT> size_t Out<ELFT>::TlsInitImageAlignedSize;<br>
<br>
 } // namespace elf2<br>
 } // namespace lld<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=252131&r1=252130&r2=252131&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=252131&r1=252130&r2=252131&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Wed Nov  4 20:00:35 2015<br>
@@ -340,7 +340,7 @@ void X86_64TargetInfo::relocateOne(uint8<br>
     write32le(Loc, SA);<br>
     break;<br>
   case R_X86_64_TPOFF32:<br>
-    write32le(Loc, SA);<br>
+    write32le(Loc, SA - Out<llvm::object::ELF64LE>::TlsInitImageAlignedSize);<br>
     break;<br>
   default:<br>
     error("unrecognized reloc " + Twine(Type));<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=252131&r1=252130&r2=252131&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=252131&r1=252130&r2=252131&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Wed Nov  4 20:00:35 2015<br>
@@ -740,8 +740,11 @@ template <class ELFT> void Writer<ELFT>:<br>
     }<br>
   }<br>
<br>
-  if (TlsPhdr.p_vaddr)<br>
+  if (TlsPhdr.p_vaddr) {<br>
     Phdrs[++PhdrIdx] = TlsPhdr;<br>
+    Out<ELFT>::TlsInitImageAlignedSize =<br>
+        RoundUpToAlignment(TlsPhdr.p_memsz, TlsPhdr.p_align);<br>
+  }<br></blockquote><div><br></div><div>Can you give me the pointer to the spec that says "TLS block end" is an aligned value this way?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
   // Add an entry for .dynamic.<br>
   if (isOutputDynamic()) {<br>
<br>
Modified: lld/trunk/test/elf2/tls.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls.s?rev=252131&r1=252130&r2=252131&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls.s?rev=252131&r1=252130&r2=252131&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/tls.s (original)<br>
+++ lld/trunk/test/elf2/tls.s Wed Nov  4 20:00:35 2015<br>
@@ -164,7 +164,7 @@ d:<br>
<br>
 // DIS:      Disassembly of section .text:<br>
 // DIS-NEXT: _start:<br>
-// DIS-NEXT:    11000: {{.+}} movl    %fs:8, %eax<br>
-// DIS-NEXT:    11008: {{.+}} movl    %fs:0, %eax<br>
-// DIS-NEXT:    11010: {{.+}} movl    %fs:12, %eax<br>
-// DIS-NEXT:    11018: {{.+}} movl    %fs:4, %eax<br>
+// DIS-NEXT:    11000: {{.+}} movl    %fs:-8, %eax<br>
+// DIS-NEXT:    11008: {{.+}} movl    %fs:-16, %eax<br>
+// DIS-NEXT:    11010: {{.+}} movl    %fs:-4, %eax<br>
+// DIS-NEXT:    11018: {{.+}} movl    %fs:-12, %eax<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>