[lld] r280310 - Fix the implementation of R_386_GOTPC and R_386_GOTOFF.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 31 16:24:12 PDT 2016


Author: rafael
Date: Wed Aug 31 18:24:11 2016
New Revision: 280310

URL: http://llvm.org/viewvc/llvm-project?rev=280310&view=rev
Log:
Fix the implementation of R_386_GOTPC and R_386_GOTOFF.

They were both pointing to the start of the got, not the end.

Fixes pr28924.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=280310&r1=280309&r2=280310&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Aug 31 18:24:11 2016
@@ -223,6 +223,9 @@ static typename ELFT::uint getSymVA(uint
     return Body.getSize<ELFT>() + A;
   case R_GOTREL:
     return Body.getVA<ELFT>(A) - Out<ELFT>::Got->getVA();
+  case R_GOTREL_FROM_END:
+    return Body.getVA<ELFT>(A) - Out<ELFT>::Got->getVA() -
+           Out<ELFT>::Got->getSize();
   case R_RELAX_TLS_GD_TO_IE_END:
   case R_GOT_FROM_END:
     return Body.getGotOffset<ELFT>() + A - Out<ELFT>::Got->getSize();
@@ -237,6 +240,8 @@ static typename ELFT::uint getSymVA(uint
     return Body.getGotVA<ELFT>() + A - P;
   case R_GOTONLY_PC:
     return Out<ELFT>::Got->getVA() + A - P;
+  case R_GOTONLY_PC_FROM_END:
+    return Out<ELFT>::Got->getVA() + A - P + Out<ELFT>::Got->getSize();
   case R_RELAX_TLS_LD_TO_LE:
   case R_RELAX_TLS_IE_TO_LE:
   case R_RELAX_TLS_GD_TO_LE:

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=280310&r1=280309&r2=280310&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Aug 31 18:24:11 2016
@@ -574,7 +574,8 @@ static void scanRelocs(InputSectionBase<
 
     // This relocation does not require got entry, but it is relative to got and
     // needs it to be created. Here we request for that.
-    if (Expr == R_GOTONLY_PC || Expr == R_GOTREL || Expr == R_PPC_TOC)
+    if (Expr == R_GOTONLY_PC || Expr == R_GOTONLY_PC_FROM_END ||
+        Expr == R_GOTREL || Expr == R_GOTREL_FROM_END || Expr == R_PPC_TOC)
       Out<ELFT>::Got->HasGotOffRel = true;
 
     uintX_t Addend = computeAddend(File, Buf, E, RI, Expr, Body);

Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=280310&r1=280309&r2=280310&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Wed Aug 31 18:24:11 2016
@@ -22,7 +22,9 @@ enum RelExpr {
   R_ABS,
   R_GOT,
   R_GOTONLY_PC,
+  R_GOTONLY_PC_FROM_END,
   R_GOTREL,
+  R_GOTREL_FROM_END,
   R_GOT_FROM_END,
   R_GOT_OFF,
   R_GOT_PAGE_PC,

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=280310&r1=280309&r2=280310&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Aug 31 18:24:11 2016
@@ -328,7 +328,7 @@ RelExpr X86TargetInfo::getRelExpr(uint32
   case R_386_PC32:
     return R_PC;
   case R_386_GOTPC:
-    return R_GOTONLY_PC;
+    return R_GOTONLY_PC_FROM_END;
   case R_386_TLS_IE:
     return R_GOT;
   case R_386_GOT32:
@@ -336,7 +336,7 @@ RelExpr X86TargetInfo::getRelExpr(uint32
   case R_386_TLS_GOTIE:
     return R_GOT_FROM_END;
   case R_386_GOTOFF:
-    return R_GOTREL;
+    return R_GOTREL_FROM_END;
   case R_386_TLS_LE:
     return R_TLS;
   case R_386_TLS_LE_32:

Modified: lld/trunk/test/ELF/relocation-i686.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-i686.s?rev=280310&r1=280309&r2=280310&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-i686.s (original)
+++ lld/trunk/test/ELF/relocation-i686.s Wed Aug 31 18:24:11 2016
@@ -56,16 +56,18 @@ movl bar at GOT, %eax
 // ADDR-NEXT:   SHF_WRITE
 // ADDR-NEXT: ]
 // ADDR-NEXT: Address: 0x12078
+// ADDR-NEXT: Offset:
+// ADDR-NEXT: Size: 8
 
 .section .R_386_GOTPC,"ax", at progbits
 R_386_GOTPC:
  movl $_GLOBAL_OFFSET_TABLE_, %eax
 
-// 0x12050 - 0x11014 = 4156
+// 0x12078 + 8 - 0x11014 = 4204
 
 // CHECK:      Disassembly of section .R_386_GOTPC:
 // CHECK-NEXT: R_386_GOTPC:
-// CHECK-NEXT:   11014:  {{.*}} movl  $4196, %eax
+// CHECK-NEXT:   11014:  {{.*}} movl  $4204, %eax
 
 .section .dynamic_reloc, "ax", at progbits
  call bar




More information about the llvm-commits mailing list