[lld] r249835 - Revert "[ELF2] - Implemented rel[a].plt sections"

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 07:25:49 PDT 2015


Author: rafael
Date: Fri Oct  9 09:25:49 2015
New Revision: 249835

URL: http://llvm.org/viewvc/llvm-project?rev=249835&view=rev
Log:
Revert "[ELF2] - Implemented rel[a].plt sections"

This reverts commit r249816.

It broke building llvm with lld:

$ ./bin/FileCheck
./bin/FileCheck: error while loading shared libraries: unexpected PLT reloc type 0x06

I think the only thing that is wrong with this patch is that it is too soon.

The plt we create (and its relocs) don't support lazy loading, so they have
to be relocated as ordinary dynamic relocations.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/plt-i686.s
    lld/trunk/test/elf2/plt.s
    lld/trunk/test/elf2/relocation.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Oct  9 09:25:49 2015
@@ -48,10 +48,6 @@ template <> RelocationSection<ELF32BE> *
 template <> RelocationSection<ELF32LE> *Out<ELF32LE>::RelaDyn = nullptr;
 template <> RelocationSection<ELF64BE> *Out<ELF64BE>::RelaDyn = nullptr;
 template <> RelocationSection<ELF64LE> *Out<ELF64LE>::RelaDyn = nullptr;
-template <> RelocationSection<ELF32BE> *Out<ELF32BE>::RelaPlt = nullptr;
-template <> RelocationSection<ELF32LE> *Out<ELF32LE>::RelaPlt = nullptr;
-template <> RelocationSection<ELF64BE> *Out<ELF64BE>::RelaPlt = nullptr;
-template <> RelocationSection<ELF64LE> *Out<ELF64LE>::RelaPlt = nullptr;
 template <> StringTableSection<false> *Out<ELF32BE>::DynStrTab = nullptr;
 template <> StringTableSection<false> *Out<ELF32LE>::DynStrTab = nullptr;
 template <> StringTableSection<true> *Out<ELF64BE>::DynStrTab = nullptr;
@@ -143,9 +139,10 @@ void PltSection<ELFT>::finalize() {
 }
 
 template <class ELFT>
-RelocationSection<ELFT>::RelocationSection(StringRef Name, bool IsRela)
-    : OutputSectionBase<ELFT::Is64Bits>(Name, IsRela ? llvm::ELF::SHT_RELA
-                                                     : llvm::ELF::SHT_REL,
+RelocationSection<ELFT>::RelocationSection(bool IsRela)
+    : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",
+                                        IsRela ? llvm::ELF::SHT_RELA
+                                               : llvm::ELF::SHT_REL,
                                         llvm::ELF::SHF_ALLOC),
       IsRela(IsRela) {
   this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
@@ -303,13 +300,6 @@ template <class ELFT> void DynamicSectio
     ++NumEntries; // DT_RELASZ / DT_RELSZ
     ++NumEntries; // DT_RELAENT / DT_RELENT
   }
-  if (Out<ELFT>::RelaPlt->hasRelocs()) {
-    ++NumEntries; // DT_JMPREL
-    ++NumEntries; // DT_PLTRELSZ
-    ++NumEntries; // DT_PLTGOT
-    ++NumEntries; // DT_PLTREL
-  }
-
   ++NumEntries; // DT_SYMTAB
   ++NumEntries; // DT_SYMENT
   ++NumEntries; // DT_STRTAB
@@ -377,12 +367,6 @@ template <class ELFT> void DynamicSectio
     WriteVal(IsRela ? DT_RELAENT : DT_RELENT,
              IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel));
   }
-  if (Out<ELFT>::RelaPlt->hasRelocs()) {
-    WritePtr(DT_JMPREL, Out<ELFT>::RelaPlt->getVA());
-    WriteVal(DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize());
-    WritePtr(DT_PLTGOT, Out<ELFT>::Got->getVA());
-    WriteVal(DT_PLTREL, Out<ELFT>::RelaPlt->isRela() ? DT_RELA : DT_REL);
-  }
 
   WritePtr(DT_SYMTAB, Out<ELFT>::DynSymTab->getVA());
   WritePtr(DT_SYMENT, sizeof(Elf_Sym));

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Fri Oct  9 09:25:49 2015
@@ -171,7 +171,7 @@ class RelocationSection final : public O
   typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
 
 public:
-  RelocationSection(StringRef Name, bool IsRela);
+  RelocationSection(bool IsRela);
   void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); }
   void finalize() override;
   void writeTo(uint8_t *Buf) override;
@@ -289,7 +289,6 @@ template <class ELFT> struct Out {
   static OutputSection<ELFT> *Bss;
   static PltSection<ELFT> *Plt;
   static RelocationSection<ELFT> *RelaDyn;
-  static RelocationSection<ELFT> *RelaPlt;
   static StringTableSection<ELFT::Is64Bits> *DynStrTab;
   static StringTableSection<ELFT::Is64Bits> *StrTab;
   static SymbolTableSection<ELFT> *DynSymTab;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct  9 09:25:49 2015
@@ -134,11 +134,8 @@ template <class ELFT> static void doWrit
   Out<ELFT>::DynSymTab = &DynSymTab;
   HashTableSection<ELFT> HashTab;
   Out<ELFT>::HashTab = &HashTab;
-  bool IsRela = Symtab->shouldUseRela();
-  RelocationSection<ELFT> RelaDyn(IsRela ? ".rela.dyn" : ".rel.dyn", IsRela);
+  RelocationSection<ELFT> RelaDyn(Symtab->shouldUseRela());
   Out<ELFT>::RelaDyn = &RelaDyn;
-  RelocationSection<ELFT> RelaPlt(IsRela ? ".rela.plt" : ".rel.plt", IsRela);
-  Out<ELFT>::RelaPlt = &RelaPlt;
   DynamicSection<ELFT> Dynamic(*Symtab);
   Out<ELFT>::Dynamic = &Dynamic;
 
@@ -236,15 +233,11 @@ void Writer<ELFT>::scanRelocs(
         Out<ELFT>::Got->addEntry(Body);
       }
     }
-
-    bool CanBePreempted = canBePreempted(Body);
-    if (CanBePreempted)
+    if (canBePreempted(Body)) {
       Body->setUsedInDynamicReloc();
-    if (CanBePreempted || (Config->Shared && !Target->isRelRelative(Type))) {
-      if (Body && Body->isInPlt())
-        Out<ELFT>::RelaPlt->addReloc({C, RI});
-      else
-        Out<ELFT>::RelaDyn->addReloc({C, RI});
+      Out<ELFT>::RelaDyn->addReloc({C, RI});
+    } else if (Config->Shared && !Target->isRelRelative(Type)) {
+      Out<ELFT>::RelaDyn->addReloc({C, RI});
     }
   }
 }
@@ -473,8 +466,6 @@ template <class ELFT> void Writer<ELFT>:
     OutputSections.push_back(Out<ELFT>::DynStrTab);
     if (Out<ELFT>::RelaDyn->hasRelocs())
       OutputSections.push_back(Out<ELFT>::RelaDyn);
-    if (Out<ELFT>::RelaPlt->hasRelocs())
-      OutputSections.push_back(Out<ELFT>::RelaPlt);
   }
   if (!Out<ELFT>::Got->empty())
     OutputSections.push_back(Out<ELFT>::Got);

Modified: lld/trunk/test/elf2/plt-i686.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt-i686.s?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/test/elf2/plt-i686.s (original)
+++ lld/trunk/test/elf2/plt-i686.s Fri Oct  9 09:25:49 2015
@@ -20,9 +20,9 @@
 // CHECK-NEXT: AddressAlignment: 16
 
 // CHECK:      Relocations [
-// CHECK-NEXT:   Section ({{.*}}) .rel.plt {
-// CHECK-NEXT:     0x13058 R_386_GLOB_DAT bar 0x0
-// CHECK-NEXT:     0x1305C R_386_GLOB_DAT zed 0x0
+// CHECK-NEXT:   Section ({{.*}}) .rel.dyn {
+// CHECK-NEXT:     0x13050 R_386_GLOB_DAT bar 0x0
+// CHECK-NEXT:     0x13054 R_386_GLOB_DAT zed 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
@@ -38,15 +38,15 @@
 // DISASM-NEXT:   12005:  e9 06 00 00 00  jmp  6
 // DISASM-NEXT:   1200a:  e9 09 00 00 00  jmp  9
 
-// 0x13058 = 77912
-// 0x1305C = 77916
+// 0x13050 = 77904
+// 0x13054 = 77908
 
 // DISASM:      Disassembly of section .plt:
 // DISASM-NEXT: .plt:
-// DISASM-NEXT:   12010:  ff 25 {{.*}}       jmpl *77912
+// DISASM-NEXT:   12010:  ff 25 {{.*}}       jmpl *77904
 // DISASM-NEXT:   12016:  90                 nop
 // DISASM-NEXT:   12017:  90                 nop
-// DISASM-NEXT:   12018:  ff 25 {{.*}}       jmpl *77916
+// DISASM-NEXT:   12018:  ff 25 {{.*}}       jmpl *77908
 // DISASM-NEXT:   1201e:  90                 nop
 // DISASM-NEXT:   1201f:  90                 nop
 

Modified: lld/trunk/test/elf2/plt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt.s?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/test/elf2/plt.s (original)
+++ lld/trunk/test/elf2/plt.s Fri Oct  9 09:25:49 2015
@@ -20,10 +20,10 @@
 // CHECK-NEXT: AddressAlignment: 16
 
 // CHECK:      Relocations [
-// CHECK-NEXT:   Section ({{.*}}) .rela.plt {
-// CHECK-NEXT:     0x30B0 R_X86_64_GLOB_DAT bar 0x0
-// CHECK-NEXT:     0x30B8 R_X86_64_GLOB_DAT zed 0x0
-// CHECK-NEXT:     0x30C0 R_X86_64_GLOB_DAT _start 0x0
+// CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
+// CHECK-NEXT:     0x30A0 R_X86_64_GLOB_DAT bar 0x0
+// CHECK-NEXT:     0x30A8 R_X86_64_GLOB_DAT zed 0x0
+// CHECK-NEXT:     0x30B0 R_X86_64_GLOB_DAT _start 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
@@ -39,15 +39,15 @@
 // DISASM-NEXT:   2005:  e9 {{.*}}       jmp  22
 // DISASM-NEXT:   200a:  e9 {{.*}}       jmp  25
 
-// 0x30B0 - 0x2026  = 4234
-// 0x30B8 - 0x202e  = 4234
+// 0x130A0 - 0x12026  = 4218
+// 0x130A8 - 0x1202e  = 4218
 
 // DISASM:      Disassembly of section .plt:
 // DISASM-NEXT: .plt:
-// DISASM-NEXT:   2020:  ff 25 {{.*}}       jmpq *4234(%rip)
+// DISASM-NEXT:   2020:  ff 25 {{.*}}       jmpq *4218(%rip)
 // DISASM-NEXT:   2026:  90                 nop
 // DISASM-NEXT:   2027:  90                 nop
-// DISASM-NEXT:   2028:  ff 25 {{.*}}       jmpq *4234(%rip)
+// DISASM-NEXT:   2028:  ff 25 {{.*}}       jmpq *4218(%rip)
 // DISASM-NEXT:   202e:  90                 nop
 // DISASM-NEXT:   202f:  90                 nop
 

Modified: lld/trunk/test/elf2/relocation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation.s?rev=249835&r1=249834&r2=249835&view=diff
==============================================================================
--- lld/trunk/test/elf2/relocation.s (original)
+++ lld/trunk/test/elf2/relocation.s Fri Oct  9 09:25:49 2015
@@ -22,7 +22,7 @@
 // SEC-NEXT:     SHF_ALLOC
 // SEC-NEXT:     SHF_WRITE
 // SEC-NEXT:   ]
-// SEC-NEXT:   Address: 0x130E0
+// SEC-NEXT:   Address: 0x130A0
 // SEC-NEXT:   Offset:
 // SEC-NEXT:   Size: 16
 // SEC-NEXT:   Link: 0
@@ -93,7 +93,7 @@ R_X86_64_64:
 R_X86_64_GOTPCREL:
  .long zed at gotpcrel
 
-// 0x130E8 - 0x11008 = 8416
-// 8416 = 0xE0200000   in little endian
+// 0x130A8 - 0x11008 = 8352
+// 8352 = 0x80200000   in little endian
 // CHECK:      Contents of section .R_X86_64_GOTPCREL
-// CHECK-NEXT:   11008 e0200000
+// CHECK-NEXT:   11008 a0200000




More information about the llvm-commits mailing list