[Mips] Pass type of relocation and addendum to the `calculateRelocation`

separately

This change reduce difference between the trunk and upcoming patch and
simplify the future code review.

No functional changes.

llvm-svn: 232919
This commit is contained in:
Simon Atanasyan 2015-03-22 16:35:08 +00:00
parent 15a6194b5d
commit 283629a0f7
1 changed files with 40 additions and 34 deletions

View File

@ -373,34 +373,36 @@ static uint32_t microShuffle(uint32_t ins) {
return ((ins & 0xffff) << 16) | ((ins & 0xffff0000) >> 16);
}
static ErrorOr<uint64_t> calculateRelocation(const Reference &ref,
static ErrorOr<uint64_t> calculateRelocation(Reference::KindValue kind,
Reference::Addend addend,
uint64_t tgtAddr, uint64_t relAddr,
uint64_t gpAddr, bool isGP) {
bool isCrossJump = getCrossJumpMode(ref) != CrossJumpMode::None;
switch (ref.kindValue()) {
uint64_t gpAddr, bool isGP,
CrossJumpMode jumpMode) {
bool isCrossJump = jumpMode != CrossJumpMode::None;
switch (kind) {
case R_MIPS_NONE:
return 0;
case R_MIPS_32:
return reloc32(tgtAddr, ref.addend());
return reloc32(tgtAddr, addend);
case R_MIPS_64:
return reloc64(tgtAddr, ref.addend());
return reloc64(tgtAddr, addend);
case R_MIPS_SUB:
return relocSub(tgtAddr, ref.addend());
return relocSub(tgtAddr, addend);
case R_MIPS_26:
return reloc26loc(relAddr, tgtAddr, ref.addend(), 2);
return reloc26loc(relAddr, tgtAddr, addend, 2);
case R_MICROMIPS_26_S1:
return reloc26loc(relAddr, tgtAddr, ref.addend(), isCrossJump ? 2 : 1);
return reloc26loc(relAddr, tgtAddr, addend, isCrossJump ? 2 : 1);
case R_MIPS_HI16:
case R_MICROMIPS_HI16:
return relocHi16(relAddr, tgtAddr, ref.addend(), isGP);
return relocHi16(relAddr, tgtAddr, addend, isGP);
case R_MIPS_PCHI16:
return relocPcHi16(relAddr, tgtAddr, ref.addend());
return relocPcHi16(relAddr, tgtAddr, addend);
case R_MIPS_LO16:
return relocLo16(relAddr, tgtAddr, ref.addend(), isGP, false);
return relocLo16(relAddr, tgtAddr, addend, isGP, false);
case R_MIPS_PCLO16:
return relocPcLo16(relAddr, tgtAddr, ref.addend());
return relocPcLo16(relAddr, tgtAddr, addend);
case R_MICROMIPS_LO16:
return relocLo16(relAddr, tgtAddr, ref.addend(), isGP, true);
return relocLo16(relAddr, tgtAddr, addend, isGP, true);
case R_MIPS_GOT16:
case R_MIPS_CALL16:
case R_MIPS_GOT_DISP:
@ -415,38 +417,38 @@ static ErrorOr<uint64_t> calculateRelocation(const Reference &ref,
case R_MICROMIPS_TLS_GOTTPREL:
return relocGOT(tgtAddr, gpAddr);
case R_MIPS_GOT_OFST:
return relocGOTOfst(tgtAddr, ref.addend());
return relocGOTOfst(tgtAddr, addend);
case R_MIPS_PC18_S3:
return relocPc18(relAddr, tgtAddr, ref.addend());
return relocPc18(relAddr, tgtAddr, addend);
case R_MIPS_PC19_S2:
return relocPc19(relAddr, tgtAddr, ref.addend());
return relocPc19(relAddr, tgtAddr, addend);
case R_MIPS_PC21_S2:
return relocPc21(relAddr, tgtAddr, ref.addend());
return relocPc21(relAddr, tgtAddr, addend);
case R_MIPS_PC26_S2:
return relocPc26(relAddr, tgtAddr, ref.addend());
return relocPc26(relAddr, tgtAddr, addend);
case R_MICROMIPS_PC7_S1:
return relocPc7(relAddr, tgtAddr, ref.addend());
return relocPc7(relAddr, tgtAddr, addend);
case R_MICROMIPS_PC10_S1:
return relocPc10(relAddr, tgtAddr, ref.addend());
return relocPc10(relAddr, tgtAddr, addend);
case R_MICROMIPS_PC16_S1:
return relocPc16(relAddr, tgtAddr, ref.addend());
return relocPc16(relAddr, tgtAddr, addend);
case R_MICROMIPS_PC23_S2:
return relocPc23(relAddr, tgtAddr, ref.addend());
return relocPc23(relAddr, tgtAddr, addend);
case R_MIPS_TLS_DTPREL_HI16:
case R_MIPS_TLS_TPREL_HI16:
case R_MICROMIPS_TLS_DTPREL_HI16:
case R_MICROMIPS_TLS_TPREL_HI16:
return relocHi16(0, tgtAddr, ref.addend(), false);
return relocHi16(0, tgtAddr, addend, false);
case R_MIPS_TLS_DTPREL_LO16:
case R_MIPS_TLS_TPREL_LO16:
return relocLo16(0, tgtAddr, ref.addend(), false, false);
return relocLo16(0, tgtAddr, addend, false, false);
case R_MICROMIPS_TLS_DTPREL_LO16:
case R_MICROMIPS_TLS_TPREL_LO16:
return relocLo16(0, tgtAddr, ref.addend(), false, true);
return relocLo16(0, tgtAddr, addend, false, true);
case R_MIPS_GPREL16:
return relocGPRel16(tgtAddr, ref.addend(), gpAddr);
return relocGPRel16(tgtAddr, addend, gpAddr);
case R_MIPS_GPREL32:
return relocGPRel32(tgtAddr, ref.addend(), gpAddr);
return relocGPRel32(tgtAddr, addend, gpAddr);
case R_MIPS_JALR:
case R_MICROMIPS_JALR:
// We do not do JALR optimization now.
@ -463,16 +465,16 @@ static ErrorOr<uint64_t> calculateRelocation(const Reference &ref,
// Ignore runtime relocations.
return 0;
case R_MIPS_PC32:
return relocpc32(relAddr, tgtAddr, ref.addend());
return relocpc32(relAddr, tgtAddr, addend);
case LLD_R_MIPS_GLOBAL_GOT:
// Do nothing.
case LLD_R_MIPS_32_HI16:
case LLD_R_MIPS_64_HI16:
return relocMaskLow16(tgtAddr, ref.addend());
return relocMaskLow16(tgtAddr, addend);
case LLD_R_MIPS_GLOBAL_26:
return reloc26ext(tgtAddr, ref.addend(), 2);
return reloc26ext(tgtAddr, addend, 2);
case LLD_R_MICROMIPS_GLOBAL_26_S1:
return reloc26ext(tgtAddr, ref.addend(), isCrossJump ? 2 : 1);
return reloc26ext(tgtAddr, addend, isCrossJump ? 2 : 1);
case LLD_R_MIPS_HI16:
return relocHi16(0, tgtAddr, 0, false);
case LLD_R_MIPS_LO16:
@ -546,14 +548,18 @@ std::error_code RelocationHandler<ELFT>::applyRelocation(
if (isMicroMipsAtom(ref.target()))
tgtAddr |= 1;
auto res = calculateRelocation(ref, tgtAddr, relAddr, gpAddr, isGpDisp);
CrossJumpMode jumpMode = getCrossJumpMode(ref);
ErrorOr<uint64_t> res =
calculateRelocation(ref.kindValue(), ref.addend(), tgtAddr, relAddr,
gpAddr, isGpDisp, jumpMode);
if (auto ec = res.getError())
return ec;
auto params = getRelocationParams(ref.kindValue());
uint64_t ins = relocRead<ELFT>(params, location);
if (auto ec = adjustJumpOpCode(ins, tgtAddr, getCrossJumpMode(ref)))
if (auto ec = adjustJumpOpCode(ins, tgtAddr, jumpMode))
return ec;
ins = (ins & ~params._mask) | (*res & params._mask);