[lld] r264802 - Simplify AHL handling.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 29 16:05:59 PDT 2016
Author: rafael
Date: Tue Mar 29 18:05:59 2016
New Revision: 264802
URL: http://llvm.org/viewvc/llvm-project?rev=264802&view=rev
Log:
Simplify AHL handling.
This simplifies a few things
* Read the value as early as possible, instead of passing a pointer to
the location.
* Print the warning for missing pair close to where we find out it is
missing.
* Don't pass the value to relocateOne.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Target.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=264802&r1=264801&r2=264802&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Mar 29 18:05:59 2016
@@ -143,13 +143,17 @@ static uint32_t getMipsPairType(const Re
}
}
+template <endianness E> static int16_t readSignedLo16(uint8_t *Loc) {
+ return read32<E>(Loc) & 0xffff;
+}
+
template <class ELFT>
template <class RelTy>
-uint8_t *InputSectionBase<ELFT>::findMipsPairedReloc(uint8_t *Buf,
- const RelTy *Rel,
- const RelTy *End) {
+int32_t
+InputSectionBase<ELFT>::findMipsPairedAddend(uint8_t *Buf, uint8_t *BufLoc,
+ SymbolBody &Sym, const RelTy *Rel,
+ const RelTy *End) {
uint32_t SymIndex = Rel->getSymbol(Config->Mips64EL);
- SymbolBody &Sym = File->getSymbolBody(SymIndex).repl();
uint32_t Type = getMipsPairType(Rel, Sym);
// Some MIPS relocations use addend calculated from addend of the relocation
@@ -157,7 +161,7 @@ uint8_t *InputSectionBase<ELFT>::findMip
// combined addend in case of REL relocation record format only.
// See p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
if (RelTy::IsRela || Type == R_MIPS_NONE)
- return nullptr;
+ return 0;
for (const RelTy *RI = Rel; RI != End; ++RI) {
if (RI->getType(Config->Mips64EL) != Type)
@@ -166,10 +170,16 @@ uint8_t *InputSectionBase<ELFT>::findMip
continue;
uintX_t Offset = getOffset(RI->r_offset);
if (Offset == (uintX_t)-1)
- return nullptr;
- return Buf + Offset;
+ break;
+ const endianness E = ELFT::TargetEndianness;
+ return ((read32<E>(BufLoc) & 0xffff) << 16) +
+ readSignedLo16<E>(Buf + Offset);
}
- return nullptr;
+ unsigned OldType = Rel->getType(Config->Mips64EL);
+ StringRef OldName = getELFRelocationTypeName(Config->EMachine, OldType);
+ StringRef NewName = getELFRelocationTypeName(Config->EMachine, Type);
+ warning("can't find matching " + NewName + " relocation for " + OldName);
+ return 0;
}
template <class ELFT, class uintX_t>
@@ -192,19 +202,14 @@ static uintX_t adjustMipsSymVA(uint32_t
template <class ELFT, class uintX_t>
static uintX_t getMipsGotVA(const SymbolBody &Body, uintX_t SymVA,
- uint8_t *BufLoc, uint8_t *PairedLoc) {
- if (Body.isLocal()) {
+ uint8_t *BufLoc, uint64_t AHL) {
+ if (Body.isLocal())
// If relocation against MIPS local symbol requires GOT entry, this entry
// should be initialized by 'page address'. This address is high 16-bits
// of sum the symbol's value and the addend. The addend in that case is
// calculated using addends from R_MIPS_GOT16 and paired R_MIPS_LO16
// relocations.
- const endianness E = ELFT::TargetEndianness;
- uint64_t AHL = read32<E>(BufLoc) << 16;
- if (PairedLoc)
- AHL += SignExtend64<16>(read32<E>(PairedLoc));
return Out<ELFT>::Got->getMipsLocalPageAddr(SymVA + AHL);
- }
if (!Body.isPreemptible())
// For non-local symbols GOT entries should contain their full
// addresses. But if such symbol cannot be preempted, we do not
@@ -270,15 +275,14 @@ void InputSectionBase<ELFT>::relocate(ui
}
uintX_t SymVA = Body.getVA<ELFT>(A);
- uint8_t *PairedLoc = nullptr;
if (Config->EMachine == EM_MIPS)
- PairedLoc = findMipsPairedReloc(Buf, &RI, Rels.end());
+ A += findMipsPairedAddend(Buf, BufLoc, Body, &RI, Rels.end());
if (Target->needsPlt(Type, Body)) {
SymVA = Body.getPltVA<ELFT>() + A;
} else if (Target->needsGot(Type, Body)) {
if (Config->EMachine == EM_MIPS)
- SymVA = getMipsGotVA<ELFT>(Body, SymVA, BufLoc, PairedLoc) + A;
+ SymVA = getMipsGotVA<ELFT>(Body, SymVA, BufLoc, A);
else
SymVA = Body.getGotVA<ELFT>() + A;
if (Body.IsTls)
@@ -296,8 +300,7 @@ void InputSectionBase<ELFT>::relocate(ui
continue;
}
uintX_t Size = Body.getSize<ELFT>();
- Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, SymVA, Size + A,
- PairedLoc);
+ Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, SymVA, Size + A);
}
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=264802&r1=264801&r2=264802&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Mar 29 18:05:59 2016
@@ -81,8 +81,8 @@ public:
private:
template <class RelTy>
- uint8_t *findMipsPairedReloc(uint8_t *Buf, const RelTy *Rel,
- const RelTy *End);
+ int32_t findMipsPairedAddend(uint8_t *Buf, uint8_t *BufLoc, SymbolBody &Sym,
+ const RelTy *Rel, const RelTy *End);
};
template <class ELFT>
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=264802&r1=264801&r2=264802&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Mar 29 18:05:59 2016
@@ -91,8 +91,7 @@ public:
bool needsGot(uint32_t Type, SymbolBody &S) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA = 0) const override;
size_t relaxTlsGdToIe(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
uint64_t P, uint64_t SA) const override;
@@ -126,8 +125,7 @@ public:
bool refersToGotEntry(uint32_t Type) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA = 0) const override;
bool isRelRelative(uint32_t Type) const override;
bool isSizeRel(uint32_t Type) const override;
@@ -145,8 +143,7 @@ class PPCTargetInfo final : public Targe
public:
PPCTargetInfo();
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA) const override;
bool isRelRelative(uint32_t Type) const override;
};
@@ -158,8 +155,7 @@ public:
bool needsGot(uint32_t Type, SymbolBody &S) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA) const override;
bool isRelRelative(uint32_t Type) const override;
};
@@ -179,9 +175,7 @@ public:
bool needsGot(uint32_t Type, SymbolBody &S) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
-
+ uint64_t SA, uint64_t ZA = 0) const override;
size_t relaxTlsGdToLe(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
uint64_t P, uint64_t SA) const override;
size_t relaxTlsIeToLe(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
@@ -195,8 +189,7 @@ class AMDGPUTargetInfo final : public Ta
public:
AMDGPUTargetInfo() {}
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA) const override;
};
template <class ELFT> class MipsTargetInfo final : public TargetInfo {
@@ -212,8 +205,7 @@ public:
bool needsGot(uint32_t Type, SymbolBody &S) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
- uint64_t S, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const override;
+ uint64_t SA, uint64_t ZA) const override;
bool isHintRel(uint32_t Type) const override;
bool isRelRelative(uint32_t Type) const override;
bool refersToGotEntry(uint32_t Type) const override;
@@ -518,8 +510,7 @@ bool X86TargetInfo::refersToGotEntry(uin
}
void X86TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA,
- uint8_t *PairedLoc) const {
+ uint64_t P, uint64_t SA, uint64_t ZA) const {
switch (Type) {
case R_386_32:
add32le(Loc, SA);
@@ -935,8 +926,7 @@ size_t X86_64TargetInfo::relaxTlsLdToLe(
}
void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA,
- uint8_t *PairedLoc) const {
+ uint64_t P, uint64_t SA, uint64_t ZA) const {
switch (Type) {
case R_X86_64_32:
checkUInt<32>(SA, Type);
@@ -995,8 +985,7 @@ PPCTargetInfo::PPCTargetInfo() {}
bool PPCTargetInfo::isRelRelative(uint32_t Type) const { return false; }
void PPCTargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA,
- uint8_t *PairedLoc) const {
+ uint64_t P, uint64_t SA, uint64_t ZA) const {
switch (Type) {
case R_PPC_ADDR16_HA:
write16be(Loc, applyPPCHa(SA));
@@ -1099,8 +1088,7 @@ bool PPC64TargetInfo::isRelRelative(uint
}
void PPC64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA,
- uint8_t *PairedLoc) const {
+ uint64_t P, uint64_t SA, uint64_t ZA) const {
uint64_t TB = getPPC64TocBase();
// For a TOC-relative relocation, adjust the addend and proceed in terms of
@@ -1391,7 +1379,7 @@ static uint64_t getAArch64Page(uint64_t
void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
uint32_t Type, uint64_t P, uint64_t SA,
- uint64_t ZA, uint8_t *PairedLoc) const {
+ uint64_t ZA) const {
switch (Type) {
case R_AARCH64_ABS16:
checkIntUInt<16>(SA, Type);
@@ -1566,8 +1554,7 @@ size_t AArch64TargetInfo::relaxTlsIeToLe
// actually called (relocateOne is called for each relocation).
// That's why the AMDGPU port works without implementing this function.
void AMDGPUTargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA,
- uint8_t *PairedLoc) const {
+ uint64_t P, uint64_t SA, uint64_t ZA) const {
llvm_unreachable("not implemented");
}
@@ -1653,11 +1640,6 @@ template <endianness E> static int16_t r
return SignExtend32<16>(read32<E>(Loc) & 0xffff);
}
-template <endianness E>
-static int64_t readMipsAHL(uint8_t *HiLoc, uint8_t *LoLoc) {
- return ((read32<E>(HiLoc) & 0xffff) << 16) + readSignedLo16<E>(LoLoc);
-}
-
template <class ELFT>
void MipsTargetInfo<ELFT>::writePltZero(uint8_t *Buf) const {
const endianness E = ELFT::TargetEndianness;
@@ -1712,7 +1694,7 @@ bool MipsTargetInfo<ELFT>::needsPltImpl(
template <class ELFT>
void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
uint32_t Type, uint64_t P, uint64_t S,
- uint64_t ZA, uint8_t *PairedLoc) const {
+ uint64_t ZA) const {
const endianness E = ELFT::TargetEndianness;
// Thread pointer and DRP offsets from the start of TLS data area.
// https://www.linux-mips.org/wiki/NPTL
@@ -1749,12 +1731,7 @@ void MipsTargetInfo<ELFT>::relocateOne(u
write32<E>(Loc, S + int32_t(read32<E>(Loc)) - getMipsGpAddr<ELFT>());
break;
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);
- }
+ writeMipsHi16<E>(Loc, S);
break;
case R_MIPS_JALR:
// Ignore this optimization relocation for now
@@ -1778,12 +1755,7 @@ void MipsTargetInfo<ELFT>::relocateOne(u
applyMipsPcReloc<E, 32, 0>(Loc, Type, P, S);
break;
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);
- }
+ writeMipsHi16<E>(Loc, S - P);
break;
case R_MIPS_PCLO16:
writeMipsLo16<E>(Loc, S + readSignedLo16<E>(Loc) - P);
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=264802&r1=264801&r2=264802&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Tue Mar 29 18:05:59 2016
@@ -62,8 +62,7 @@ public:
PltNeed needsPlt(uint32_t Type, const SymbolBody &S) const;
virtual void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
- uint64_t P, uint64_t SA, uint64_t ZA = 0,
- uint8_t *PairedLoc = nullptr) const = 0;
+ uint64_t P, uint64_t SA, uint64_t ZA = 0) const = 0;
virtual bool isGotRelative(uint32_t Type) const;
bool canRelaxTls(uint32_t Type, const SymbolBody *S) const;
template <class ELFT>
More information about the llvm-commits
mailing list