<div dir="ltr">Thanks!<div><br></div><div>This patch contained trailing whitespace characters. I removed them in r250170.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 13, 2015 at 9:09 AM, George Rimar 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: grimar<br>
Date: Tue Oct 13 11:09:55 2015<br>
New Revision: 250169<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=250169&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=250169&view=rev</a><br>
Log:<br>
This patch implements basic variant of lazy loading for x86_x64 and for X86 targets.<br>
<br>
What was done:<br>
1) .got.plt section is created for functions that requires PLT. .got.plt has 3 predefined empty entries now that are required for dynamic linker.<br>
Also other new items created are configured to have correct jump to PLT[N].<br>
2) PLT section now has PLT[0] entry, also others ones are configured to support PLT->GOT(.got.plt) calls.<br>
3) Implemented .rel[a].plt sections (based on patch <a href="http://reviews.llvm.org/D13569" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13569</a>).<br>
4) Fixed plt relocations types (based on patch <a href="http://reviews.llvm.org/D13589" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13589</a>).<br>
<br>
NOTES:<br>
The .plt.got zero entry is still empty now. According to ELF specification it should hold the address of the dynamic structure, referenced with the symbol<br>
_DYNAMIC. The _DYNAMIC entry points to the .dynamic section which contains information used by the ELF interpreter to setup the binary.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D13651" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13651</a><br>
<br>
Modified:<br>
    lld/trunk/ELF/OutputSections.cpp<br>
    lld/trunk/ELF/OutputSections.h<br>
    lld/trunk/ELF/Symbols.h<br>
    lld/trunk/ELF/Target.cpp<br>
    lld/trunk/ELF/Target.h<br>
    lld/trunk/ELF/Writer.cpp<br>
    lld/trunk/test/elf2/plt-i686.s<br>
    lld/trunk/test/elf2/plt.s<br>
    lld/trunk/test/elf2/relocation-i686.s<br>
    lld/trunk/test/elf2/relocation.s<br>
<br>
Modified: lld/trunk/ELF/OutputSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct 13 11:09:55 2015<br>
@@ -30,6 +30,43 @@ OutputSectionBase<Is64Bits>::OutputSecti<br>
 }<br>
<br>
 template <class ELFT><br>
+GotPltSection<ELFT>::GotPltSection()<br>
+    : OutputSectionBase<ELFT::Is64Bits>(".got.plt", llvm::ELF::SHT_PROGBITS,<br>
+                                        llvm::ELF::SHF_ALLOC |<br>
+                                            llvm::ELF::SHF_WRITE) {<br>
+  this->Header.sh_addralign = this->getAddrSize();<br>
+  // .got.plt has 3 reserved entry<br>
+  Entries.resize(3);<br>
+}<br>
+<br>
+template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody *Sym) {<br>
+  Sym->GotPltIndex = Entries.size();<br>
+  Entries.push_back(Sym);<br>
+}<br>
+<br>
+template <class ELFT> bool GotPltSection<ELFT>::empty() const {<br>
+  return Entries.size() == 3;<br>
+}<br>
+<br>
+template <class ELFT><br>
+typename GotPltSection<ELFT>::uintX_t<br>
+GotPltSection<ELFT>::getEntryAddr(const SymbolBody &B) const {<br>
+  return this->getVA() + B.GotPltIndex * this->getAddrSize();<br>
+}<br>
+<br>
+template <class ELFT> void GotPltSection<ELFT>::finalize() {<br>
+  this->Header.sh_size = Entries.size() * this->getAddrSize();<br>
+}<br>
+<br>
+template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) {<br>
+  for (const SymbolBody *B : Entries) {<br>
+    if (B)<br>
+      Target->writeGotPltEntry(Buf, Out<ELFT>::Plt->getEntryAddr(*B));<br>
+    Buf += sizeof(uintX_t);<br>
+  }<br>
+}<br>
+<br>
+template <class ELFT><br>
 GotSection<ELFT>::GotSection()<br>
     : OutputSectionBase<ELFT::Is64Bits>(".got", llvm::ELF::SHT_PROGBITS,<br>
                                         llvm::ELF::SHF_ALLOC |<br>
@@ -69,10 +106,13 @@ PltSection<ELFT>::PltSection()<br>
<br>
 template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) {<br>
   size_t Off = 0;<br>
+  // First write PLT[0] entry which is special.<br>
+  Target->writePltZeroEntry(Buf, Out<ELFT>::GotPlt->getVA(), this->getVA());<br>
+  Off += Target->getPltZeroEntrySize();<br>
   for (const SymbolBody *E : Entries) {<br>
-    uint64_t Got = Out<ELFT>::Got->getEntryAddr(*E);<br>
+    uint64_t Got = Out<ELFT>::GotPlt->getEntryAddr(*E);<br>
     uint64_t Plt = this->getVA() + Off;<br>
-    Target->writePltEntry(Buf + Off, Got, Plt);<br>
+    Target->writePltEntry(Buf + Off, Got, Plt, E->PltIndex);<br>
     Off += Target->getPltEntrySize();<br>
   }<br>
 }<br>
@@ -85,19 +125,20 @@ template <class ELFT> void PltSection<EL<br>
 template <class ELFT><br>
 typename PltSection<ELFT>::uintX_t<br>
 PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const {<br>
-  return this->getVA() + B.PltIndex * Target->getPltEntrySize();<br>
+  return this->getVA() + Target->getPltZeroEntrySize() +<br>
+         B.PltIndex * Target->getPltEntrySize();<br>
 }<br>
<br>
 template <class ELFT><br>
 void PltSection<ELFT>::finalize() {<br>
-  this->Header.sh_size = Entries.size() * Target->getPltEntrySize();<br>
+  this->Header.sh_size =<br>
+      Target->getPltZeroEntrySize() + Entries.size() * Target->getPltEntrySize();<br>
 }<br>
<br>
 template <class ELFT><br>
-RelocationSection<ELFT>::RelocationSection(bool IsRela)<br>
-    : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",<br>
-                                        IsRela ? llvm::ELF::SHT_RELA<br>
-                                               : llvm::ELF::SHT_REL,<br>
+RelocationSection<ELFT>::RelocationSection(StringRef Name, bool IsRela)<br>
+    : OutputSectionBase<ELFT::Is64Bits>(Name, IsRela ? llvm::ELF::SHT_RELA<br>
+                                                     : llvm::ELF::SHT_REL,<br>
                                         llvm::ELF::SHF_ALLOC),<br>
       IsRela(IsRela) {<br>
   this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);<br>
@@ -135,10 +176,22 @@ template <class ELFT> void RelocationSec<br>
     }<br>
<br>
     if (Body && Target->relocNeedsGot(Type, *Body)) {<br>
-      P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);<br>
+      // Each symbol that needs plt relocation is placed to Plt and GotPlt,<br>
+      // otherwise to Got.<br>
+      // Also symbol can be placed both to Got and Plt + GotPlt, for example<br>
+      // when we take address of function from DSO and also make a call to it.<br>
+      // So here depending on what type of relocation is we switch from which<br>
+      // table to take the offset from.<br>
+      bool NeedsPlt = Target->relocNeedsPlt(Type, *Body);<br>
+      if (NeedsPlt)<br>
+        P->r_offset = Out<ELFT>::GotPlt->getEntryAddr(*Body);<br>
+      else<br>
+        P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);<br>
       if (CanBePreempted)<br>
         P->setSymbolAndType(Body->getDynamicSymbolTableIndex(),<br>
-                            Target->getGotReloc(), IsMips64EL);<br>
+                            NeedsPlt ? Target->getPltReloc()<br>
+                                     : Target->getGotReloc(),<br>
+                            IsMips64EL);<br>
     } else {<br>
       if (IsRela)<br>
         Addend += static_cast<const Elf_Rela &>(RI).r_addend;<br>
@@ -255,6 +308,12 @@ template <class ELFT> void DynamicSectio<br>
     ++NumEntries; // DT_RELASZ / DT_RELSZ<br>
     ++NumEntries; // DT_RELAENT / DT_RELENT<br>
   }<br>
+  if (Out<ELFT>::RelaPlt->hasRelocs()) {<br>
+    ++NumEntries; // DT_JMPREL<br>
+    ++NumEntries; // DT_PLTRELSZ<br>
+    ++NumEntries; // DT_PLTGOT<br>
+    ++NumEntries; // DT_PLTREL<br>
+  }<br>
   ++NumEntries; // DT_SYMTAB<br>
   ++NumEntries; // DT_SYMENT<br>
   ++NumEntries; // DT_STRTAB<br>
@@ -323,7 +382,12 @@ template <class ELFT> void DynamicSectio<br>
     WriteVal(IsRela ? DT_RELAENT : DT_RELENT,<br>
              IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel));<br>
   }<br>
-<br>
+  if (Out<ELFT>::RelaPlt->hasRelocs()) {<br>
+    WritePtr(DT_JMPREL, Out<ELFT>::RelaPlt->getVA());<br>
+    WriteVal(DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize());<br>
+    WritePtr(DT_PLTGOT, Out<ELFT>::Got->getVA());<br>
+    WriteVal(DT_PLTREL, Out<ELFT>::RelaPlt->isRela() ? DT_RELA : DT_REL);<br>
+  }<br>
   WritePtr(DT_SYMTAB, Out<ELFT>::DynSymTab->getVA());<br>
   WritePtr(DT_SYMENT, sizeof(Elf_Sym));<br>
   WritePtr(DT_STRTAB, Out<ELFT>::DynStrTab->getVA());<br>
@@ -695,6 +759,11 @@ template void OutputSectionBase<false>::<br>
 template void OutputSectionBase<true>::writeHeaderTo<support::big>(<br>
     ELFFile<ELFType<support::big, true>>::Elf_Shdr *SHdr);<br>
<br>
+template class GotPltSection<ELF32LE>;<br>
+template class GotPltSection<ELF32BE>;<br>
+template class GotPltSection<ELF64LE>;<br>
+template class GotPltSection<ELF64BE>;<br>
+<br>
 template class GotSection<ELF32LE>;<br>
 template class GotSection<ELF32BE>;<br>
 template class GotSection<ELF64LE>;<br>
<br>
Modified: lld/trunk/ELF/OutputSections.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.h (original)<br>
+++ lld/trunk/ELF/OutputSections.h Tue Oct 13 11:09:55 2015<br>
@@ -117,6 +117,23 @@ private:<br>
 };<br>
<br>
 template <class ELFT><br>
+class GotPltSection final : public OutputSectionBase<ELFT::Is64Bits> {<br>
+  typedef OutputSectionBase<ELFT::Is64Bits> Base;<br>
+  typedef typename Base::uintX_t uintX_t;<br>
+<br>
+public:<br>
+  GotPltSection();<br>
+  void finalize() override;<br>
+  void writeTo(uint8_t *Buf) override;<br>
+  void addEntry(SymbolBody *Sym);<br>
+  bool empty() const;<br>
+  uintX_t getEntryAddr(const SymbolBody &B) const;<br>
+<br>
+private:<br>
+  std::vector<const SymbolBody *> Entries;<br>
+};<br>
+<br>
+template <class ELFT><br>
 class PltSection final : public OutputSectionBase<ELFT::Is64Bits> {<br>
   typedef OutputSectionBase<ELFT::Is64Bits> Base;<br>
   typedef typename Base::uintX_t uintX_t;<br>
@@ -172,7 +189,7 @@ class RelocationSection final : public O<br>
   typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;<br>
<br>
 public:<br>
-  RelocationSection(bool IsRela);<br>
+  RelocationSection(StringRef Name, bool IsRela);<br>
   void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); }<br>
   void finalize() override;<br>
   void writeTo(uint8_t *Buf) override;<br>
@@ -284,6 +301,7 @@ private:<br>
 // until Writer is initialized.<br>
 template <class ELFT> struct Out {<br>
   static DynamicSection<ELFT> *Dynamic;<br>
+  static GotPltSection<ELFT> *GotPlt;<br>
   static GotSection<ELFT> *Got;<br>
   static HashTableSection<ELFT> *HashTab;<br>
   static InterpSection<ELFT::Is64Bits> *Interp;<br>
@@ -292,6 +310,7 @@ template <class ELFT> struct Out {<br>
   static uint8_t *OpdBuf;<br>
   static PltSection<ELFT> *Plt;<br>
   static RelocationSection<ELFT> *RelaDyn;<br>
+  static RelocationSection<ELFT> *RelaPlt;<br>
   static StringTableSection<ELFT::Is64Bits> *DynStrTab;<br>
   static StringTableSection<ELFT::Is64Bits> *StrTab;<br>
   static SymbolTableSection<ELFT> *DynSymTab;<br>
@@ -299,6 +318,7 @@ template <class ELFT> struct Out {<br>
 };<br>
<br>
 template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;<br>
+template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;<br>
 template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;<br>
 template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;<br>
 template <class ELFT> InterpSection<ELFT::Is64Bits> *Out<ELFT>::Interp;<br>
@@ -307,6 +327,7 @@ template <class ELFT> OutputSection<ELFT<br>
 template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;<br>
 template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;<br>
 template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;<br>
+template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;<br>
 template <class ELFT> StringTableSection<ELFT::Is64Bits> *Out<ELFT>::DynStrTab;<br>
 template <class ELFT> StringTableSection<ELFT::Is64Bits> *Out<ELFT>::StrTab;<br>
 template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;<br>
<br>
Modified: lld/trunk/ELF/Symbols.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Symbols.h (original)<br>
+++ lld/trunk/ELF/Symbols.h Tue Oct 13 11:09:55 2015<br>
@@ -79,8 +79,10 @@ public:<br>
   void setDynamicSymbolTableIndex(unsigned V) { DynamicSymbolTableIndex = V; }<br>
<br>
   uint32_t GotIndex = -1;<br>
+  uint32_t GotPltIndex = -1;<br>
   uint32_t PltIndex = -1;<br>
   bool isInGot() const { return GotIndex != -1U; }<br>
+  bool isInGotPlt() const { return GotPltIndex != -1U; }<br>
   bool isInPlt() const { return PltIndex != -1U; }<br>
<br>
   // A SymbolBody has a backreference to a Symbol. Originally they are<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Tue Oct 13 11:09:55 2015<br>
@@ -55,16 +55,40 @@ X86TargetInfo::X86TargetInfo() {<br>
   PCRelReloc = R_386_PC32;<br>
   GotReloc = R_386_GLOB_DAT;<br>
   GotRefReloc = R_386_GOT32;<br>
+  PltReloc = R_386_JUMP_SLOT;<br>
+  PltEntrySize = 16;<br>
   VAStart = 0x10000;<br>
 }<br>
<br>
+void X86TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {<br>
+  // Skip 6 bytes of "jmpq *got(%rip)"<br>
+  write32le(Buf, Plt + 6);<br>
+}<br>
+<br>
+void X86TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                      uint64_t PltEntryAddr) const {<br>
+  const uint8_t PltData[] = {<br>
+      0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip)<br>
+      0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip)<br>
+      0x00, 0x00, 0x00, 0x00<br>
+  };<br>
+  memcpy(Buf, PltData, sizeof(PltData));<br>
+  write32le(Buf + 2, GotEntryAddr - PltEntryAddr + 2); // GOT+8<br>
+  write32le(Buf + 8, GotEntryAddr - PltEntryAddr + 4); // GOT+16<br>
+};<br>
+<br>
 void X86TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                  uint64_t PltEntryAddr) const {<br>
-  // jmpl *val; nop; nop<br>
-  const uint8_t Inst[] = {0xff, 0x25, 0, 0, 0, 0, 0x90, 0x90};<br>
+                                  uint64_t PltEntryAddr, int32_t Index) const {<br>
+  const uint8_t Inst[] = {<br>
+      0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmpq *got(%rip)<br>
+      0x68, 0x00, 0x00, 0x00, 0x00,       // pushq <relocation index><br>
+      0xe9, 0x00, 0x00, 0x00, 0x00        // jmpq plt[0]<br>
+  };<br>
   memcpy(Buf, Inst, sizeof(Inst));<br>
-  assert(isUInt<32>(GotEntryAddr));<br>
-  write32le(Buf + 2, GotEntryAddr);<br>
+<br>
+  write32le(Buf + 2, GotEntryAddr - PltEntryAddr - 6);<br>
+  write32le(Buf + 7, Index);<br>
+  write32le(Buf + 12, -Index * PltEntrySize - PltZeroEntrySize - 16);<br>
 }<br>
<br>
 bool X86TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {<br>
@@ -109,7 +133,9 @@ X86_64TargetInfo::X86_64TargetInfo() {<br>
   PCRelReloc = R_X86_64_PC32;<br>
   GotReloc = R_X86_64_GLOB_DAT;<br>
   GotRefReloc = R_X86_64_PC32;<br>
+  PltReloc = R_X86_64_JUMP_SLOT;<br>
   RelativeReloc = R_X86_64_RELATIVE;<br>
+  PltEntrySize = 16;<br>
<br>
   // On freebsd x86_64 the first page cannot be mmaped.<br>
   // On linux that is controled by vm.mmap_min_addr. At least on some x86_64<br>
@@ -120,16 +146,35 @@ X86_64TargetInfo::X86_64TargetInfo() {<br>
   VAStart = 0x10000;<br>
 }<br>
<br>
+void X86_64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {<br>
+  // Skip 6 bytes of "jmpq *got(%rip)"<br>
+  write32le(Buf, Plt + 6);<br>
+}<br>
+<br>
+void X86_64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                      uint64_t PltEntryAddr) const {<br>
+  const uint8_t PltData[] = {<br>
+      0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip)<br>
+      0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip)<br>
+      0x0f, 0x1f, 0x40, 0x00              // nopl 0x0(rax)<br>
+  };<br>
+  memcpy(Buf, PltData, sizeof(PltData));<br>
+  write32le(Buf + 2, GotEntryAddr - PltEntryAddr + 2); // GOT+8<br>
+  write32le(Buf + 8, GotEntryAddr - PltEntryAddr + 4); // GOT+16<br>
+}<br>
+<br>
 void X86_64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                     uint64_t PltEntryAddr) const {<br>
-  // jmpq *val(%rip); nop; nop<br>
-  const uint8_t Inst[] = {0xff, 0x25, 0, 0, 0, 0, 0x90, 0x90};<br>
+                                     uint64_t PltEntryAddr, int32_t Index) const {<br>
+  const uint8_t Inst[] = {<br>
+      0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmpq *got(%rip)<br>
+      0x68, 0x00, 0x00, 0x00, 0x00,       // pushq <relocation index><br>
+      0xe9, 0x00, 0x00, 0x00, 0x00        // jmpq plt[0]<br>
+  };<br>
   memcpy(Buf, Inst, sizeof(Inst));<br>
<br>
-  uint64_t NextPC = PltEntryAddr + 6;<br>
-  int64_t Delta = GotEntryAddr - NextPC;<br>
-  assert(isInt<32>(Delta));<br>
-  write32le(Buf + 2, Delta);<br>
+  write32le(Buf + 2, GotEntryAddr - PltEntryAddr - 6);<br>
+  write32le(Buf + 7, Index);<br>
+  write32le(Buf + 12, -Index * PltEntrySize - PltZeroEntrySize - 16);<br>
 }<br>
<br>
 bool X86_64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {<br>
@@ -241,7 +286,9 @@ PPC64TargetInfo::PPC64TargetInfo() {<br>
   GotReloc = R_PPC64_GLOB_DAT;<br>
   GotRefReloc = R_PPC64_REL64;<br>
   RelativeReloc = R_PPC64_RELATIVE;<br>
+  // PltReloc = FIXME<br>
   PltEntrySize = 32;<br>
+  PltZeroEntrySize = 0; //FIXME<br>
<br>
   // We need 64K pages (at least under glibc/Linux, the loader won't<br>
   // set different permissions on a finer granularity than that).<br>
@@ -267,8 +314,12 @@ static uint64_t getPPC64TocBase() {<br>
   return TocVA + 0x8000;<br>
 }<br>
<br>
+<br>
+void PPC64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}<br>
+void PPC64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                       uint64_t PltEntryAddr) const {};<br>
 void PPC64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                    uint64_t PltEntryAddr) const {<br>
+                                    uint64_t PltEntryAddr, int32_t Index) const {<br>
   uint64_t Off = GotEntryAddr - getPPC64TocBase();<br>
<br>
   // FIXME: What we should do, in theory, is get the offset of the function<br>
@@ -457,11 +508,16 @@ void PPC64TargetInfo::relocateOne(uint8_<br>
 PPCTargetInfo::PPCTargetInfo() {<br>
   // PCRelReloc = FIXME<br>
   // GotReloc = FIXME<br>
+  // PltReloc = FIXME<br>
   PageSize = 65536;<br>
   VAStart = 0x10000000;<br>
 }<br>
+<br>
+void PPCTargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}<br>
+void PPCTargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                      uint64_t PltEntryAddr) const {};<br>
 void PPCTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                  uint64_t PltEntryAddr) const {}<br>
+                                  uint64_t PltEntryAddr, int32_t Index) const {}<br>
 bool PPCTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {<br>
   return false;<br>
 }<br>
@@ -475,10 +531,16 @@ void PPCTargetInfo::relocateOne(uint8_t<br>
 AArch64TargetInfo::AArch64TargetInfo() {<br>
   // PCRelReloc = FIXME<br>
   // GotReloc = FIXME<br>
+  // PltReloc = FIXME<br>
   VAStart = 0x400000;<br>
 }<br>
+<br>
+void AArch64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}<br>
+void AArch64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                          uint64_t PltEntryAddr) const {};<br>
 void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                      uint64_t PltEntryAddr) const {}<br>
+                                      uint64_t PltEntryAddr,<br>
+                                      int32_t Index) const {}<br>
 bool AArch64TargetInfo::relocNeedsGot(uint32_t Type,<br>
                                       const SymbolBody &S) const {<br>
   return false;<br>
@@ -553,12 +615,19 @@ void AArch64TargetInfo::relocateOne(uint<br>
 MipsTargetInfo::MipsTargetInfo() {<br>
   // PCRelReloc = FIXME<br>
   // GotReloc = FIXME<br>
+  // PltReloc = FIXME<br>
   PageSize = 65536;<br>
   VAStart = 0x400000;<br>
 }<br>
<br>
+void MipsTargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}<br>
+<br>
+void MipsTargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                                       uint64_t PltEntryAddr) const {}<br>
+<br>
 void MipsTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                                   uint64_t PltEntryAddr) const {}<br>
+                                   uint64_t PltEntryAddr, int32_t Index) const {<br>
+}<br>
<br>
 bool MipsTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {<br>
   return false;<br>
<br>
Modified: lld/trunk/ELF/Target.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.h (original)<br>
+++ lld/trunk/ELF/Target.h Tue Oct 13 11:09:55 2015<br>
@@ -24,11 +24,16 @@ public:<br>
   uint64_t getVAStart() const { return VAStart; }<br>
   unsigned getPCRelReloc() const { return PCRelReloc; }<br>
   unsigned getGotReloc() const { return GotReloc; }<br>
+  unsigned getPltReloc() const { return PltReloc; }<br>
   unsigned getGotRefReloc() const { return GotRefReloc; }<br>
   unsigned getRelativeReloc() const { return RelativeReloc; }<br>
+  unsigned getPltZeroEntrySize() const { return PltZeroEntrySize; }<br>
   unsigned getPltEntrySize() const { return PltEntrySize; }<br>
+  virtual void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const = 0;<br>
+  virtual void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                              uint64_t PltEntryAddr) const = 0;<br>
   virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                             uint64_t PltEntryAddr) const = 0;<br>
+                             uint64_t PltEntryAddr, int32_t Index) const = 0;<br>
   virtual bool isRelRelative(uint32_t Type) const;<br>
   virtual bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const = 0;<br>
   virtual bool relocPointsToGot(uint32_t Type) const;<br>
@@ -45,15 +50,21 @@ protected:<br>
   unsigned PCRelReloc;<br>
   unsigned GotRefReloc;<br>
   unsigned GotReloc;<br>
+  unsigned PltReloc;<br>
   unsigned RelativeReloc;<br>
   unsigned PltEntrySize = 8;<br>
+  unsigned PltZeroEntrySize = 16;<br>
+  llvm::StringRef DefaultEntry = "_start";<br>
 };<br>
<br>
 class X86TargetInfo final : public TargetInfo {<br>
 public:<br>
   X86TargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocPointsToGot(uint32_t Type) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
@@ -65,8 +76,11 @@ public:<br>
 class X86_64TargetInfo final : public TargetInfo {<br>
 public:<br>
   X86_64TargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
   void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,<br>
@@ -78,8 +92,11 @@ public:<br>
 class PPC64TargetInfo final : public TargetInfo {<br>
 public:<br>
   PPC64TargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
   void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,<br>
@@ -91,8 +108,11 @@ public:<br>
 class PPCTargetInfo final : public TargetInfo {<br>
 public:<br>
   PPCTargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
   void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,<br>
@@ -103,8 +123,11 @@ public:<br>
 class AArch64TargetInfo final : public TargetInfo {<br>
 public:<br>
   AArch64TargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
   void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,<br>
@@ -115,8 +138,11 @@ public:<br>
 class MipsTargetInfo final : public TargetInfo {<br>
 public:<br>
   MipsTargetInfo();<br>
+  void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;<br>
+  void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
+                      uint64_t PltEntryAddr) const override;<br>
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,<br>
-                     uint64_t PltEntryAddr) const override;<br>
+                     uint64_t PltEntryAddr, int32_t Index) const override;<br>
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;<br>
   void relocateOne(uint8_t *Buf, uint8_t *BufEnd, const void *RelP,<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Tue Oct 13 11:09:55 2015<br>
@@ -98,6 +98,8 @@ template <class ELFT> void lld::elf2::wr<br>
   Out<ELFT>::Bss = &Bss;<br>
   GotSection<ELFT> Got;<br>
   Out<ELFT>::Got = &Got;<br>
+  GotPltSection<ELFT> GotPlt;<br>
+  Out<ELFT>::GotPlt = &GotPlt;<br>
   PltSection<ELFT> Plt;<br>
   Out<ELFT>::Plt = &Plt;<br>
   SymbolTableSection<ELFT> SymTab(*Symtab, *Out<ELFT>::StrTab);<br>
@@ -106,8 +108,11 @@ template <class ELFT> void lld::elf2::wr<br>
   Out<ELFT>::DynSymTab = &DynSymTab;<br>
   HashTableSection<ELFT> HashTab;<br>
   Out<ELFT>::HashTab = &HashTab;<br>
-  RelocationSection<ELFT> RelaDyn(Symtab->shouldUseRela());<br>
+  bool IsRela = Symtab->shouldUseRela();<br>
+  RelocationSection<ELFT> RelaDyn(IsRela ? ".rela.dyn" : ".rel.dyn", IsRela);<br>
   Out<ELFT>::RelaDyn = &RelaDyn;<br>
+  RelocationSection<ELFT> RelaPlt(IsRela ? ".rela.plt" : ".rel.plt", IsRela);<br>
+  Out<ELFT>::RelaPlt = &RelaPlt;<br>
   DynamicSection<ELFT> Dynamic(*Symtab);<br>
   Out<ELFT>::Dynamic = &Dynamic;<br>
<br>
@@ -187,8 +192,8 @@ void Writer<ELFT>::scanRelocs(<br>
         if (Body->isInPlt())<br>
           continue;<br>
         Out<ELFT>::Plt->addEntry(Body);<br>
-      }<br>
-      if (Target->relocNeedsGot(Type, *Body)) {<br>
+        Out<ELFT>::GotPlt->addEntry(Body);<br>
+      } else if (Target->relocNeedsGot(Type, *Body)) {<br>
         if (Body->isInGot())<br>
           continue;<br>
         Out<ELFT>::Got->addEntry(Body);<br>
@@ -200,7 +205,10 @@ void Writer<ELFT>::scanRelocs(<br>
       continue;<br>
     if (CBP)<br>
       Body->setUsedInDynamicReloc();<br>
-    Out<ELFT>::RelaDyn->addReloc({C, RI});<br>
+    if (Body && Target->relocNeedsPlt(Type, *Body))<br>
+      Out<ELFT>::RelaPlt->addReloc({ C, RI });<br>
+    else<br>
+      Out<ELFT>::RelaDyn->addReloc({ C, RI });<br>
   }<br>
 }<br>
<br>
@@ -447,9 +455,13 @@ template <class ELFT> void Writer<ELFT>:<br>
     OutputSections.push_back(Out<ELFT>::DynStrTab);<br>
     if (Out<ELFT>::RelaDyn->hasRelocs())<br>
       OutputSections.push_back(Out<ELFT>::RelaDyn);<br>
+    if (Out<ELFT>::RelaPlt->hasRelocs())<br>
+      OutputSections.push_back(Out<ELFT>::RelaPlt);<br>
   }<br>
   if (!Out<ELFT>::Got->empty())<br>
     OutputSections.push_back(Out<ELFT>::Got);<br>
+  if (!Out<ELFT>::GotPlt->empty())<br>
+    OutputSections.push_back(Out<ELFT>::GotPlt);<br>
   if (!Out<ELFT>::Plt->empty())<br>
     OutputSections.push_back(Out<ELFT>::Plt);<br>
<br>
<br>
Modified: lld/trunk/test/elf2/plt-i686.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt-i686.s?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt-i686.s?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/plt-i686.s (original)<br>
+++ lld/trunk/test/elf2/plt-i686.s Tue Oct 13 11:09:55 2015<br>
@@ -14,42 +14,63 @@<br>
 // CHECK-NEXT: ]<br>
 // CHECK-NEXT: Address: 0x11010<br>
 // CHECK-NEXT: Offset:<br>
-// CHECK-NEXT: Size: 16<br>
+// CHECK-NEXT: Size: 48<br>
 // CHECK-NEXT: Link: 0<br>
 // CHECK-NEXT: Info: 0<br>
 // CHECK-NEXT: AddressAlignment: 16<br>
<br>
+// CHECK:      Name: .got.plt<br>
+// CHECK-NEXT: Type: SHT_PROGBITS<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT:   SHF_ALLOC<br>
+// CHECK-NEXT:   SHF_WRITE<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address: 0x12058<br>
+// CHECK-NEXT: Offset: 0x2058<br>
+// CHECK-NEXT: Size: 20<br>
+// CHECK-NEXT: Link: 0<br>
+// CHECK-NEXT: Info: 0<br>
+// CHECK-NEXT: AddressAlignment: 4<br>
+// CHECK-NEXT: EntrySize: 0<br>
+<br>
 // CHECK:      Relocations [<br>
-// CHECK-NEXT:   Section ({{.*}}) .rel.dyn {<br>
-// CHECK-NEXT:     0x12050 R_386_GLOB_DAT bar 0x0<br>
-// CHECK-NEXT:     0x12054 R_386_GLOB_DAT zed 0x0<br>
+// CHECK-NEXT:   Section ({{.*}}) .rel.plt {<br>
+// CHECK-NEXT:     0x12064 R_386_JUMP_SLOT bar 0x0<br>
+// CHECK-NEXT:     0x12068 R_386_JUMP_SLOT zed 0x0<br>
 // CHECK-NEXT:   }<br>
 // CHECK-NEXT: ]<br>
<br>
 // Unfortunately FileCheck can't do math, so we have to check for explicit<br>
 // values:<br>
<br>
-// 0x11010 - (0x11000 + 1) - 4 = 11<br>
-// 0x11010 - (0x11005 + 1) - 4 = 2<br>
-// 0x11018 - (0x1100a + 1) - 4 = 9<br>
+// 16 is the size of PLT[0]<br>
+// (0x11010 + 16) - (0x11000 + 1) - 4 = 27<br>
+// (0x11010 + 16) - (0x11005 + 1) - 4 = 22<br>
+// (0x11020 + 16) - (0x1100a + 1) - 4 = 33<br>
<br>
 // DISASM:      _start:<br>
-// DISASM-NEXT:   11000:  e9 0b 00 00 00  jmp  11<br>
-// DISASM-NEXT:   11005:  e9 06 00 00 00  jmp  6<br>
-// DISASM-NEXT:   1100a:  e9 09 00 00 00  jmp  9<br>
-<br>
-// 0x12050 = 73808<br>
-// 0x12054 = 73812<br>
-<br>
+// DISASM-NEXT:   11000:  e9 1b 00 00 00  jmp  27<br>
+// DISASM-NEXT:   11005:  e9 16 00 00 00  jmp  22<br>
+// DISASM-NEXT:   1100a:  e9 21 00 00 00  jmp  33<br>
+<br>
+// 0x12064 - 0x11020 - 6 = 4158<br>
+// 0x12068 - 0x11030 - 6 = 4146<br>
+// 0x11010 - 0x1102b - 5 = -32<br>
+// 0x11010 - 0x1103b - 5 = -48<br>
 // DISASM:      Disassembly of section .plt:<br>
 // DISASM-NEXT: .plt:<br>
-// DISASM-NEXT:   11010:  ff 25 {{.*}}       jmpl *73808<br>
-// DISASM-NEXT:   11016:  90                 nop<br>
-// DISASM-NEXT:   11017:  90                 nop<br>
-// DISASM-NEXT:   11018:  ff 25 {{.*}}       jmpl *73812<br>
-// DISASM-NEXT:   1101e:  90                 nop<br>
-// DISASM-NEXT:   1101f:  90                 nop<br>
-<br>
+// DISASM-NEXT:   11010:  ff 35 4a 10 00 00 pushl 4170<br>
+// DISASM-NEXT:   11016:  ff 25 4c 10 00 00 jmpl *4172<br>
+// DISASM-NEXT:   1101c:  00 00  addb %al, (%eax)<br>
+// DISASM-NEXT:   1101e:  00 00  addb %al, (%eax)<br>
+// DISASM-NEXT:   11020:  ff 25 3e 10 00 00 jmpl *4158<br>
+// DISASM-NEXT:   11026:  68 00 00 00 00 pushl $0<br>
+// DISASM-NEXT:   1102b:  e9 e0 ff ff ff jmp -32<br>
+// DISASM-NEXT:   11030:  ff 25 32 10 00 00 jmpl *4146<br>
+// DISASM-NEXT:   11036:  68 01 00 00 00 pushl $1<br>
+// DISASM-NEXT:   1103b:  e9 d0 ff ff ff jmp -48<br>
+<br>
+<br>
 .global _start<br>
 _start:<br>
   jmp bar@PLT<br>
<br>
Modified: lld/trunk/test/elf2/plt.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt.s?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt.s?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/plt.s (original)<br>
+++ lld/trunk/test/elf2/plt.s Tue Oct 13 11:09:55 2015<br>
@@ -14,42 +14,49 @@<br>
 // CHECK-NEXT: ]<br>
 // CHECK-NEXT: Address: 0x1020<br>
 // CHECK-NEXT: Offset:<br>
-// CHECK-NEXT: Size: 24<br>
+// CHECK-NEXT: Size: 64<br>
 // CHECK-NEXT: Link: 0<br>
 // CHECK-NEXT: Info: 0<br>
 // CHECK-NEXT: AddressAlignment: 16<br>
<br>
 // CHECK:      Relocations [<br>
-// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {<br>
-// CHECK-NEXT:     0x20A0 R_X86_64_GLOB_DAT bar 0x0<br>
-// CHECK-NEXT:     0x20A8 R_X86_64_GLOB_DAT zed 0x0<br>
-// CHECK-NEXT:     0x20B0 R_X86_64_GLOB_DAT _start 0x0<br>
+// CHECK-NEXT:   Section ({{.*}}) .rela.plt {<br>
+// CHECK-NEXT:     0x20C8 R_X86_64_JUMP_SLOT bar 0x0<br>
+// CHECK-NEXT:     0x20D0 R_X86_64_JUMP_SLOT zed 0x0<br>
+// CHECK-NEXT:     0x20D8 R_X86_64_JUMP_SLOT _start 0x0<br>
 // CHECK-NEXT:   }<br>
 // CHECK-NEXT: ]<br>
<br>
 // Unfortunately FileCheck can't do math, so we have to check for explicit<br>
 // values:<br>
<br>
-// 0x11020 - (0x11000 + 1) - 4 = 27<br>
-// 0x11020 - (0x11005 + 1) - 4 = 22<br>
-// 0x11028 - (0x1100a + 1) - 4 = 25<br>
+// 0x1030 - (0x1000 + 5) = 43<br>
+// 0x1030 - (0x1005 + 5) = 38<br>
+// 0x1040 - (0x100a + 5) = 49<br>
<br>
 // DISASM:      _start:<br>
-// DISASM-NEXT:   1000:  e9 {{.*}}       jmp  27<br>
-// DISASM-NEXT:   1005:  e9 {{.*}}       jmp  22<br>
-// DISASM-NEXT:   100a:  e9 {{.*}}       jmp  25<br>
+// DISASM-NEXT:   1000:  e9 {{.*}}       jmp  43<br>
+// DISASM-NEXT:   1005:  e9 {{.*}}       jmp  38<br>
+// DISASM-NEXT:   100a:  e9 {{.*}}       jmp  49<br>
<br>
-// 0x120A0 - 0x11026  = 4218<br>
-// 0x120A8 - 0x1102e  = 4218<br>
+// 0x20C8 - 0x1036  = 4242<br>
+// 0x20D0 - 0x1046  = 4234<br>
<br>
 // DISASM:      Disassembly of section .plt:<br>
 // DISASM-NEXT: .plt:<br>
-// DISASM-NEXT:   1020:  ff 25 {{.*}}       jmpq *4218(%rip)<br>
-// DISASM-NEXT:   1026:  90                 nop<br>
-// DISASM-NEXT:   1027:  90                 nop<br>
-// DISASM-NEXT:   1028:  ff 25 {{.*}}       jmpq *4218(%rip)<br>
-// DISASM-NEXT:   102e:  90                 nop<br>
-// DISASM-NEXT:   102f:  90                 nop<br>
+// DISASM-NEXT:   1020:  ff 35 92 10 00 00  pushq 4242(%rip)<br>
+// DISASM-NEXT:   1026:  ff 25 94 10 00 00  jmpq *4244(%rip)<br>
+// DISASM-NEXT:   102c:  0f 1f 40 00        nopl (%rax)<br>
+// DISASM-NEXT:   1030:  ff 25 92 10 00 00  jmpq *4242(%rip)<br>
+// DISASM-NEXT:   1036:  68 00 00 00 00     pushq $0<br>
+// DISASM-NEXT:   103b:  e9 e0 ff ff ff     jmp -32 <bar+1020><br>
+// DISASM-NEXT:   1040:  ff 25 8a 10 00 00  jmpq *4234(%rip)<br>
+// DISASM-NEXT:   1046:  68 01 00 00 00     pushq $1<br>
+// DISASM-NEXT:   104b:  e9 d0 ff ff ff     jmp -48 <bar+1020><br>
+// DISASM-NEXT:   1050:  ff 25 82 10 00 00  jmpq *4226(%rip)<br>
+// DISASM-NEXT:   1056:  68 02 00 00 00     pushq $2<br>
+// DISASM-NEXT:   105b:  e9 c0 ff ff ff     jmp -64 <bar+1020><br>
+<br>
<br>
 .global _start<br>
 _start:<br>
<br>
Modified: lld/trunk/test/elf2/relocation-i686.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-i686.s?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-i686.s?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/relocation-i686.s (original)<br>
+++ lld/trunk/test/elf2/relocation-i686.s Tue Oct 13 11:09:55 2015<br>
@@ -47,7 +47,7 @@ movl bar@GOT, %eax<br>
 // ADDR-NEXT: ]<br>
 // ADDR-NEXT: Address: 0x11030<br>
 // ADDR-NEXT: Offset: 0x1030<br>
-// ADDR-NEXT: Size: 8<br>
+// ADDR-NEXT: Size: 32<br>
<br>
 // ADDR:      Name: .got<br>
 // ADDR-NEXT: Type: SHT_PROGBITS<br>
@@ -55,24 +55,25 @@ movl bar@GOT, %eax<br>
 // ADDR-NEXT:   SHF_ALLOC<br>
 // ADDR-NEXT:   SHF_WRITE<br>
 // ADDR-NEXT: ]<br>
-// ADDR-NEXT: Address: 0x12050<br>
+// ADDR-NEXT: Address: 0x12070<br>
<br>
 .section .R_386_GOTPC,"ax",@progbits<br>
 R_386_GOTPC:<br>
  movl $_GLOBAL_OFFSET_TABLE_, %eax<br>
<br>
-// 0x12050 - 0x11014 = 4156<br>
+// 0x12070 - 0x11014 = 4188<br>
<br>
 // CHECK:      Disassembly of section .R_386_GOTPC:<br>
 // CHECK-NEXT: R_386_GOTPC:<br>
-// CHECK-NEXT:   11014:  {{.*}} movl  $4156, %eax<br>
+// CHECK-NEXT:   11014:  {{.*}} movl  $4188, %eax<br>
<br>
 .section .dynamic_reloc, "ax",@progbits<br>
  call bar<br>
-// 0x11030 - (0x11019 + 5) = 18<br>
+// (0x11030 + 16) - (0x11019 + 5) = 34<br>
+// 16 - is a size of PLT[0]<br>
 // CHECK:      Disassembly of section .dynamic_reloc:<br>
 // CHECK-NEXT: .dynamic_reloc:<br>
-// CHECK-NEXT:   11019:  e8 12 00 00 00 calll 18<br>
+// CHECK-NEXT:   11019:  e8 22 00 00 00 calll 34<br>
<br>
 .section .R_386_GOT32,"ax",@progbits<br>
 .global R_386_GOT32<br>
<br>
Modified: lld/trunk/test/elf2/relocation.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation.s?rev=250169&r1=250168&r2=250169&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation.s?rev=250169&r1=250168&r2=250169&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/relocation.s (original)<br>
+++ lld/trunk/test/elf2/relocation.s Tue Oct 13 11:09:55 2015<br>
@@ -14,23 +14,39 @@<br>
 // SEC-NEXT: ]<br>
 // SEC-NEXT: Address: 0x11020<br>
 // SEC-NEXT: Offset: 0x1020<br>
-// SEC-NEXT: Size: 8<br>
+// SEC-NEXT: Size: 32<br>
<br>
-// SEC:         Name: .got<br>
+// SEC:        Name: .got<br>
 // SEC-NEXT:   Type: SHT_PROGBITS<br>
 // SEC-NEXT:   Flags [<br>
 // SEC-NEXT:     SHF_ALLOC<br>
 // SEC-NEXT:     SHF_WRITE<br>
 // SEC-NEXT:   ]<br>
-// SEC-NEXT:   Address: 0x120A0<br>
+// SEC-NEXT:   Address: 0x120E0<br>
 // SEC-NEXT:   Offset:<br>
-// SEC-NEXT:   Size: 16<br>
+// SEC-NEXT:   Size: 8<br>
 // SEC-NEXT:   Link: 0<br>
 // SEC-NEXT:   Info: 0<br>
 // SEC-NEXT:   AddressAlignment: 8<br>
 // SEC-NEXT:   EntrySize: 0<br>
 // SEC-NEXT: }<br>
<br>
+// SEC:        Name: .got.plt<br>
+// SEC-NEXT:   Type: SHT_PROGBITS<br>
+// SEC-NEXT:   Flags [<br>
+// SEC-NEXT:     SHF_ALLOC<br>
+// SEC-NEXT:     SHF_WRITE<br>
+// SEC-NEXT:   ]<br>
+// SEC-NEXT:   Address: 0x120E8<br>
+// SEC-NEXT:   Offset: 0x20E8<br>
+// SEC-NEXT:   Size: 32<br>
+// SEC-NEXT:   Link: 0<br>
+// SEC-NEXT:   Info: 0<br>
+// SEC-NEXT:   AddressAlignment: 8<br>
+// SEC-NEXT:   EntrySize: 0<br>
+// SEC-NEXT:   }<br>
+<br>
+<br>
 .section       .text,"ax",@progbits,unique,1<br>
 .global _start<br>
 _start:<br>
@@ -75,10 +91,11 @@ R_X86_64_32S:<br>
 .global R_X86_64_PC32<br>
 R_X86_64_PC32:<br>
  call bar<br>
-// 0x11020 - (0x11017 + 5) = 4<br>
+// (0x11020 + 16) - (0x11017 + 5) = 20<br>
+// 16 - is a size of PLT[0]<br>
 // CHECK:      Disassembly of section .R_X86_64_PC32:<br>
 // CHECK-NEXT: R_X86_64_PC32:<br>
-// CHECK-NEXT:  11017:   e8 04 00 00 00  callq  4<br>
+// CHECK-NEXT:  11017:   e8 14 00 00 00  callq  20<br>
<br>
 .section .R_X86_64_64,"a",@progbits<br>
 .global R_X86_64_64<br>
@@ -93,7 +110,7 @@ R_X86_64_64:<br>
 R_X86_64_GOTPCREL:<br>
  .long zed@gotpcrel<br>
<br>
-// 0x120A8 - 0x10160 = 8008<br>
-// 8008 = 0x481f0000   in little endian<br>
+// 0x120E0 - 0x10160 = 8064<br>
+// 8064 = 0x801f0000   in little endian<br>
 // CHECK:      Contents of section .R_X86_64_GOTPCREL<br>
-// CHECK-NEXT:   10160 481f0000<br>
+// CHECK-NEXT:   10160 801f0000<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>