Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -122,14 +122,11 @@ public: PltSection(); - void finalize() override { - this->Header.sh_size = Entries.size() * EntrySize; - } + void finalize() override; void writeTo(uint8_t *Buf) override; void addEntry(SymbolBody *Sym); bool empty() const { return Entries.empty(); } uintX_t getEntryAddr(const SymbolBody &B) const; - static const unsigned EntrySize = 8; private: std::vector Entries; Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -119,7 +119,7 @@ uintptr_t InstPos = reinterpret_cast(Buf); uint64_t PltEntryAddr = (InstPos - Start) + this->getVA(); Target->writePltEntry(Buf, GotEntryAddr, PltEntryAddr); - Buf += EntrySize; + Buf += Target->getPltEntrySize(); } } @@ -131,7 +131,12 @@ template typename PltSection::uintX_t PltSection::getEntryAddr(const SymbolBody &B) const { - return this->getVA() + B.getPltIndex() * EntrySize; + return this->getVA() + B.getPltIndex() * Target->getPltEntrySize(); +} + +template +void PltSection::finalize() { + this->Header.sh_size = Entries.size() * Target->getPltEntrySize(); } template Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -26,6 +26,7 @@ unsigned getGotReloc() const { return GotReloc; } unsigned getGotRefReloc() const { return GotRefReloc; } unsigned getRelativeReloc() const { return RelativeReloc; } + unsigned getPltEntrySize() const { return PltEntrySize; } virtual void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr) const = 0; virtual bool isRelRelative(uint32_t Type) const; @@ -44,6 +45,7 @@ unsigned GotRefReloc; unsigned GotReloc; unsigned RelativeReloc; + unsigned PltEntrySize; llvm::StringRef DefaultEntry = "_start"; }; Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -36,6 +36,7 @@ PCRelReloc = R_386_PC32; GotReloc = R_386_GLOB_DAT; GotRefReloc = R_386_GOT32; + PltEntrySize = 8; VAStart = 0x10000; } @@ -94,6 +95,7 @@ GotReloc = R_X86_64_GLOB_DAT; GotRefReloc = R_X86_64_PC32; RelativeReloc = R_X86_64_RELATIVE; + PltEntrySize = 8; // On freebsd x86_64 the first page cannot be mmaped. // On linux that is controled by vm.mmap_min_addr. At least on some x86_64 @@ -203,6 +205,7 @@ PPC64TargetInfo::PPC64TargetInfo() { // PCRelReloc = FIXME // GotReloc = FIXME + PltEntrySize = 32; VAStart = 0x10000000; } void PPC64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, @@ -237,6 +240,7 @@ PPCTargetInfo::PPCTargetInfo() { // PCRelReloc = FIXME // GotReloc = FIXME + PltEntrySize = 8; VAStart = 0x10000000; } void PPCTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, @@ -254,6 +258,7 @@ ARMTargetInfo::ARMTargetInfo() { // PCRelReloc = FIXME // GotReloc = FIXME + PltEntrySize = 8; VAStart = 0x8000; } void ARMTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, @@ -271,6 +276,7 @@ AArch64TargetInfo::AArch64TargetInfo() { // PCRelReloc = FIXME // GotReloc = FIXME + PltEntrySize = 8; VAStart = 0x400000; } void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr, @@ -351,6 +357,7 @@ // PCRelReloc = FIXME // GotReloc = FIXME DefaultEntry = "__start"; + PltEntrySize = 8; VAStart = 0x400000; }