<div dir="ltr">Woohoo!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 13, 2015 at 7:34 AM, Rafael Espíndola <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">Now all tests pass is a stage2 build of llvm+clang+lld when linking with lld :-)<br>
<br>
<br>
On 12 November 2015 at 19:28, Michael J. Spencer via llvm-commits<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: mspencer<br>
> Date: Thu Nov 12 18:28:34 2015<br>
> New Revision: 252979<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252979&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252979&view=rev</a><br>
> Log:<br>
> [elf2] Implement global dynamic tls.<br>
><br>
> Modified:<br>
> lld/trunk/ELF/InputSection.cpp<br>
> lld/trunk/ELF/OutputSections.cpp<br>
> lld/trunk/ELF/OutputSections.h<br>
> lld/trunk/ELF/Target.cpp<br>
> lld/trunk/ELF/Target.h<br>
> lld/trunk/ELF/Writer.cpp<br>
> lld/trunk/test/elf2/tls-dynamic.s<br>
><br>
> Modified: lld/trunk/ELF/InputSection.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/InputSection.cpp (original)<br>
> +++ lld/trunk/ELF/InputSection.cpp Thu Nov 12 18:28:34 2015<br>
> @@ -126,6 +126,14 @@ void InputSectionBase<ELFT>::relocate(<br>
> }<br>
><br>
> SymbolBody &Body = *File->getSymbolBody(SymIndex)->repl();<br>
> +<br>
> + if (Type == Target->getTlsGlobalDynamicReloc()) {<br>
> + Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc,<br>
> + Out<ELFT>::Got->getEntryAddr(Body) +<br>
> + getAddend<ELFT>(RI));<br>
> + continue;<br>
> + }<br>
> +<br>
> uintX_t SymVA = getSymVA<ELFT>(Body);<br>
> if (Target->relocNeedsPlt(Type, Body)) {<br>
> SymVA = Out<ELFT>::Plt->getEntryAddr(Body);<br>
><br>
> Modified: lld/trunk/ELF/OutputSections.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/OutputSections.cpp (original)<br>
> +++ lld/trunk/ELF/OutputSections.cpp Thu Nov 12 18:28:34 2015<br>
> @@ -80,6 +80,9 @@ GotSection<ELFT>::GotSection()<br>
> template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) {<br>
> Sym->GotIndex = Target->getGotHeaderEntriesNum() + Entries.size();<br>
> Entries.push_back(Sym);<br>
> + // Global Dynamic TLS entries take two GOT slots.<br>
> + if (Sym->isTLS())<br>
> + Entries.push_back(nullptr);<br>
> }<br>
><br>
> template <class ELFT> uint32_t GotSection<ELFT>::addLocalModuleTlsIndex() {<br>
> @@ -187,8 +190,13 @@ template <class ELFT> void RelocationSec<br>
> auto *P = reinterpret_cast<Elf_Rel *>(Buf);<br>
> Buf += EntrySize;<br>
><br>
> - InputSectionBase<ELFT> &C = Rel.C;<br>
> - const Elf_Rel &RI = Rel.RI;<br>
> + // Skip placeholder for global dynamic TLS relocation pair. It was already<br>
> + // handled by the previous relocation.<br>
> + if (!Rel.C || !Rel.RI)<br>
> + continue;<br>
> +<br>
> + InputSectionBase<ELFT> &C = *Rel.C;<br>
> + const Elf_Rel &RI = *Rel.RI;<br>
> uint32_t SymIndex = RI.getSymbol(Config->Mips64EL);<br>
> const ObjectFile<ELFT> &File = *C.getFile();<br>
> SymbolBody *Body = File.getSymbolBody(SymIndex);<br>
> @@ -205,6 +213,17 @@ template <class ELFT> void RelocationSec<br>
> continue;<br>
> }<br>
><br>
> + if (Body && Type == Target->getTlsGlobalDynamicReloc()) {<br>
> + P->setSymbolAndType(Body->getDynamicSymbolTableIndex(),<br>
> + Target->getTlsModuleIndexReloc(), Config->Mips64EL);<br>
> + P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);<br>
> + auto *PNext = reinterpret_cast<Elf_Rel *>(Buf);<br>
> + PNext->setSymbolAndType(Body->getDynamicSymbolTableIndex(),<br>
> + Target->getTlsOffsetReloc(), Config->Mips64EL);<br>
> + PNext->r_offset = Out<ELFT>::Got->getEntryAddr(*Body) + sizeof(uintX_t);<br>
> + continue;<br>
> + }<br>
> +<br>
> bool NeedsCopy = Body && Target->relocNeedsCopy(Type, *Body);<br>
> bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body);<br>
> bool CanBePreempted = canBePreempted(Body, NeedsGot);<br>
><br>
> Modified: lld/trunk/ELF/OutputSections.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/OutputSections.h (original)<br>
> +++ lld/trunk/ELF/OutputSections.h Thu Nov 12 18:28:34 2015<br>
> @@ -170,8 +170,8 @@ private:<br>
><br>
> template <class ELFT> struct DynamicReloc {<br>
> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;<br>
> - InputSectionBase<ELFT> &C;<br>
> - const Elf_Rel &RI;<br>
> + InputSectionBase<ELFT> *C;<br>
> + const Elf_Rel *RI;<br>
> };<br>
><br>
> template <class ELFT><br>
><br>
> Modified: lld/trunk/ELF/Target.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/Target.cpp (original)<br>
> +++ lld/trunk/ELF/Target.cpp Thu Nov 12 18:28:34 2015<br>
> @@ -216,7 +216,9 @@ X86_64TargetInfo::X86_64TargetInfo() {<br>
> PltReloc = R_X86_64_JUMP_SLOT;<br>
> RelativeReloc = R_X86_64_RELATIVE;<br>
> TlsLocalDynamicReloc = R_X86_64_TLSLD;<br>
> + TlsGlobalDynamicReloc = R_X86_64_TLSGD;<br>
> TlsModuleIndexReloc = R_X86_64_DTPMOD64;<br>
> + TlsOffsetReloc = R_X86_64_DTPOFF64;<br>
> LazyRelocations = true;<br>
> PltEntrySize = 16;<br>
> PltZeroEntrySize = 16;<br>
> @@ -335,6 +337,7 @@ void X86_64TargetInfo::relocateOne(uint8<br>
> case R_X86_64_GOTPCREL:<br>
> case R_X86_64_PLT32:<br>
> case R_X86_64_TLSLD:<br>
> + case R_X86_64_TLSGD:<br>
> write32le(Loc, SA - P);<br>
> break;<br>
> case R_X86_64_64:<br>
><br>
> Modified: lld/trunk/ELF/Target.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/Target.h (original)<br>
> +++ lld/trunk/ELF/Target.h Thu Nov 12 18:28:34 2015<br>
> @@ -30,7 +30,9 @@ public:<br>
> unsigned getGotRefReloc() const { return GotRefReloc; }<br>
> unsigned getRelativeReloc() const { return RelativeReloc; }<br>
> unsigned getTlsLocalDynamicReloc() const { return TlsLocalDynamicReloc; }<br>
> + unsigned getTlsGlobalDynamicReloc() const { return TlsGlobalDynamicReloc; }<br>
> unsigned getTlsModuleIndexReloc() const { return TlsModuleIndexReloc; }<br>
> + unsigned getTlsOffsetReloc() const { return TlsOffsetReloc; }<br>
> unsigned getPltZeroEntrySize() const { return PltZeroEntrySize; }<br>
> unsigned getPltEntrySize() const { return PltEntrySize; }<br>
> bool supportsLazyRelocations() const { return LazyRelocations; }<br>
> @@ -70,7 +72,9 @@ protected:<br>
> unsigned PltReloc;<br>
> unsigned RelativeReloc;<br>
> unsigned TlsLocalDynamicReloc = 0;<br>
> + unsigned TlsGlobalDynamicReloc = 0;<br>
> unsigned TlsModuleIndexReloc;<br>
> + unsigned TlsOffsetReloc;<br>
> unsigned PltEntrySize = 8;<br>
> unsigned PltZeroEntrySize = 0;<br>
> unsigned GotHeaderEntriesNum = 0;<br>
><br>
> Modified: lld/trunk/ELF/Writer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/Writer.cpp (original)<br>
> +++ lld/trunk/ELF/Writer.cpp Thu Nov 12 18:28:34 2015<br>
> @@ -203,7 +203,7 @@ void Writer<ELFT>::scanRelocs(<br>
> if (Out<ELFT>::LocalModuleTlsIndexOffset == uint32_t(-1)) {<br>
> Out<ELFT>::LocalModuleTlsIndexOffset =<br>
> Out<ELFT>::Got->addLocalModuleTlsIndex();<br>
> - Out<ELFT>::RelaDyn->addReloc({C, RI});<br>
> + Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
> }<br>
> continue;<br>
> }<br>
> @@ -215,6 +215,19 @@ void Writer<ELFT>::scanRelocs(<br>
><br>
> if (Body)<br>
> Body = Body->repl();<br>
> +<br>
> + if (Body && Body->isTLS()) {<br>
> + if (Type != Target->getTlsGlobalDynamicReloc())<br>
> + continue;<br>
> + if (Body->isInGot())<br>
> + continue;<br>
> + Out<ELFT>::Got->addEntry(Body);<br>
> + Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
> + Out<ELFT>::RelaDyn->addReloc({nullptr, nullptr});<br>
> + Body->setUsedInDynamicReloc();<br>
> + continue;<br>
> + }<br>
> +<br>
> bool NeedsGot = false;<br>
> bool NeedsPlt = false;<br>
> if (Body) {<br>
> @@ -257,9 +270,9 @@ void Writer<ELFT>::scanRelocs(<br>
> if (CBP)<br>
> Body->setUsedInDynamicReloc();<br>
> if (NeedsPlt && Target->supportsLazyRelocations())<br>
> - Out<ELFT>::RelaPlt->addReloc({C, RI});<br>
> + Out<ELFT>::RelaPlt->addReloc({&C, &RI});<br>
> else<br>
> - Out<ELFT>::RelaDyn->addReloc({C, RI});<br>
> + Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
> }<br>
> }<br>
><br>
><br>
> Modified: lld/trunk/test/elf2/tls-dynamic.s<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls-dynamic.s?rev=252979&r1=252978&r2=252979&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls-dynamic.s?rev=252979&r1=252978&r2=252979&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/test/elf2/tls-dynamic.s (original)<br>
> +++ lld/trunk/test/elf2/tls-dynamic.s Thu Nov 12 18:28:34 2015<br>
> @@ -11,6 +11,10 @@<br>
> leaq a@dtpoff(%rax), %rcx<br>
> leaq b@dtpoff(%rax), %rcx<br>
> .long b@dtpoff, 0<br>
> + leaq c@tlsgd(%rip), %rdi<br>
> + rex64<br>
> + callq __tls_get_addr@PLT<br>
> + leaq c@dtpoff(%rax), %rcx<br>
><br>
> .global a<br>
> .hidden a<br>
> @@ -23,8 +27,14 @@ a:<br>
> .align 4<br>
> b:<br>
> .long 0<br>
> +<br>
> + .global c<br>
> + .section .tbss,"awT",@nobits<br>
> + .align 4<br>
> +c:<br>
> + .long 0<br>
><br>
> -// Get the address of the got, and check that it has two entries.<br>
> +// Get the address of the got, and check that it has 4 entries.<br>
><br>
> // CHECK: Sections [<br>
> // CHECK: Name: .got<br>
> @@ -35,15 +45,18 @@ b:<br>
> // CHECK-NEXT: ]<br>
> // CHECK-NEXT: Address: 0x20D0<br>
> // CHECK-NEXT: Offset:<br>
> -// CHECK-NEXT: Size: 16<br>
> +// CHECK-NEXT: Size: 32<br>
><br>
> // CHECK: Relocations [<br>
> // CHECK: Section ({{.+}}) .rela.dyn {<br>
> // CHECK-NEXT: 0x20D0 R_X86_64_DTPMOD64 - 0x0<br>
> +// CHECK-NEXT: 0x20E0 R_X86_64_DTPMOD64 c 0x0<br>
> +// CHECK-NEXT: 0x20E8 R_X86_64_DTPOFF64 c 0x0<br>
> // CHECK-NEXT: }<br>
><br>
> // 4297 = (0x20D0 + -4) - (0x1000 + 3) // PC relative offset to got entry.<br>
> // 4285 = (0x20D0 + -4) - (0x100c + 3) // PC relative offset to got entry.<br>
> +// 4267 = (0x20E0 + -4) - (0x102e + 3) // PC relative offset to got entry.<br>
><br>
> // DIS: Disassembly of section .text:<br>
> // DIS-NEXT: .text:<br>
> @@ -57,3 +70,6 @@ b:<br>
> // DIS-NEXT: 1028: 00 00<br>
> // DIS-NEXT: 102a: 00 00<br>
> // DIS-NEXT: 102c: 00 00<br>
> +// DIS-NEXT: 102e: {{.+}} leaq 4267(%rip), %rdi<br>
> +// DIS-NEXT: 1035: {{.+}} callq<br>
> +// DIS-NEXT: 103b: {{.+}} leaq 8(%rax), %rcx<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>
_______________________________________________<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>
</div></div></blockquote></div><br></div>