[lld] r255451 - [ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 12 22:49:02 PST 2015


Author: atanasyan
Date: Sun Dec 13 00:49:01 2015
New Revision: 255451

URL: http://llvm.org/viewvc/llvm-project?rev=255451&view=rev
Log:
[ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/test/ELF/mips-hilo.s

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=255451&r1=255450&r2=255451&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Sun Dec 13 00:49:01 2015
@@ -1287,6 +1287,8 @@ bool MipsTargetInfo<ELFT>::relocNeedsPlt
   return false;
 }
 
+static uint16_t mipsHigh(uint64_t V) { return ((V + 0x8000) >> 16) & 0xffff; }
+
 template <class ELFT>
 void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
                                        uint32_t Type, uint64_t P, uint64_t SA,
@@ -1309,10 +1311,10 @@ void MipsTargetInfo<ELFT>::relocateOne(u
     if (PairedLoc) {
       uint64_t AHL = ((Instr & 0xffff) << 16) +
                      SignExtend64<16>(read32<E>(PairedLoc) & 0xffff);
-      write32<E>(Loc, (Instr & 0xffff0000) | (((SA + AHL) >> 16) & 0xffff));
+      write32<E>(Loc, (Instr & 0xffff0000) | mipsHigh(SA + AHL));
     } else {
       warning("Can't find matching R_MIPS_LO16 relocation for R_MIPS_HI16");
-      write32<E>(Loc, (Instr & 0xffff0000) | ((SA >> 16) & 0xffff));
+      write32<E>(Loc, (Instr & 0xffff0000) | mipsHigh(SA));
     }
     break;
   }

Modified: lld/trunk/test/ELF/mips-hilo.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo.s?rev=255451&r1=255450&r2=255451&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-hilo.s (original)
+++ lld/trunk/test/ELF/mips-hilo.s Sun Dec 13 00:49:01 2015
@@ -40,9 +40,9 @@ g1:
 #                                                    ^-- %lo(__start+4)
 # CHECK-NEXT:  2000c:   21 08 00 0c   addi   $8, $8, 12
 #                                                    ^-- %lo(g1+8)
-# CHECK-NEXT:  20010:   3c 08 00 03   lui    $8, 3
+# CHECK-NEXT:  20010:   3c 08 00 04   lui    $8, 4
 #                                                ^-- %hi(l1+0x10000-4)
-# CHECK-NEXT:  20014:   3c 09 00 04   lui    $9, 4
+# CHECK-NEXT:  20014:   3c 09 00 05   lui    $9, 5
 #                                                ^-- %hi(l1+0x20000-4)
 # CHECK-NEXT:  20018:   21 08 ff fc   addi   $8, $8, -4
 #                                                    ^-- %lo(l1-4)




More information about the llvm-commits mailing list