summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2016-03-04 10:55:20 +0000
committerSimon Atanasyan <simon@atanasyan.com>2016-03-04 10:55:20 +0000
commit3b37785feec6d7653c6c309fe78d455f16765fe8 (patch)
treeee827fa24b9f23faa96dd36fca339c4058b68e66
parentdeed55d70600deac8e5df186325ef3aba5a82249 (diff)
downloadbcm5719-llvm-3b37785feec6d7653c6c309fe78d455f16765fe8.tar.gz
bcm5719-llvm-3b37785feec6d7653c6c309fe78d455f16765fe8.zip
[ELF][MIPS] Factor out the code reading and calculating AHL addend into the separate function. NFC
llvm-svn: 262706
-rw-r--r--lld/ELF/Target.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 2418644cf04..a955657d553 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -1646,6 +1646,12 @@ static void writeMipsHi16(uint8_t *Loc, uint64_t V) {
write32<E>(Loc, (Instr & 0xffff0000) | mipsHigh(V));
}
+template <endianness E>
+static int64_t readMipsAHL(uint8_t *HiLoc, uint8_t *LoLoc) {
+ return ((read32<E>(HiLoc) & 0xffff) << 16) +
+ SignExtend64<16>(read32<E>(LoLoc) & 0xffff);
+}
+
template <class ELFT>
void MipsTargetInfo<ELFT>::writePltZero(uint8_t *Buf) const {
const endianness E = ELFT::TargetEndianness;
@@ -1734,18 +1740,14 @@ void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
case R_MIPS_GPREL32:
write32<E>(Loc, S + int32_t(read32<E>(Loc)) - getMipsGpAddr<ELFT>());
break;
- case R_MIPS_HI16: {
- uint32_t Instr = read32<E>(Loc);
- if (PairedLoc) {
- uint64_t AHL = ((Instr & 0xffff) << 16) +
- SignExtend64<16>(read32<E>(PairedLoc) & 0xffff);
- writeMipsHi16<E>(Loc, S + AHL);
- } else {
+ case R_MIPS_HI16:
+ if (PairedLoc)
+ writeMipsHi16<E>(Loc, S + readMipsAHL<E>(Loc, PairedLoc));
+ else {
warning("Can't find matching R_MIPS_LO16 relocation for R_MIPS_HI16");
writeMipsHi16<E>(Loc, S);
}
break;
- }
case R_MIPS_JALR:
// Ignore this optimization relocation for now
break;
@@ -1770,17 +1772,14 @@ void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
case R_MIPS_PC32:
applyMipsPcReloc<E, 32, 0>(Loc, Type, P, S);
break;
- case R_MIPS_PCHI16: {
- if (PairedLoc) {
- uint64_t AHL = ((read32<E>(Loc) & 0xffff) << 16) +
- SignExtend64<16>(read32<E>(PairedLoc) & 0xffff);
- writeMipsHi16<E>(Loc, S + AHL - P);
- } else {
+ case R_MIPS_PCHI16:
+ if (PairedLoc)
+ writeMipsHi16<E>(Loc, S + readMipsAHL<E>(Loc, PairedLoc) - P);
+ else {
warning("Can't find matching R_MIPS_PCLO16 relocation for R_MIPS_PCHI16");
writeMipsHi16<E>(Loc, S - P);
}
break;
- }
case R_MIPS_PCLO16: {
uint32_t Instr = read32<E>(Loc);
int64_t AHL = SignExtend64<16>(Instr & 0xffff);
OpenPOWER on IntegriCloud