[lld] r248586 - Move a few methods out of line. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 10:19:11 PDT 2015
Author: rafael
Date: Fri Sep 25 12:19:10 2015
New Revision: 248586
URL: http://llvm.org/viewvc/llvm-project?rev=248586&view=rev
Log:
Move a few methods out of line. NFC.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248586&r1=248585&r2=248586&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Sep 25 12:19:10 2015
@@ -28,6 +28,14 @@ OutputSectionBase<Is64Bits>::OutputSecti
Header.sh_flags = sh_flags;
}
+template <class ELFT>
+GotSection<ELFT>::GotSection()
+ : OutputSectionBase<ELFT::Is64Bits>(".got", llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC |
+ llvm::ELF::SHF_WRITE) {
+ this->Header.sh_addralign = this->getAddrSize();
+}
+
template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) {
Sym->setGotIndex(Entries.size());
Entries.push_back(Sym);
@@ -39,6 +47,15 @@ GotSection<ELFT>::getEntryAddr(const Sym
return this->getVA() + B.getGotIndex() * this->getAddrSize();
}
+template <class ELFT>
+PltSection<ELFT>::PltSection(const GotSection<ELFT> &GotSec)
+ : OutputSectionBase<ELFT::Is64Bits>(".plt", llvm::ELF::SHT_PROGBITS,
+ llvm::ELF::SHF_ALLOC |
+ llvm::ELF::SHF_EXECINSTR),
+ GotSec(GotSec) {
+ this->Header.sh_addralign = 16;
+}
+
template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) {
uintptr_t Start = reinterpret_cast<uintptr_t>(Buf);
ArrayRef<uint8_t> Jmp = {0xff, 0x25}; // jmpq *val(%rip)
@@ -62,6 +79,19 @@ PltSection<ELFT>::getEntryAddr(const Sym
return this->getVA() + B.getPltIndex() * EntrySize;
}
+template <class ELFT>
+RelocationSection<ELFT>::RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
+ const GotSection<ELFT> &GotSec,
+ bool IsRela)
+ : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",
+ IsRela ? llvm::ELF::SHT_RELA
+ : llvm::ELF::SHT_REL,
+ llvm::ELF::SHF_ALLOC),
+ DynSymSec(DynSymSec), GotSec(GotSec), IsRela(IsRela) {
+ this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+ this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
+}
+
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
bool IsMips64EL = Relocs[0].C.getFile()->getObj().isMips64EL();
@@ -122,6 +152,15 @@ template <bool Is64Bits> void InterpSect
memcpy(Buf, Config->DynamicLinker.data(), Config->DynamicLinker.size());
}
+template <class ELFT>
+HashTableSection<ELFT>::HashTableSection(SymbolTableSection<ELFT> &DynSymSec)
+ : OutputSectionBase<ELFT::Is64Bits>(".hash", llvm::ELF::SHT_HASH,
+ llvm::ELF::SHF_ALLOC),
+ DynSymSec(DynSymSec) {
+ this->Header.sh_entsize = sizeof(Elf_Word);
+ this->Header.sh_addralign = sizeof(Elf_Word);
+}
+
template <class ELFT> void HashTableSection<ELFT>::addSymbol(SymbolBody *S) {
StringRef Name = S->getName();
DynSymSec.addSymbol(Name);
@@ -129,6 +168,21 @@ template <class ELFT> void HashTableSect
S->setDynamicSymbolTableIndex(Hashes.size());
}
+template <class ELFT>
+DynamicSection<ELFT>::DynamicSection(SymbolTable &SymTab,
+ HashTableSection<ELFT> &HashSec,
+ RelocationSection<ELFT> &RelaDynSec)
+ : OutputSectionBase<ELFT::Is64Bits>(".dynamic", llvm::ELF::SHT_DYNAMIC,
+ llvm::ELF::SHF_ALLOC |
+ llvm::ELF::SHF_WRITE),
+ HashSec(HashSec), DynSymSec(HashSec.getDynSymSec()),
+ DynStrSec(DynSymSec.getStrTabSec()), RelaDynSec(RelaDynSec),
+ SymTab(SymTab) {
+ typename Base::HeaderT &Header = this->Header;
+ Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
+ Header.sh_entsize = ELFT::Is64Bits ? 16 : 8;
+}
+
template <class ELFT> void DynamicSection<ELFT>::finalize() {
typename Base::HeaderT &Header = this->Header;
Header.sh_link = DynStrSec.getSectionIndex();
@@ -213,6 +267,15 @@ template <class ELFT> void DynamicSectio
}
template <class ELFT>
+OutputSection<ELFT>::OutputSection(const PltSection<ELFT> &PltSec,
+ const GotSection<ELFT> &GotSec,
+ const OutputSection<ELFT> &BssSec,
+ StringRef Name, uint32_t sh_type,
+ uintX_t sh_flags)
+ : OutputSectionBase<ELFT::Is64Bits>(Name, sh_type, sh_flags),
+ PltSec(PltSec), GotSec(GotSec), BssSec(BssSec) {}
+
+template <class ELFT>
void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) {
Sections.push_back(C);
C->setOutputSection(this);
@@ -256,6 +319,15 @@ template <class ELFT> void OutputSection
}
template <bool Is64Bits>
+StringTableSection<Is64Bits>::StringTableSection(bool Dynamic)
+ : OutputSectionBase<Is64Bits>(Dynamic ? ".dynstr" : ".strtab",
+ llvm::ELF::SHT_STRTAB,
+ Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
+ Dynamic(Dynamic) {
+ this->Header.sh_addralign = 1;
+}
+
+template <bool Is64Bits>
void StringTableSection<Is64Bits>::writeTo(uint8_t *Buf) {
StringRef Data = StrTabBuilder.data();
memcpy(Buf, Data.data(), Data.size());
@@ -278,6 +350,22 @@ bool lld::elf2::includeInDynamicSymtab(c
return B.isUsedInDynamicReloc();
}
+template <class ELFT>
+SymbolTableSection<ELFT>::SymbolTableSection(
+ SymbolTable &Table, StringTableSection<ELFT::Is64Bits> &StrTabSec,
+ const OutputSection<ELFT> &BssSec)
+ : OutputSectionBase<ELFT::Is64Bits>(
+ StrTabSec.isDynamic() ? ".dynsym" : ".symtab",
+ StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB,
+ StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
+ Table(Table), StrTabSec(StrTabSec), BssSec(BssSec) {
+ typedef OutputSectionBase<ELFT::Is64Bits> Base;
+ typename Base::HeaderT &Header = this->Header;
+
+ Header.sh_entsize = sizeof(Elf_Sym);
+ Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
+}
+
template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
const OutputSection<ELFT> *Out = nullptr;
const InputSection<ELFT> *Section = nullptr;
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=248586&r1=248585&r2=248586&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Fri Sep 25 12:19:10 2015
@@ -105,12 +105,7 @@ class GotSection final : public OutputSe
typedef typename Base::uintX_t uintX_t;
public:
- GotSection()
- : OutputSectionBase<ELFT::Is64Bits>(".got", llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE) {
- this->Header.sh_addralign = this->getAddrSize();
- }
+ GotSection();
void finalize() override {
this->Header.sh_size = Entries.size() * this->getAddrSize();
}
@@ -129,13 +124,7 @@ class PltSection final : public OutputSe
typedef typename Base::uintX_t uintX_t;
public:
- PltSection(const GotSection<ELFT> &GotSec)
- : OutputSectionBase<ELFT::Is64Bits>(".plt", llvm::ELF::SHT_PROGBITS,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_EXECINSTR),
- GotSec(GotSec) {
- this->Header.sh_addralign = 16;
- }
+ PltSection(const GotSection<ELFT> &GotSec);
void finalize() override {
this->Header.sh_size = Entries.size() * EntrySize;
}
@@ -165,19 +154,7 @@ public:
typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
SymbolTableSection(SymbolTable &Table,
StringTableSection<ELFT::Is64Bits> &StrTabSec,
- const OutputSection<ELFT> &BssSec)
- : OutputSectionBase<ELFT::Is64Bits>(
- StrTabSec.isDynamic() ? ".dynsym" : ".symtab",
- StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM
- : llvm::ELF::SHT_SYMTAB,
- StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
- Table(Table), StrTabSec(StrTabSec), BssSec(BssSec) {
- typedef OutputSectionBase<ELFT::Is64Bits> Base;
- typename Base::HeaderT &Header = this->Header;
-
- Header.sh_entsize = sizeof(Elf_Sym);
- Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
- }
+ const OutputSection<ELFT> &BssSec);
void finalize() override {
this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym);
@@ -214,16 +191,7 @@ class RelocationSection final : public O
public:
RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
- const GotSection<ELFT> &GotSec, bool IsRela)
- : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",
- IsRela ? llvm::ELF::SHT_RELA
- : llvm::ELF::SHT_REL,
- llvm::ELF::SHF_ALLOC),
- DynSymSec(DynSymSec), GotSec(GotSec), IsRela(IsRela) {
- this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
- this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
- }
-
+ const GotSection<ELFT> &GotSec, bool IsRela);
void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); }
void finalize() override;
void writeTo(uint8_t *Buf) override;
@@ -247,10 +215,7 @@ public:
typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
OutputSection(const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec,
const OutputSection<ELFT> &BssSec, StringRef Name,
- uint32_t sh_type, uintX_t sh_flags)
- : OutputSectionBase<ELFT::Is64Bits>(Name, sh_type, sh_flags),
- PltSec(PltSec), GotSec(GotSec), BssSec(BssSec) {}
-
+ uint32_t sh_type, uintX_t sh_flags);
void addSection(InputSection<ELFT> *C);
void writeTo(uint8_t *Buf) override;
@@ -273,14 +238,7 @@ template <bool Is64Bits>
class StringTableSection final : public OutputSectionBase<Is64Bits> {
public:
typedef typename OutputSectionBase<Is64Bits>::uintX_t uintX_t;
- StringTableSection(bool Dynamic)
- : OutputSectionBase<Is64Bits>(
- Dynamic ? ".dynstr" : ".strtab", llvm::ELF::SHT_STRTAB,
- Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
- Dynamic(Dynamic) {
- this->Header.sh_addralign = 1;
- }
-
+ StringTableSection(bool Dynamic);
void add(StringRef S) { StrTabBuilder.add(S); }
size_t getFileOff(StringRef S) const { return StrTabBuilder.getOffset(S); }
StringRef data() const { return StrTabBuilder.data(); }
@@ -303,14 +261,7 @@ class HashTableSection final : public Ou
typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word;
public:
- HashTableSection(SymbolTableSection<ELFT> &DynSymSec)
- : OutputSectionBase<ELFT::Is64Bits>(".hash", llvm::ELF::SHT_HASH,
- llvm::ELF::SHF_ALLOC),
- DynSymSec(DynSymSec) {
- this->Header.sh_entsize = sizeof(Elf_Word);
- this->Header.sh_addralign = sizeof(Elf_Word);
- }
-
+ HashTableSection(SymbolTableSection<ELFT> &DynSymSec);
void addSymbol(SymbolBody *S);
void finalize() override {
@@ -368,18 +319,7 @@ class DynamicSection final : public Outp
public:
DynamicSection(SymbolTable &SymTab, HashTableSection<ELFT> &HashSec,
- RelocationSection<ELFT> &RelaDynSec)
- : OutputSectionBase<ELFT::Is64Bits>(".dynamic", llvm::ELF::SHT_DYNAMIC,
- llvm::ELF::SHF_ALLOC |
- llvm::ELF::SHF_WRITE),
- HashSec(HashSec), DynSymSec(HashSec.getDynSymSec()),
- DynStrSec(DynSymSec.getStrTabSec()), RelaDynSec(RelaDynSec),
- SymTab(SymTab) {
- typename Base::HeaderT &Header = this->Header;
- Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
- Header.sh_entsize = ELFT::Is64Bits ? 16 : 8;
- }
-
+ RelocationSection<ELFT> &RelaDynSec);
void finalize() override;
void writeTo(uint8_t *Buf) override;
More information about the llvm-commits
mailing list