[lld] r250300 - Add support for a R_X86_64_32 referring to a plt.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 09:15:47 PDT 2015


Author: rafael
Date: Wed Oct 14 11:15:46 2015
New Revision: 250300

URL: http://llvm.org/viewvc/llvm-project?rev=250300&view=rev
Log:
Add support for a R_X86_64_32 referring to a plt.

This can show up with a non-PIC .o being linked into an executable that uses
shared libraries.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/test/elf2/relocation.s

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=250300&r1=250299&r2=250300&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Oct 14 11:15:46 2015
@@ -51,7 +51,7 @@ void InputSection<ELFT>::relocate(
     uintX_t SymVA = getSymVA<ELFT>(Body);
     if (Target->relocNeedsPlt(Type, Body)) {
       SymVA = Out<ELFT>::Plt->getEntryAddr(Body);
-      Type = Target->getPCRelReloc();
+      Type = Target->getPLTRefReloc(Type);
     } else if (Target->relocNeedsGot(Type, Body)) {
       SymVA = Out<ELFT>::Got->getEntryAddr(Body);
       Type = Target->getGotRefReloc();

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250300&r1=250299&r2=250300&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Oct 14 11:15:46 2015
@@ -59,6 +59,8 @@ TargetInfo *createTarget() {
 
 TargetInfo::~TargetInfo() {}
 
+unsigned TargetInfo::getPLTRefReloc(unsigned Type) const { return PCRelReloc; }
+
 bool TargetInfo::relocPointsToGot(uint32_t Type) const { return false; }
 
 bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
@@ -144,10 +146,22 @@ bool X86_64TargetInfo::relocNeedsGot(uin
   return Type == R_X86_64_GOTPCREL || relocNeedsPlt(Type, S);
 }
 
+unsigned X86_64TargetInfo::getPLTRefReloc(unsigned Type) const {
+  switch (Type) {
+  case R_X86_64_32:
+    return R_X86_64_32;
+  case R_X86_64_PC32:
+  case R_X86_64_PLT32:
+    return R_X86_64_PC32;
+  }
+  llvm_unreachable("Unexpected relocation");
+}
+
 bool X86_64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
   switch (Type) {
   default:
     return false;
+  case R_X86_64_32:
   case R_X86_64_PC32:
     // This relocation is defined to have a value of (S + A - P).
     // The problems start when a non PIC program calls a function in a shared

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=250300&r1=250299&r2=250300&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Oct 14 11:15:46 2015
@@ -26,6 +26,7 @@ public:
   unsigned getGotRefReloc() const { return GotRefReloc; }
   unsigned getRelativeReloc() const { return RelativeReloc; }
   unsigned getPltEntrySize() const { return PltEntrySize; }
+  virtual unsigned getPLTRefReloc(unsigned Type) const;
   virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
                              uint64_t PltEntryAddr) const = 0;
   virtual bool isRelRelative(uint32_t Type) const;
@@ -63,6 +64,7 @@ public:
 class X86_64TargetInfo final : public TargetInfo {
 public:
   X86_64TargetInfo();
+  unsigned getPLTRefReloc(unsigned Type) const override;
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
                      uint64_t PltEntryAddr) const override;
   bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;

Modified: lld/trunk/test/elf2/relocation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation.s?rev=250300&r1=250299&r2=250300&view=diff
==============================================================================
--- lld/trunk/test/elf2/relocation.s (original)
+++ lld/trunk/test/elf2/relocation.s Wed Oct 14 11:15:46 2015
@@ -12,8 +12,8 @@
 // SEC-NEXT:   SHF_ALLOC
 // SEC-NEXT:   SHF_EXECINSTR
 // SEC-NEXT: ]
-// SEC-NEXT: Address: 0x11020
-// SEC-NEXT: Offset: 0x1020
+// SEC-NEXT: Address: 0x11030
+// SEC-NEXT: Offset: 0x1030
 // SEC-NEXT: Size: 8
 
 // SEC:         Name: .got
@@ -75,10 +75,13 @@ R_X86_64_32S:
 .global R_X86_64_PC32
 R_X86_64_PC32:
  call bar
-// 0x11020 - (0x11017 + 5) = 4
+ movl $bar, %eax
+// 0x11030 - (0x11017 + 5) = 20
+// 0x11030 = 69680
 // CHECK:      Disassembly of section .R_X86_64_PC32:
 // CHECK-NEXT: R_X86_64_PC32:
-// CHECK-NEXT:  11017:   e8 04 00 00 00  callq  4
+// CHECK-NEXT:  11017:   {{.*}}  callq  20
+// CHECK-NEXT:  1101c:   {{.*}}  movl $69680, %eax
 
 .section .R_X86_64_64,"a", at progbits
 .global R_X86_64_64




More information about the llvm-commits mailing list