[lld] r311711 - [MIPS] Keep all code read addends in the `getImplicitAddend` function

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 24 14:56:58 PDT 2017


Author: atanasyan
Date: Thu Aug 24 14:56:58 2017
New Revision: 311711

URL: http://llvm.org/viewvc/llvm-project?rev=311711&view=rev
Log:
[MIPS] Keep all code read addends in the `getImplicitAddend` function

Currently LLD reads the R_MIPS_HI16's addends in the `computeMipsAddend`
function, the R_MIPS_LO16's addends in both `computeMipsAddend` and
`getImplicitAddend` functions. This patch moves reading all addends to
the `getImplicitAddend` function. As a side effect it fixes a "paired"
HI16/LO16 addend calculation if "LO16" part of a pair is not found.

Modified:
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/test/ELF/mips-hilo-hi-only.s

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=311711&r1=311710&r2=311711&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Thu Aug 24 14:56:58 2017
@@ -259,6 +259,10 @@ int64_t MIPS<ELFT>::getImplicitAddend(co
     // we should use another expression for calculation:
     // ((A << 2) | (P & 0xf0000000)) >> 2
     return SignExtend64<28>(read32<E>(Buf) << 2);
+  case R_MIPS_GOT16:
+  case R_MIPS_HI16:
+  case R_MIPS_PCHI16:
+    return SignExtend64<16>(read32<E>(Buf)) << 16;
   case R_MIPS_GPREL16:
   case R_MIPS_LO16:
   case R_MIPS_PCLO16:

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=311711&r1=311710&r2=311711&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Aug 24 14:56:58 2017
@@ -669,10 +669,7 @@ static int64_t computeMipsAddend(const R
     if (RI->getSymbol(Config->IsMips64EL) != SymIndex)
       continue;
 
-    endianness E = Config->Endianness;
-    int32_t Hi = (read32(Buf + Rel.r_offset, E) & 0xffff) << 16;
-    int32_t Lo = SignExtend32<16>(read32(Buf + RI->r_offset, E));
-    return Hi + Lo;
+    return Target->getImplicitAddend(Buf + RI->r_offset, PairTy);
   }
 
   warn("can't find matching " + toString(PairTy) + " relocation for " +

Modified: lld/trunk/test/ELF/mips-hilo-hi-only.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo-hi-only.s?rev=311711&r1=311710&r2=311711&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-hilo-hi-only.s (original)
+++ lld/trunk/test/ELF/mips-hilo-hi-only.s Thu Aug 24 14:56:58 2017
@@ -18,7 +18,7 @@ _label:
 
 # CHECK:      Disassembly of section .text:
 # CHECK-NEXT: __start:
-# CHECK-NEXT:  20000:   3c 08 00 02   lui    $8, 2
+# CHECK-NEXT:  20000:   3c 08 00 03   lui    $8, 3
 #                                                ^-- %hi(__start) w/o addend
 # CHECK-NEXT   20004:   21 08 00 08   addi   $8, $8, 8
 #                                                    ^-- %lo(_label)




More information about the llvm-commits mailing list