[lld] r343784 - [ELF][HEXAGON] Add support for GOT relocations.

Sid Manning via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 07:54:18 PDT 2018


Author: sidneym
Date: Thu Oct  4 07:54:17 2018
New Revision: 343784

URL: http://llvm.org/viewvc/llvm-project?rev=343784&view=rev
Log:
[ELF][HEXAGON] Add support for GOT relocations.

The GOT is referenced through the symbol _GLOBAL_OFFSET_TABLE_ .

The relocation added calculates the offset into the global offset table for
the entry of a symbol.  In order to get the correct TargetVA I needed to
create an new relocation expression, HEXAGON_GOT.  It does
Sym.getGotVA() - In.GotPlt->getVA().

Differential Revision: https://reviews.llvm.org/D52744

Modified:
    lld/trunk/ELF/Arch/Hexagon.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Relocations.h
    lld/trunk/test/ELF/hexagon-shared.s

Modified: lld/trunk/ELF/Arch/Hexagon.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Hexagon.cpp?rev=343784&r1=343783&r2=343784&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Hexagon.cpp (original)
+++ lld/trunk/ELF/Arch/Hexagon.cpp Thu Oct  4 07:54:17 2018
@@ -40,6 +40,13 @@ public:
 Hexagon::Hexagon() {
   PltRel = R_HEX_JMP_SLOT;
   RelativeRel = R_HEX_RELATIVE;
+  GotRel = R_HEX_GLOB_DAT;
+  GotEntrySize = 4;
+  // The zero'th GOT entry is reserved for the address of _DYNAMIC.  The
+  // next 3 are reserved for the dynamic loader.
+  GotPltHeaderEntriesNum = 4;
+  GotPltEntrySize = 4;
+
   PltEntrySize = 16;
   PltHeaderSize = 32;
 
@@ -82,6 +89,9 @@ RelExpr Hexagon::getRelExpr(RelType Type
   case R_HEX_B22_PCREL_X:
   case R_HEX_B32_PCREL_X:
     return R_PLT_PC;
+  case R_HEX_GOT_11_X:
+  case R_HEX_GOT_32_6_X:
+    return R_HEXAGON_GOT;
   default:
     return R_ABS;
   }
@@ -175,6 +185,7 @@ void Hexagon::relocateOne(uint8_t *Loc,
     or32le(Loc, applyMask(0x00203fe0, Val & 0x3f));
     break;
   case R_HEX_11_X:
+  case R_HEX_GOT_11_X:
     or32le(Loc, applyMask(findMaskR11(read32le(Loc)), Val & 0x3f));
     break;
   case R_HEX_12_X:
@@ -188,6 +199,7 @@ void Hexagon::relocateOne(uint8_t *Loc,
     or32le(Loc, Val);
     break;
   case R_HEX_32_6_X:
+  case R_HEX_GOT_32_6_X:
     or32le(Loc, applyMask(0x0fff3fff, Val >> 6));
     break;
   case R_HEX_B9_PCREL:

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=343784&r1=343783&r2=343784&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Oct  4 07:54:17 2018
@@ -545,6 +545,8 @@ static uint64_t getRelocTargetVA(const I
   case R_GOT_PC:
   case R_RELAX_TLS_GD_TO_IE:
     return Sym.getGotVA() + A - P;
+  case R_HEXAGON_GOT:
+    return Sym.getGotVA() - In.GotPlt->getVA();
   case R_MIPS_GOTREL:
     return Sym.getVA(A) - In.MipsGot->getGp(File);
   case R_MIPS_GOT_GP:

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=343784&r1=343783&r2=343784&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Oct  4 07:54:17 2018
@@ -331,9 +331,9 @@ static bool needsPlt(RelExpr Expr) {
 // returns false for TLS variables even though they need GOT, because
 // TLS variables uses GOT differently than the regular variables.
 static bool needsGot(RelExpr Expr) {
-  return isRelExprOneOf<R_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF,
-                        R_MIPS_GOT_OFF32, R_GOT_PAGE_PC, R_GOT_PC,
-                        R_GOT_FROM_END>(Expr);
+  return isRelExprOneOf<R_GOT, R_GOT_OFF, R_HEXAGON_GOT, R_MIPS_GOT_LOCAL_PAGE,
+                        R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_GOT_PAGE_PC,
+                        R_GOT_PC, R_GOT_FROM_END>(Expr);
 }
 
 // True if this expression is of the form Sym - X, where X is a position in the
@@ -357,12 +357,12 @@ static bool isStaticLinkTimeConstant(Rel
                                      InputSectionBase &S, uint64_t RelOff) {
   // These expressions always compute a constant
   if (isRelExprOneOf<
-          R_GOT_FROM_END, R_GOT_OFF, R_TLSLD_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
-          R_MIPS_GOTREL, R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC,
-          R_MIPS_TLSGD, R_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC,
-          R_GOTONLY_PC_FROM_END, R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOT_FROM_END,
-          R_TLSGD_PC, R_PPC_CALL_PLT, R_TLSDESC_CALL, R_TLSDESC_PAGE, R_HINT,
-          R_TLSLD_HINT, R_TLSIE_HINT>(E))
+          R_GOT_FROM_END, R_GOT_OFF, R_HEXAGON_GOT, R_TLSLD_GOT_OFF,
+          R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOTREL, R_MIPS_GOT_OFF,
+          R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC, R_MIPS_TLSGD, R_GOT_PAGE_PC,
+          R_GOT_PC, R_GOTONLY_PC, R_GOTONLY_PC_FROM_END, R_PLT_PC, R_TLSGD_GOT,
+          R_TLSGD_GOT_FROM_END, R_TLSGD_PC, R_PPC_CALL_PLT, R_TLSDESC_CALL,
+          R_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E))
     return true;
 
   // These never do, except if the entire file is position dependent or if

Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=343784&r1=343783&r2=343784&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Thu Oct  4 07:54:17 2018
@@ -43,6 +43,7 @@ enum RelExpr {
   R_GOT_OFF,
   R_GOT_PAGE_PC,
   R_GOT_PC,
+  R_HEXAGON_GOT,
   R_HINT,
   R_MIPS_GOTREL,
   R_MIPS_GOT_GP,

Modified: lld/trunk/test/ELF/hexagon-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/hexagon-shared.s?rev=343784&r1=343783&r2=343784&view=diff
==============================================================================
--- lld/trunk/test/ELF/hexagon-shared.s (original)
+++ lld/trunk/test/ELF/hexagon-shared.s Thu Oct  4 07:54:17 2018
@@ -3,19 +3,27 @@
 # RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %S/Inputs/hexagon-shared.s -o %t2.o
 # RUN: ld.lld -shared %t2.o -soname %t3.so -o %t3.so
 # RUN: ld.lld -shared %t %t3.so -soname %t4.so -o %t4.so
-# RUN: llvm-objdump -d -j=.plt %t4.so | FileCheck --check-prefix=PLT %s
-# RUN: llvm-objdump -d -j=.text %t4.so | FileCheck --check-prefix=TEXT %s
+# RUN: llvm-objdump -d -j .plt %t4.so | FileCheck --check-prefix=PLT %s
+# RUN: llvm-objdump -d -j .text %t4.so | FileCheck --check-prefix=TEXT %s
+# RUN: llvm-objdump -D -j .got %t4.so | FileCheck --check-prefix=GOT %s
 
 .global foo
 foo:
+
 # _HEX_32_PCREL
 .word _DYNAMIC - .
 call ##bar
+
 # R_HEX_PLT_B22_PCREL
 call bar at PLT
 
+# R_HEX_GOT_11_X and R_HEX_GOT_32_6_X
+r2=add(pc,##_GLOBAL_OFFSET_TABLE_ at PCREL)
+r0 = memw (r2+##bar at GOT)
+jumpr r0
+
 # PLT: { immext(#65472
-# PLT: r28 = add(pc,##65520) }
+# PLT: r28 = add(pc,##65488) }
 # PLT: { r14 -= add(r28,#16)
 # PLT: r15 = memw(r28+#8)
 # PLT: r28 = memw(r28+#4) }
@@ -23,9 +31,12 @@ call bar at PLT
 # PLT: jumpr r28 }
 # PLT: { trap0(#219) }
 # PLT: immext(#65472)
-# PLT: r14 = add(pc,##65488) }
+# PLT: r14 = add(pc,##65472) }
 # PLT: r28 = memw(r14+#0) }
 # PLT: jumpr r28 }
 
-# TEXT:  10000: 00 00 01 00 00010000
-# TEXT: { 	call 0x10030 }
+# TEXT:  10000: 00 00 02 00 00020000
+# TEXT: { 	call 0x10050 }
+
+# GOT: .got:
+# GOT: 30080:	00 00 00 00 00000000 <unknown>




More information about the llvm-commits mailing list