[lld] r276395 - [ELF][MIPS] Apply mask while reading implicit addend and writing result of R_MIPS_26 relocation.

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 22:56:43 PDT 2016


Author: atanasyan
Date: Fri Jul 22 00:56:43 2016
New Revision: 276395

URL: http://llvm.org/viewvc/llvm-project?rev=276395&view=rev
Log:
[ELF][MIPS] Apply mask while reading implicit addend and writing result of R_MIPS_26 relocation.

Added:
    lld/trunk/test/ELF/mips-26-mask.s
Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=276395&r1=276394&r2=276395&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Jul 22 00:56:43 2016
@@ -2040,7 +2040,7 @@ uint64_t MipsTargetInfo<ELFT>::getImplic
     // FIXME (simon): If the relocation target symbol is not a PLT entry
     // we should use another expression for calculation:
     // ((A << 2) | (P & 0xf0000000)) >> 2
-    return SignExtend64<28>(read32<E>(Buf) << 2);
+    return SignExtend64<28>((read32<E>(Buf) & 0x3ffffff) << 2);
   case R_MIPS_GPREL16:
   case R_MIPS_LO16:
   case R_MIPS_PCLO16:
@@ -2109,7 +2109,7 @@ void MipsTargetInfo<ELFT>::relocateOne(u
     write64<E>(Loc, Val);
     break;
   case R_MIPS_26:
-    write32<E>(Loc, (read32<E>(Loc) & ~0x3ffffff) | (Val >> 2));
+    write32<E>(Loc, (read32<E>(Loc) & ~0x3ffffff) | ((Val >> 2) & 0x3ffffff));
     break;
   case R_MIPS_GOT_DISP:
   case R_MIPS_GOT_PAGE:

Added: lld/trunk/test/ELF/mips-26-mask.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-26-mask.s?rev=276395&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-26-mask.s (added)
+++ lld/trunk/test/ELF/mips-26-mask.s Fri Jul 22 00:56:43 2016
@@ -0,0 +1,16 @@
+# Check reading/writing implicit addend for R_MIPS_26 relocation.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK:      Disassembly of section .text:
+# CHECK:      __start:
+# CHECK-NEXT:   20000:       0e 00 80 00     jal     134348800
+
+  .text
+  .global __start
+__start:
+  jal __start+0x8000000




More information about the llvm-commits mailing list