[ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation

llvm-svn: 255451
This commit is contained in:
Simon Atanasyan 2015-12-13 06:49:01 +00:00
parent 84543b09cb
commit 2cd670da02
2 changed files with 6 additions and 4 deletions

View File

@ -1287,6 +1287,8 @@ bool MipsTargetInfo<ELFT>::relocNeedsPlt(uint32_t Type,
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(uint8_t *Loc, uint8_t *BufEnd,
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;
}

View File

@ -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)