[lld] r259154 - ELF: Do not pass addresses that can be obtained using Out.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 28 19:51:50 PST 2016
Author: ruiu
Date: Thu Jan 28 21:51:49 2016
New Revision: 259154
URL: http://llvm.org/viewvc/llvm-project?rev=259154&view=rev
Log:
ELF: Do not pass addresses that can be obtained using Out.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Target.h
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=259154&r1=259153&r2=259154&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Jan 28 21:51:49 2016
@@ -192,7 +192,7 @@ template <class ELFT> void PltSection<EL
bool LazyReloc = Target->UseLazyBinding;
if (LazyReloc) {
// First write PLT[0] entry which is special.
- Target->writePltZero(Buf, Out<ELFT>::GotPlt->getVA(), this->getVA());
+ Target->writePltZero(Buf);
Off += Target->PltZeroSize;
}
for (auto &I : Entries) {
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=259154&r1=259153&r2=259154&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Jan 28 21:51:49 2016
@@ -90,8 +90,7 @@ public:
unsigned getTlsGotRel(unsigned Type) const override;
bool isTlsDynRel(unsigned Type, const SymbolBody &S) const override;
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -124,8 +123,7 @@ public:
bool isTlsDynRel(unsigned Type, const SymbolBody &S) const override;
void writeGotPltHeader(uint8_t *Buf) const override;
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -156,8 +154,7 @@ class PPCTargetInfo final : public Targe
public:
PPCTargetInfo();
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -173,8 +170,7 @@ class PPC64TargetInfo final : public Tar
public:
PPC64TargetInfo();
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -191,8 +187,7 @@ public:
AArch64TargetInfo();
unsigned getDynRel(unsigned Type) const override;
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -210,8 +205,7 @@ class AMDGPUTargetInfo final : public Ta
public:
AMDGPUTargetInfo();
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -228,8 +222,7 @@ public:
unsigned getDynRel(unsigned Type) const override;
void writeGotHeader(uint8_t *Buf) const override;
void writeGotPlt(uint8_t *Buf, uint64_t Plt) const override;
- void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const override;
+ void writePltZero(uint8_t *Buf) const override;
void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
unsigned RelOff) const override;
@@ -348,8 +341,7 @@ bool X86TargetInfo::isTlsDynRel(unsigned
return Type == R_386_TLS_GD;
}
-void X86TargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {
+void X86TargetInfo::writePltZero(uint8_t *Buf) const {
// Executable files and shared object files have
// separate procedure linkage tables.
if (Config->Shared) {
@@ -368,8 +360,9 @@ void X86TargetInfo::writePltZero(uint8_t
0x90, 0x90, 0x90, 0x90 // nop;nop;nop;nop
};
memcpy(Buf, PltData, sizeof(PltData));
- write32le(Buf + 2, GotAddr + 4); // GOT+4
- write32le(Buf + 8, GotAddr + 8); // GOT+8
+ uint32_t Got = Out<ELF32LE>::GotPlt->getVA();
+ write32le(Buf + 2, Got + 4); // GOT+4
+ write32le(Buf + 8, Got + 8); // GOT+8
}
void X86TargetInfo::writePlt(uint8_t *Buf, uint64_t GotAddr,
@@ -629,16 +622,17 @@ void X86_64TargetInfo::writeGotPlt(uint8
write32le(Buf, Plt + 6);
}
-void X86_64TargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {
+void X86_64TargetInfo::writePltZero(uint8_t *Buf) const {
const uint8_t PltData[] = {
0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip)
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip)
0x0f, 0x1f, 0x40, 0x00 // nopl 0x0(rax)
};
memcpy(Buf, PltData, sizeof(PltData));
- write32le(Buf + 2, GotAddr - PltAddr + 2); // GOT+8
- write32le(Buf + 8, GotAddr - PltAddr + 4); // GOT+16
+ uint64_t Got = Out<ELF64LE>::GotPlt->getVA();
+ uint64_t Plt = Out<ELF64LE>::Plt->getVA();
+ write32le(Buf + 2, Got - Plt + 2); // GOT+8
+ write32le(Buf + 8, Got - Plt + 4); // GOT+16
}
void X86_64TargetInfo::writePlt(uint8_t *Buf, uint64_t GotAddr,
@@ -936,8 +930,7 @@ static uint16_t applyPPCHighesta(uint64_
PPCTargetInfo::PPCTargetInfo() {}
void PPCTargetInfo::writeGotPlt(uint8_t *Buf, uint64_t Plt) const {}
-void PPCTargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {}
+void PPCTargetInfo::writePltZero(uint8_t *Buf) const {}
void PPCTargetInfo::writePlt(uint8_t *Buf, uint64_t GotAddr,
uint64_t GotEntryAddr, uint64_t PltEntryAddr,
int32_t Index, unsigned RelOff) const {}
@@ -1002,8 +995,7 @@ uint64_t getPPC64TocBase() {
}
void PPC64TargetInfo::writeGotPlt(uint8_t *Buf, uint64_t Plt) const {}
-void PPC64TargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {}
+void PPC64TargetInfo::writePltZero(uint8_t *Buf) const {}
void PPC64TargetInfo::writePlt(uint8_t *Buf, uint64_t GotAddr,
uint64_t GotEntryAddr, uint64_t PltEntryAddr,
int32_t Index, unsigned RelOff) const {
@@ -1198,8 +1190,7 @@ void AArch64TargetInfo::writeGotPlt(uint
write64le(Buf, Out<ELF64LE>::Plt->getVA());
}
-void AArch64TargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {
+void AArch64TargetInfo::writePltZero(uint8_t *Buf) const {
const uint8_t PltData[] = {
0xf0, 0x7b, 0xbf, 0xa9, // stp x16, x30, [sp,#-16]!
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[2]))
@@ -1212,12 +1203,13 @@ void AArch64TargetInfo::writePltZero(uin
};
memcpy(Buf, PltData, sizeof(PltData));
- relocateOne(Buf + 4, Buf + 8, R_AARCH64_ADR_PREL_PG_HI21, PltAddr + 4,
- GotAddr + 16);
- relocateOne(Buf + 8, Buf + 12, R_AARCH64_LDST64_ABS_LO12_NC, PltAddr + 8,
- GotAddr + 16);
- relocateOne(Buf + 12, Buf + 16, R_AARCH64_ADD_ABS_LO12_NC, PltAddr + 12,
- GotAddr + 16);
+ uint64_t Got = Out<ELF64LE>::GotPlt->getVA();
+ uint64_t Plt = Out<ELF64LE>::Plt->getVA();
+ relocateOne(Buf + 4, Buf + 8, R_AARCH64_ADR_PREL_PG_HI21, Plt + 4, Got + 16);
+ relocateOne(Buf + 8, Buf + 12, R_AARCH64_LDST64_ABS_LO12_NC, Plt + 8,
+ Got + 16);
+ relocateOne(Buf + 12, Buf + 16, R_AARCH64_ADD_ABS_LO12_NC, Plt + 12,
+ Got + 16);
}
void AArch64TargetInfo::writePlt(uint8_t *Buf, uint64_t GotAddr,
@@ -1416,8 +1408,7 @@ void AMDGPUTargetInfo::writeGotPlt(uint8
llvm_unreachable("not implemented");
}
-void AMDGPUTargetInfo::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {
+void AMDGPUTargetInfo::writePltZero(uint8_t *Buf) const {
llvm_unreachable("not implemented");
}
@@ -1471,8 +1462,7 @@ void MipsTargetInfo<ELFT>::writeGotHeade
template <class ELFT>
void MipsTargetInfo<ELFT>::writeGotPlt(uint8_t *Buf, uint64_t Plt) const {}
template <class ELFT>
-void MipsTargetInfo<ELFT>::writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const {}
+void MipsTargetInfo<ELFT>::writePltZero(uint8_t *Buf) const {}
template <class ELFT>
void MipsTargetInfo<ELFT>::writePlt(uint8_t *Buf, uint64_t GotAddr,
uint64_t GotEntryAddr,
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=259154&r1=259153&r2=259154&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Jan 28 21:51:49 2016
@@ -46,8 +46,7 @@ public:
// If lazy binding is supported, the first entry of the PLT has code
// to call the dynamic linker to resolve PLT entries the first time
// they are called. This function writes that code.
- virtual void writePltZero(uint8_t *Buf, uint64_t GotAddr,
- uint64_t PltAddr) const = 0;
+ virtual void writePltZero(uint8_t *Buf) const = 0;
virtual void writePlt(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr,
uint64_t PltEntryAddr, int32_t Index,
More information about the llvm-commits
mailing list