[lld] MIPS relocations in KSEG0

Martin Pelikán via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 07:05:05 PDT 2016


The high bit in Val gets sign-extended, which then clobbers the
J-instruction opcode in its top 6 bits.

--- a/ELF/Target.cpp
+++ b/ELF/Target.cpp
@@ -1979,7 +1979,7 @@ void MipsTargetInfo<ELFT>::relocateOne(uint8_t
*Loc, uint32_t Type,
     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 & 0x3ffffff) >> 2));
     break;
   case R_MIPS_GOT_DISP:
   case R_MIPS_GOT_PAGE:


More information about the llvm-commits mailing list