[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.

llvm-svn: 311711
This commit is contained in:
Simon Atanasyan 2017-08-24 21:56:58 +00:00
parent 204cae99bb
commit c5455e237f
3 changed files with 6 additions and 5 deletions

View File

@ -259,6 +259,10 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, uint32_t Type) const {
// 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:

View File

@ -669,10 +669,7 @@ static int64_t computeMipsAddend(const RelTy &Rel, InputSectionBase &Sec,
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 " +

View File

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