[lld] r248793 - Add R_386_GOTPC support.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 06:36:32 PDT 2015


Author: rafael
Date: Tue Sep 29 08:36:32 2015
New Revision: 248793

URL: http://llvm.org/viewvc/llvm-project?rev=248793&view=rev
Log:
Add R_386_GOTPC support.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=248793&r1=248792&r2=248793&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Sep 29 08:36:32 2015
@@ -57,6 +57,9 @@ void InputSection<ELFT>::relocate(
       } else if (Target->relocNeedsGot(Type)) {
         SymVA = GotSec.getEntryAddr(Body);
         Type = Target->getPCRelReloc();
+      } else if (Target->relocPointsToGot(Type)) {
+        SymVA = GotSec.getVA();
+        Type = Target->getPCRelReloc();
       }
     }
 

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=248793&r1=248792&r2=248793&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Sep 29 08:36:32 2015
@@ -27,6 +27,8 @@ std::unique_ptr<TargetInfo> Target;
 
 TargetInfo::~TargetInfo() {}
 
+bool TargetInfo::relocPointsToGot(uint32_t Type) const { return false; }
+
 X86TargetInfo::X86TargetInfo() {
   PCRelReloc = R_386_PC32;
   GotReloc = R_386_GLOB_DAT;
@@ -57,6 +59,10 @@ bool X86TargetInfo::relocNeedsGot(uint32
   }
 }
 
+bool X86TargetInfo::relocPointsToGot(uint32_t Type) const {
+  return Type == R_386_GOTPC;
+}
+
 bool X86TargetInfo::relocNeedsPlt(uint32_t Type) const {
   switch (Type) {
   default:

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=248793&r1=248792&r2=248793&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Tue Sep 29 08:36:32 2015
@@ -26,6 +26,7 @@ public:
   virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
                              uint64_t PltEntryAddr) const = 0;
   virtual bool relocNeedsGot(uint32_t Type) const = 0;
+  virtual bool relocPointsToGot(uint32_t Type) const;
   virtual bool relocNeedsPlt(uint32_t Type) const = 0;
   virtual void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
                            uint64_t BaseAddr, uint64_t SymVA) const = 0;
@@ -44,6 +45,7 @@ public:
   void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
                      uint64_t PltEntryAddr) const override;
   bool relocNeedsGot(uint32_t Type) const override;
+  bool relocPointsToGot(uint32_t Type) const override;
   bool relocNeedsPlt(uint32_t Type) const override;
   void relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
                    uint64_t BaseAddr, uint64_t SymVA) const override;

Modified: lld/trunk/test/elf2/relocation-i686.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relocation-i686.s?rev=248793&r1=248792&r2=248793&view=diff
==============================================================================
--- lld/trunk/test/elf2/relocation-i686.s (original)
+++ lld/trunk/test/elf2/relocation-i686.s Tue Sep 29 08:36:32 2015
@@ -1,5 +1,8 @@
 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t
-// RUN: lld -flavor gnu2 %t -o %t2
+// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o
+// RUN: lld -flavor gnu2 -shared %t2.o -o %t2.so
+// RUN: lld -flavor gnu2 %t %t2.so -o %t2
+// RUN: llvm-readobj -s %t2 | FileCheck --check-prefix=ADDR %s
 // RUN: llvm-objdump -d %t2 | FileCheck %s
 // REQUIRES: x86
 
@@ -32,3 +35,25 @@ R_386_PC32_2:
 
 // CHECK:      R_386_PC32_2:
 // CHECK-NEXT:   1100e:  90  nop
+
+// Create a .got
+movl bar at GOT, %eax
+
+
+// ADDR:      Name: .got (14)
+// ADDR-NEXT: Type: SHT_PROGBITS
+// ADDR-NEXT: Flags [
+// ADDR-NEXT:   SHF_ALLOC
+// ADDR-NEXT:   SHF_WRITE
+// ADDR-NEXT: ]
+// ADDR-NEXT: Address: 0x15000
+
+.section .R_386_GOTPC,"ax", at progbits
+R_386_GOTPC:
+ movl $_GLOBAL_OFFSET_TABLE_, %eax
+
+// 0x15000 - 0x11014 = 16364
+
+// CHECK:      Disassembly of section .R_386_GOTPC:
+// CHECK-NEXT: R_386_GOTPC:
+// CHECK-NEXT:   11014:  {{.*}} movl  $16364, %eax




More information about the llvm-commits mailing list