[lld] r327536 - Reduce code duplication a bit.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 14 10:41:34 PDT 2018
Author: rafael
Date: Wed Mar 14 10:41:34 2018
New Revision: 327536
URL: http://llvm.org/viewvc/llvm-project?rev=327536&view=rev
Log:
Reduce code duplication a bit.
The code for computing the offset of an entry in the plt is simple,
but it was duplicated in quite a few places.
Modified:
lld/trunk/ELF/Arch/SPARCV9.cpp
lld/trunk/ELF/Arch/X86.cpp
lld/trunk/ELF/Arch/X86_64.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Target.h
Modified: lld/trunk/ELF/Arch/SPARCV9.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/SPARCV9.cpp?rev=327536&r1=327535&r2=327536&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/SPARCV9.cpp (original)
+++ lld/trunk/ELF/Arch/SPARCV9.cpp Wed Mar 14 10:41:34 2018
@@ -137,7 +137,7 @@ void SPARCV9::writePlt(uint8_t *Buf, uin
};
memcpy(Buf, PltData, sizeof(PltData));
- uint64_t Off = PltHeaderSize + Index * PltEntrySize;
+ uint64_t Off = getPltEntryOffset(Index);
relocateOne(Buf, R_SPARC_22, Off);
relocateOne(Buf + 4, R_SPARC_WDISP19, -(Off + 4 - PltEntrySize));
}
Modified: lld/trunk/ELF/Arch/X86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86.cpp?rev=327536&r1=327535&r2=327536&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86.cpp (original)
+++ lld/trunk/ELF/Arch/X86.cpp Wed Mar 14 10:41:34 2018
@@ -223,7 +223,7 @@ void X86::writePlt(uint8_t *Buf, uint64_
}
write32le(Buf + 7, RelOff);
- write32le(Buf + 12, -Index * PltEntrySize - PltHeaderSize - 16);
+ write32le(Buf + 12, -getPltEntryOffset(Index) - 16);
}
int64_t X86::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
@@ -466,11 +466,12 @@ void RetpolinePic::writePlt(uint8_t *Buf
memcpy(Buf, Insn, sizeof(Insn));
uint32_t Ebx = InX::Got->getVA() + InX::Got->getSize();
+ unsigned Off = getPltEntryOffset(Index);
write32le(Buf + 3, GotPltEntryAddr - Ebx);
- write32le(Buf + 8, -Index * PltEntrySize - PltHeaderSize - 12 + 32);
- write32le(Buf + 13, -Index * PltEntrySize - PltHeaderSize - 17 + 18);
+ write32le(Buf + 8, -Off - 12 + 32);
+ write32le(Buf + 13, -Off - 17 + 18);
write32le(Buf + 18, RelOff);
- write32le(Buf + 23, -Index * PltEntrySize - PltHeaderSize - 27);
+ write32le(Buf + 23, -Off - 27);
}
RetpolineNoPic::RetpolineNoPic() {
@@ -520,11 +521,12 @@ void RetpolineNoPic::writePlt(uint8_t *B
};
memcpy(Buf, Insn, sizeof(Insn));
+ unsigned Off = getPltEntryOffset(Index);
write32le(Buf + 2, GotPltEntryAddr);
- write32le(Buf + 7, -Index * PltEntrySize - PltHeaderSize - 11 + 32);
- write32le(Buf + 12, -Index * PltEntrySize - PltHeaderSize - 16 + 17);
+ write32le(Buf + 7, -Off - 11 + 32);
+ write32le(Buf + 12, -Off - 16 + 17);
write32le(Buf + 17, RelOff);
- write32le(Buf + 22, -Index * PltEntrySize - PltHeaderSize - 26);
+ write32le(Buf + 22, -Off - 26);
}
TargetInfo *elf::getX86TargetInfo() {
Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=327536&r1=327535&r2=327536&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Wed Mar 14 10:41:34 2018
@@ -152,7 +152,7 @@ void X86_64<ELFT>::writePlt(uint8_t *Buf
write32le(Buf + 2, GotPltEntryAddr - PltEntryAddr - 6);
write32le(Buf + 7, Index);
- write32le(Buf + 12, -Index * PltEntrySize - PltHeaderSize - 16);
+ write32le(Buf + 12, -getPltEntryOffset(Index) - 16);
}
template <class ELFT> bool X86_64<ELFT>::isPicRel(RelType Type) const {
@@ -522,7 +522,7 @@ void Retpoline<ELFT>::writePlt(uint8_t *
};
memcpy(Buf, Insn, sizeof(Insn));
- uint64_t Off = TargetInfo::PltHeaderSize + TargetInfo::PltEntrySize * Index;
+ uint64_t Off = TargetInfo::getPltEntryOffset(Index);
write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7);
write32le(Buf + 8, -Off - 12 + 32);
@@ -561,8 +561,7 @@ void RetpolineZNow<ELFT>::writePlt(uint8
memcpy(Buf, Insn, sizeof(Insn));
write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7);
- write32le(Buf + 8,
- -Index * TargetInfo::PltEntrySize - TargetInfo::PltHeaderSize - 12);
+ write32le(Buf + 8, -TargetInfo::getPltEntryOffset(Index) - 12);
}
template <class ELFT> TargetInfo *getTargetInfo() {
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=327536&r1=327535&r2=327536&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Mar 14 10:41:34 2018
@@ -139,8 +139,7 @@ uint64_t Symbol::getGotPltOffset() const
uint64_t Symbol::getPltVA() const {
if (this->IsInIplt)
return InX::Iplt->getVA() + PltIndex * Target->PltEntrySize;
- return InX::Plt->getVA() + Target->PltHeaderSize +
- PltIndex * Target->PltEntrySize;
+ return InX::Plt->getVA() + Target->getPltEntryOffset(PltIndex);
}
uint64_t Symbol::getSize() const {
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=327536&r1=327535&r2=327536&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Mar 14 10:41:34 2018
@@ -43,6 +43,10 @@ public:
virtual void addPltHeaderSymbols(InputSection &IS) const {}
virtual void addPltSymbols(InputSection &IS, uint64_t Off) const {}
+ unsigned getPltEntryOffset(unsigned Index) const {
+ return Index * PltEntrySize + PltHeaderSize;
+ }
+
// Returns true if a relocation only uses the low bits of a value such that
// all those bits are in in the same page. For example, if the relocation
// only uses the low 12 bits in a system with 4k pages. If this is true, the
More information about the llvm-commits
mailing list