diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-01-29 03:51:49 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-01-29 03:51:49 +0000 |
| commit | 900e2d25788a369c168445a0f05f167dd0fc2ebb (patch) | |
| tree | 9afa2018b85f615dda1fd8e60c36a90e35cd2156 | |
| parent | 3b2bec41fd5522b31f08baa2db419055b802de58 (diff) | |
| download | bcm5719-llvm-900e2d25788a369c168445a0f05f167dd0fc2ebb.tar.gz bcm5719-llvm-900e2d25788a369c168445a0f05f167dd0fc2ebb.zip | |
ELF: Do not pass addresses that can be obtained using Out.
llvm-svn: 259154
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 66 | ||||
| -rw-r--r-- | lld/ELF/Target.h | 3 |
3 files changed, 30 insertions, 41 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index b89b94acb78..812e027c3ae 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -192,7 +192,7 @@ template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { 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) { diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 5fab7413220..95d2b77ddb6 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -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 TargetInfo { 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 TargetInfo { 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 TargetInfo { 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 Type, const SymbolBody &S) const { 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 *Buf, uint64_t GotAddr, 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_t *Buf, uint64_t Plt) const { 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_t V) { return (V + 0x8000) >> 48; } 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(uint8_t *Buf, uint64_t Plt) const { 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(uint8_t *Buf, uint64_t GotAddr, }; 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_t *Buf, uint64_t Plt) const { 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>::writeGotHeader(uint8_t *Buf) const { 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, diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 1683b3c0430..ce6702cd050 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -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, |

