Skip to content

Commit 10f74fc

Browse files
author
George Rimar
committedMar 15, 2017
[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
1 parent 775588c commit 10f74fc

File tree

4 files changed

+23
-37
lines changed

4 files changed

+23
-37
lines changed
 

‎lld/ELF/Config.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ struct Configuration {
162162
unsigned Optimize;
163163
unsigned ThinLTOJobs;
164164

165+
// Returns true if target is 64 bit.
166+
bool is64Bit() const { return EKind == ELF64LEKind || EKind == ELF64BEKind; }
167+
165168
// The ELF spec defines two types of relocation table entries, RELA and
166169
// REL. RELA is a triplet of (offset, info, addend) while REL is a
167170
// tuple of (offset, info). Addends for REL are implicit and read from
@@ -177,9 +180,8 @@ struct Configuration {
177180
// As far as we know, all 64-bit ABIs are using RELA. A few 32-bit ABIs
178181
// are using RELA too.
179182
bool isRela() const {
180-
bool is64 = (EKind == ELF64LEKind || EKind == ELF64BEKind);
181-
bool isX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
182-
return is64 || isX32Abi || MipsN32Abi;
183+
bool IsX32Abi = (EKind == ELF32LEKind && EMachine == llvm::ELF::EM_X86_64);
184+
return is64Bit() || IsX32Abi || MipsN32Abi;
183185
}
184186

185187
// Returns true if we need to pass through relocations in input

‎lld/ELF/SyntheticSections.cpp

+10-22
Original file line numberDiff line numberDiff line change
@@ -937,52 +937,50 @@ template <class ELFT> void MipsGotSection<ELFT>::writeTo(uint8_t *Buf) {
937937
}
938938
}
939939

940-
template <class ELFT>
941-
GotPltSection<ELFT>::GotPltSection()
940+
GotPltSection::GotPltSection()
942941
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
943942
Target->GotPltEntrySize, ".got.plt") {}
944943

945-
template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
944+
void GotPltSection::addEntry(SymbolBody &Sym) {
946945
Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size();
947946
Entries.push_back(&Sym);
948947
}
949948

950-
template <class ELFT> size_t GotPltSection<ELFT>::getSize() const {
949+
size_t GotPltSection::getSize() const {
951950
return (Target->GotPltHeaderEntriesNum + Entries.size()) *
952951
Target->GotPltEntrySize;
953952
}
954953

955-
template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) {
954+
void GotPltSection::writeTo(uint8_t *Buf) {
956955
Target->writeGotPltHeader(Buf);
957956
Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize;
958957
for (const SymbolBody *B : Entries) {
959958
Target->writeGotPlt(Buf, *B);
960-
Buf += sizeof(uintX_t);
959+
Buf += Config->is64Bit() ? 8 : 4;
961960
}
962961
}
963962

964963
// On ARM the IgotPltSection is part of the GotSection, on other Targets it is
965964
// part of the .got.plt
966-
template <class ELFT>
967-
IgotPltSection<ELFT>::IgotPltSection()
965+
IgotPltSection::IgotPltSection()
968966
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,
969967
Target->GotPltEntrySize,
970968
Config->EMachine == EM_ARM ? ".got" : ".got.plt") {}
971969

972-
template <class ELFT> void IgotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
970+
void IgotPltSection::addEntry(SymbolBody &Sym) {
973971
Sym.IsInIgot = true;
974972
Sym.GotPltIndex = Entries.size();
975973
Entries.push_back(&Sym);
976974
}
977975

978-
template <class ELFT> size_t IgotPltSection<ELFT>::getSize() const {
976+
size_t IgotPltSection::getSize() const {
979977
return Entries.size() * Target->GotPltEntrySize;
980978
}
981979

982-
template <class ELFT> void IgotPltSection<ELFT>::writeTo(uint8_t *Buf) {
980+
void IgotPltSection::writeTo(uint8_t *Buf) {
983981
for (const SymbolBody *B : Entries) {
984982
Target->writeIgotPlt(Buf, *B);
985-
Buf += sizeof(uintX_t);
983+
Buf += Config->is64Bit() ? 8 : 4;
986984
}
987985
}
988986

@@ -2324,16 +2322,6 @@ template class elf::MipsGotSection<ELF32BE>;
23242322
template class elf::MipsGotSection<ELF64LE>;
23252323
template class elf::MipsGotSection<ELF64BE>;
23262324

2327-
template class elf::GotPltSection<ELF32LE>;
2328-
template class elf::GotPltSection<ELF32BE>;
2329-
template class elf::GotPltSection<ELF64LE>;
2330-
template class elf::GotPltSection<ELF64BE>;
2331-
2332-
template class elf::IgotPltSection<ELF32LE>;
2333-
template class elf::IgotPltSection<ELF32BE>;
2334-
template class elf::IgotPltSection<ELF64LE>;
2335-
template class elf::IgotPltSection<ELF64BE>;
2336-
23372325
template class elf::StringTableSection<ELF32LE>;
23382326
template class elf::StringTableSection<ELF32BE>;
23392327
template class elf::StringTableSection<ELF64LE>;

‎lld/ELF/SyntheticSections.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ template <class ELFT> class MipsGotSection final : public SyntheticSection {
265265
uintX_t Size = 0;
266266
};
267267

268-
template <class ELFT> class GotPltSection final : public SyntheticSection {
269-
typedef typename ELFT::uint uintX_t;
270-
268+
class GotPltSection final : public SyntheticSection {
271269
public:
272270
GotPltSection();
273271
void addEntry(SymbolBody &Sym);
@@ -283,9 +281,7 @@ template <class ELFT> class GotPltSection final : public SyntheticSection {
283281
// Symbols that will be relocated by Target->IRelativeRel.
284282
// On most Targets the IgotPltSection will immediately follow the GotPltSection
285283
// on ARM the IgotPltSection will immediately follow the GotSection.
286-
template <class ELFT> class IgotPltSection final : public SyntheticSection {
287-
typedef typename ELFT::uint uintX_t;
288-
284+
class IgotPltSection final : public SyntheticSection {
289285
public:
290286
IgotPltSection();
291287
void addEntry(SymbolBody &Sym);
@@ -773,8 +769,8 @@ template <class ELFT> struct In {
773769
static GotSection<ELFT> *Got;
774770
static EhFrameSection<ELFT> *EhFrame;
775771
static MipsGotSection<ELFT> *MipsGot;
776-
static GotPltSection<ELFT> *GotPlt;
777-
static IgotPltSection<ELFT> *IgotPlt;
772+
static GotPltSection *GotPlt;
773+
static IgotPltSection *IgotPlt;
778774
static HashTableSection<ELFT> *HashTab;
779775
static InputSection *Interp;
780776
static MipsRldMapSection<ELFT> *MipsRldMap;
@@ -803,8 +799,8 @@ template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
803799
template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
804800
template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
805801
template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
806-
template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
807-
template <class ELFT> IgotPltSection<ELFT> *In<ELFT>::IgotPlt;
802+
template <class ELFT> GotPltSection *In<ELFT>::GotPlt;
803+
template <class ELFT> IgotPltSection *In<ELFT>::IgotPlt;
808804
template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
809805
template <class ELFT> InputSection *In<ELFT>::Interp;
810806
template <class ELFT> MipsRldMapSection<ELFT> *In<ELFT>::MipsRldMap;

‎lld/ELF/Writer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
428428
Add(In<ELFT>::Got);
429429
}
430430

431-
In<ELFT>::GotPlt = make<GotPltSection<ELFT>>();
431+
In<ELFT>::GotPlt = make<GotPltSection>();
432432
Add(In<ELFT>::GotPlt);
433-
In<ELFT>::IgotPlt = make<IgotPltSection<ELFT>>();
433+
In<ELFT>::IgotPlt = make<IgotPltSection>();
434434
Add(In<ELFT>::IgotPlt);
435435

436436
if (Config->GdbIndex) {

0 commit comments

Comments
 (0)
Please sign in to comment.