forked from OSchip/llvm-project
[ELF] - Detemplate GotPltSection and IgotPltSection sections.
Patch introduces Config->is64Bit() and with help of that detemplates GotPltSection and IgotPltSection sections Differential revision: https://reviews.llvm.org/D30944 llvm-svn: 297813
This commit is contained in:
parent
775588c0c3
commit
10f74fc10b
|
|
@ -162,6 +162,9 @@ struct Configuration {
|
|||
unsigned Optimize;
|
||||
unsigned ThinLTOJobs;
|
||||
|
||||
// Returns true if target is 64 bit.
|
||||
bool is64Bit() const { return EKind == ELF64LEKind || EKind == ELF64BEKind; }
|
||||
|
||||
// The ELF spec defines two types of relocation table entries, RELA and
|
||||
// REL. RELA is a triplet of (offset, info, addend) while REL is a
|
||||
// tuple of (offset, info). Addends for REL are implicit and read from
|
||||
|
|
@ -177,9 +180,8 @@ struct Configuration {
|
|||
// As far as we know, all 64-bit ABIs are using RELA. A few 32-bit ABIs
|
||||
// are using RELA too.
|
||||
bool isRela() const {
|
||||
bool is64 = (EKind == ELF64LEKind || EKind == ELF64BEKind);
|
||||
bool isX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
|
||||
return is64 || isX32Abi || MipsN32Abi;
|
||||
bool IsX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
|
||||
return is64Bit() || IsX32Abi || MipsN32Abi;
|
||||
}
|
||||
|
||||
// Returns true if we need to pass through relocations in input
|
||||
|
|
|
|||
|
|
@ -937,52 +937,50 @@ template <class ELFT> void MipsGotSection<ELFT>::writeTo(uint8_t *Buf) {
|
|||
}
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
GotPltSection<ELFT>::GotPltSection()
|
||||
GotPltSection::GotPltSection()
|
||||
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
|
||||
Target->GotPltEntrySize, ".got.plt") {}
|
||||
|
||||
template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
|
||||
void GotPltSection::addEntry(SymbolBody &Sym) {
|
||||
Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size();
|
||||
Entries.push_back(&Sym);
|
||||
}
|
||||
|
||||
template <class ELFT> size_t GotPltSection<ELFT>::getSize() const {
|
||||
size_t GotPltSection::getSize() const {
|
||||
return (Target->GotPltHeaderEntriesNum + Entries.size()) *
|
||||
Target->GotPltEntrySize;
|
||||
}
|
||||
|
||||
template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) {
|
||||
void GotPltSection::writeTo(uint8_t *Buf) {
|
||||
Target->writeGotPltHeader(Buf);
|
||||
Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize;
|
||||
for (const SymbolBody *B : Entries) {
|
||||
Target->writeGotPlt(Buf, *B);
|
||||
Buf += sizeof(uintX_t);
|
||||
Buf += Config->is64Bit() ? 8 : 4;
|
||||
}
|
||||
}
|
||||
|
||||
// On ARM the IgotPltSection is part of the GotSection, on other Targets it is
|
||||
// part of the .got.plt
|
||||
template <class ELFT>
|
||||
IgotPltSection<ELFT>::IgotPltSection()
|
||||
IgotPltSection::IgotPltSection()
|
||||
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
|
||||
Target->GotPltEntrySize,
|
||||
Config->EMachine == EM_ARM ? ".got" : ".got.plt") {}
|
||||
|
||||
template <class ELFT> void IgotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
|
||||
void IgotPltSection::addEntry(SymbolBody &Sym) {
|
||||
Sym.IsInIgot = true;
|
||||
Sym.GotPltIndex = Entries.size();
|
||||
Entries.push_back(&Sym);
|
||||
}
|
||||
|
||||
template <class ELFT> size_t IgotPltSection<ELFT>::getSize() const {
|
||||
size_t IgotPltSection::getSize() const {
|
||||
return Entries.size() * Target->GotPltEntrySize;
|
||||
}
|
||||
|
||||
template <class ELFT> void IgotPltSection<ELFT>::writeTo(uint8_t *Buf) {
|
||||
void IgotPltSection::writeTo(uint8_t *Buf) {
|
||||
for (const SymbolBody *B : Entries) {
|
||||
Target->writeIgotPlt(Buf, *B);
|
||||
Buf += sizeof(uintX_t);
|
||||
Buf += Config->is64Bit() ? 8 : 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2324,16 +2322,6 @@ template class elf::MipsGotSection<ELF32BE>;
|
|||
template class elf::MipsGotSection<ELF64LE>;
|
||||
template class elf::MipsGotSection<ELF64BE>;
|
||||
|
||||
template class elf::GotPltSection<ELF32LE>;
|
||||
template class elf::GotPltSection<ELF32BE>;
|
||||
template class elf::GotPltSection<ELF64LE>;
|
||||
template class elf::GotPltSection<ELF64BE>;
|
||||
|
||||
template class elf::IgotPltSection<ELF32LE>;
|
||||
template class elf::IgotPltSection<ELF32BE>;
|
||||
template class elf::IgotPltSection<ELF64LE>;
|
||||
template class elf::IgotPltSection<ELF64BE>;
|
||||
|
||||
template class elf::StringTableSection<ELF32LE>;
|
||||
template class elf::StringTableSection<ELF32BE>;
|
||||
template class elf::StringTableSection<ELF64LE>;
|
||||
|
|
|
|||
|
|
@ -265,9 +265,7 @@ private:
|
|||
uintX_t Size = 0;
|
||||
};
|
||||
|
||||
template <class ELFT> class GotPltSection final : public SyntheticSection {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
|
||||
class GotPltSection final : public SyntheticSection {
|
||||
public:
|
||||
GotPltSection();
|
||||
void addEntry(SymbolBody &Sym);
|
||||
|
|
@ -283,9 +281,7 @@ private:
|
|||
// Symbols that will be relocated by Target->IRelativeRel.
|
||||
// On most Targets the IgotPltSection will immediately follow the GotPltSection
|
||||
// on ARM the IgotPltSection will immediately follow the GotSection.
|
||||
template <class ELFT> class IgotPltSection final : public SyntheticSection {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
|
||||
class IgotPltSection final : public SyntheticSection {
|
||||
public:
|
||||
IgotPltSection();
|
||||
void addEntry(SymbolBody &Sym);
|
||||
|
|
@ -773,8 +769,8 @@ template <class ELFT> struct In {
|
|||
static GotSection<ELFT> *Got;
|
||||
static EhFrameSection<ELFT> *EhFrame;
|
||||
static MipsGotSection<ELFT> *MipsGot;
|
||||
static GotPltSection<ELFT> *GotPlt;
|
||||
static IgotPltSection<ELFT> *IgotPlt;
|
||||
static GotPltSection *GotPlt;
|
||||
static IgotPltSection *IgotPlt;
|
||||
static HashTableSection<ELFT> *HashTab;
|
||||
static InputSection *Interp;
|
||||
static MipsRldMapSection<ELFT> *MipsRldMap;
|
||||
|
|
@ -803,8 +799,8 @@ template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
|
|||
template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
|
||||
template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
|
||||
template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
|
||||
template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
|
||||
template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
|
||||
template <class ELFT> GotPltSection *In<ELFT>::GotPlt;
|
||||
template <class ELFT> IgotPltSection *In<ELFT>::IgotPlt;
|
||||
template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
|
||||
template <class ELFT> InputSection *In<ELFT>::Interp;
|
||||
template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;
|
||||
|
|
|
|||
|
|
@ -428,9 +428,9 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
|
|||
Add(In<ELFT>::Got);
|
||||
}
|
||||
|
||||
In<ELFT>::GotPlt = make<GotPltSection<ELFT>>();
|
||||
In<ELFT>::GotPlt = make<GotPltSection>();
|
||||
Add(In<ELFT>::GotPlt);
|
||||
In<ELFT>::IgotPlt = make<IgotPltSection<ELFT>>();
|
||||
In<ELFT>::IgotPlt = make<IgotPltSection>();
|
||||
Add(In<ELFT>::IgotPlt);
|
||||
|
||||
if (Config->GdbIndex) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue