[lld] r250466 - ELF2: Use ELFT to template OutputSections.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 16:17:00 PDT 2015
On Fri, Oct 16, 2015 at 3:37 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Thu, Oct 15, 2015 at 3:27 PM, Rui Ueyama via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ruiu
>> Date: Thu Oct 15 17:27:29 2015
>> New Revision: 250466
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=250466&view=rev
>> Log:
>> ELF2: Use ELFT to template OutputSections.
>>
>> This patch is to use ELFT instead of Is64Bits to template OutputSection
>> and its subclasses. This increases code size slightly because it creates
>> two identical functions for some classes, but that's only 20 KB out of
>> 33 MB, so it's negligible.
>>
>
> Are you doing this for the convenience of the users? (so they can specify
> ELFT instead of having to extract the 64bit-ness from it?) If so, you could
> keep the code size down by using an alias template, perhaps?
>
> template<typename T>
> using OutputSectionBase = OutputSectionBaseRealThing<T::is64Bits>;
>
Well, it's not for the users but for us. I didn't want to think about which
class is templated for ELFT and which is for ELFT::Is64Bits.
>
>> This is as per discussion with Rafael. He's not fan of the idea but OK
>> with this. We'll revisit later to this topic.
>>
>> Modified:
>> lld/trunk/ELF/InputSection.h
>> lld/trunk/ELF/OutputSections.cpp
>> lld/trunk/ELF/OutputSections.h
>> lld/trunk/ELF/SymbolTable.cpp
>> lld/trunk/ELF/SymbolTable.h
>> lld/trunk/ELF/Symbols.h
>> lld/trunk/ELF/Writer.cpp
>>
>> Modified: lld/trunk/ELF/InputSection.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/InputSection.h (original)
>> +++ lld/trunk/ELF/InputSection.h Thu Oct 15 17:27:29 2015
>> @@ -18,7 +18,7 @@ namespace elf2 {
>>
>> template <class ELFT> class ObjectFile;
>> template <class ELFT> class OutputSection;
>> -template <bool Is64Bits> class OutputSectionBase;
>> +template <class ELFT> class OutputSectionBase;
>>
>> // This corresponds to a section of an input file.
>> template <class ELFT> class InputSection {
>> @@ -55,7 +55,7 @@ public:
>> // The offset from beginning of the output sections this section was
>> assigned
>> // to. The writer sets a value.
>> uint64_t OutSecOff = 0;
>> - OutputSectionBase<ELFT::Is64Bits> *OutSec = nullptr;
>> + OutputSectionBase<ELFT> *OutSec = nullptr;
>>
>> static InputSection<ELFT> Discarded;
>>
>>
>> Modified: lld/trunk/ELF/OutputSections.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/OutputSections.cpp (original)
>> +++ lld/trunk/ELF/OutputSections.cpp Thu Oct 15 17:27:29 2015
>> @@ -20,20 +20,19 @@ using namespace llvm::ELF;
>> using namespace lld;
>> using namespace lld::elf2;
>>
>> -template <bool Is64Bits>
>> -OutputSectionBase<Is64Bits>::OutputSectionBase(StringRef Name, uint32_t
>> sh_type,
>> - uintX_t sh_flags)
>> +template <class ELFT>
>> +OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t
>> sh_type,
>> + uintX_t sh_flags)
>> : Name(Name) {
>> - memset(&Header, 0, sizeof(HeaderT));
>> + memset(&Header, 0, sizeof(Elf_Shdr));
>> Header.sh_type = sh_type;
>> 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) {
>> + : OutputSectionBase<ELFT>(".got", llvm::ELF::SHT_PROGBITS,
>> + llvm::ELF::SHF_ALLOC |
>> llvm::ELF::SHF_WRITE) {
>> this->Header.sh_addralign = sizeof(uintX_t);
>> }
>>
>> @@ -61,9 +60,8 @@ template <class ELFT> void GotSection<EL
>>
>> template <class ELFT>
>> PltSection<ELFT>::PltSection()
>> - : OutputSectionBase<ELFT::Is64Bits>(".plt", llvm::ELF::SHT_PROGBITS,
>> - llvm::ELF::SHF_ALLOC |
>> - llvm::ELF::SHF_EXECINSTR) {
>> + : OutputSectionBase<ELFT>(".plt", llvm::ELF::SHT_PROGBITS,
>> + llvm::ELF::SHF_ALLOC |
>> llvm::ELF::SHF_EXECINSTR) {
>> this->Header.sh_addralign = 16;
>> }
>>
>> @@ -95,10 +93,9 @@ void PltSection<ELFT>::finalize() {
>>
>> template <class ELFT>
>> RelocationSection<ELFT>::RelocationSection(bool IsRela)
>> - : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" :
>> ".rel.dyn",
>> - IsRela ? llvm::ELF::SHT_RELA
>> - : llvm::ELF::SHT_REL,
>> - llvm::ELF::SHF_ALLOC),
>> + : OutputSectionBase<ELFT>(IsRela ? ".rela.dyn" : ".rel.dyn",
>> + IsRela ? llvm::ELF::SHT_RELA :
>> llvm::ELF::SHT_REL,
>> + llvm::ELF::SHF_ALLOC),
>> IsRela(IsRela) {
>> this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
>> this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
>> @@ -158,38 +155,27 @@ template <class ELFT> void RelocationSec
>> this->Header.sh_size = Relocs.size() * this->Header.sh_entsize;
>> }
>>
>> -template <bool Is64Bits>
>> -InterpSection<Is64Bits>::InterpSection()
>> - : OutputSectionBase<Is64Bits>(".interp", llvm::ELF::SHT_PROGBITS,
>> - llvm::ELF::SHF_ALLOC) {
>> +template <class ELFT>
>> +InterpSection<ELFT>::InterpSection()
>> + : OutputSectionBase<ELFT>(".interp", llvm::ELF::SHT_PROGBITS,
>> + llvm::ELF::SHF_ALLOC) {
>> this->Header.sh_size = Config->DynamicLinker.size() + 1;
>> this->Header.sh_addralign = 1;
>> }
>>
>> -template <bool Is64Bits>
>> -template <endianness E>
>> -void OutputSectionBase<Is64Bits>::writeHeaderTo(
>> - typename ELFFile<ELFType<E, Is64Bits>>::Elf_Shdr *SHdr) {
>> - SHdr->sh_name = Header.sh_name;
>> - SHdr->sh_type = Header.sh_type;
>> - SHdr->sh_flags = Header.sh_flags;
>> - SHdr->sh_addr = Header.sh_addr;
>> - SHdr->sh_offset = Header.sh_offset;
>> - SHdr->sh_size = Header.sh_size;
>> - SHdr->sh_link = Header.sh_link;
>> - SHdr->sh_info = Header.sh_info;
>> - SHdr->sh_addralign = Header.sh_addralign;
>> - SHdr->sh_entsize = Header.sh_entsize;
>> +template <class ELFT>
>> +void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *SHdr) {
>> + *SHdr = Header;
>> }
>>
>> -template <bool Is64Bits> void InterpSection<Is64Bits>::writeTo(uint8_t
>> *Buf) {
>> +template <class ELFT> void InterpSection<ELFT>::writeTo(uint8_t *Buf) {
>> memcpy(Buf, Config->DynamicLinker.data(),
>> Config->DynamicLinker.size());
>> }
>>
>> template <class ELFT>
>> HashTableSection<ELFT>::HashTableSection()
>> - : OutputSectionBase<ELFT::Is64Bits>(".hash", llvm::ELF::SHT_HASH,
>> - llvm::ELF::SHF_ALLOC) {
>> + : OutputSectionBase<ELFT>(".hash", llvm::ELF::SHT_HASH,
>> + llvm::ELF::SHF_ALLOC) {
>> this->Header.sh_entsize = sizeof(Elf_Word);
>> this->Header.sh_addralign = sizeof(Elf_Word);
>> }
>> @@ -245,11 +231,10 @@ template <class ELFT> void HashTableSect
>>
>> template <class ELFT>
>> DynamicSection<ELFT>::DynamicSection(SymbolTable<ELFT> &SymTab)
>> - : OutputSectionBase<ELFT::Is64Bits>(".dynamic",
>> llvm::ELF::SHT_DYNAMIC,
>> - llvm::ELF::SHF_ALLOC |
>> - llvm::ELF::SHF_WRITE),
>> + : OutputSectionBase<ELFT>(".dynamic", llvm::ELF::SHT_DYNAMIC,
>> + llvm::ELF::SHF_ALLOC |
>> llvm::ELF::SHF_WRITE),
>> SymTab(SymTab) {
>> - typename Base::HeaderT &Header = this->Header;
>> + Elf_Shdr &Header = this->Header;
>> Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
>> Header.sh_entsize = ELFT::Is64Bits ? 16 : 8;
>> }
>> @@ -258,7 +243,7 @@ template <class ELFT> void DynamicSectio
>> if (this->Header.sh_size)
>> return; // Already finalized.
>>
>> - typename Base::HeaderT &Header = this->Header;
>> + Elf_Shdr &Header = this->Header;
>> Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex;
>>
>> unsigned NumEntries = 0;
>> @@ -358,7 +343,7 @@ template <class ELFT> void DynamicSectio
>> WriteVal(DT_SONAME,
>> Out<ELFT>::DynStrTab->getFileOff(Config->SoName));
>>
>> auto WriteArray = [&](int32_t T1, int32_t T2,
>> - const OutputSectionBase<ELFT::Is64Bits> *Sec) {
>> + const OutputSectionBase<ELFT> *Sec) {
>> if (!Sec)
>> return;
>> WritePtr(T1, Sec->getVA());
>> @@ -391,7 +376,7 @@ template <class ELFT> void DynamicSectio
>> template <class ELFT>
>> OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t sh_type,
>> uintX_t sh_flags)
>> - : OutputSectionBase<ELFT::Is64Bits>(Name, sh_type, sh_flags) {}
>> + : OutputSectionBase<ELFT>(Name, sh_type, sh_flags) {}
>>
>> template <class ELFT>
>> void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) {
>> @@ -506,17 +491,16 @@ template <class ELFT> void OutputSection
>> C->writeTo(Buf);
>> }
>>
>> -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),
>> +template <class ELFT>
>> +StringTableSection<ELFT>::StringTableSection(bool Dynamic)
>> + : OutputSectionBase<ELFT>(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) {
>> +template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t
>> *Buf) {
>> StringRef Data = StrTabBuilder.data();
>> memcpy(Buf, Data.data(), Data.size());
>> }
>> @@ -571,14 +555,14 @@ bool lld::elf2::shouldKeepInSymtab(const
>>
>> template <class ELFT>
>> SymbolTableSection<ELFT>::SymbolTableSection(
>> - SymbolTable<ELFT> &Table, StringTableSection<ELFT::Is64Bits>
>> &StrTabSec)
>> - : OutputSectionBase<ELFT::Is64Bits>(
>> + SymbolTable<ELFT> &Table, StringTableSection<ELFT> &StrTabSec)
>> + : OutputSectionBase<ELFT>(
>> 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) {
>> - typedef OutputSectionBase<ELFT::Is64Bits> Base;
>> - typename Base::HeaderT &Header = this->Header;
>> + typedef OutputSectionBase<ELFT> Base;
>> + typename Base::Elf_Shdr &Header = this->Header;
>>
>> Header.sh_entsize = sizeof(Elf_Sym);
>> Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
>> @@ -664,7 +648,7 @@ void SymbolTableSection<ELFT>::writeGlob
>>
>> ESym->st_name = StrTabSec.getFileOff(Name);
>>
>> - const OutputSectionBase<ELFT::Is64Bits> *OutSec = nullptr;
>> + const OutputSectionBase<ELFT> *OutSec = nullptr;
>> const InputSection<ELFT> *Section = nullptr;
>>
>> switch (Body->kind()) {
>> @@ -721,17 +705,10 @@ void SymbolTableSection<ELFT>::writeGlob
>>
>> namespace lld {
>> namespace elf2 {
>> -template class OutputSectionBase<false>;
>> -template class OutputSectionBase<true>;
>> -
>> -template void OutputSectionBase<false>::writeHeaderTo<support::little>(
>> - ELFFile<ELFType<support::little, false>>::Elf_Shdr *SHdr);
>> -template void OutputSectionBase<true>::writeHeaderTo<support::little>(
>> - ELFFile<ELFType<support::little, true>>::Elf_Shdr *SHdr);
>> -template void OutputSectionBase<false>::writeHeaderTo<support::big>(
>> - ELFFile<ELFType<support::big, false>>::Elf_Shdr *SHdr);
>> -template void OutputSectionBase<true>::writeHeaderTo<support::big>(
>> - ELFFile<ELFType<support::big, true>>::Elf_Shdr *SHdr);
>> +template class OutputSectionBase<ELF32LE>;
>> +template class OutputSectionBase<ELF32BE>;
>> +template class OutputSectionBase<ELF64LE>;
>> +template class OutputSectionBase<ELF64BE>;
>>
>> template class GotSection<ELF32LE>;
>> template class GotSection<ELF32BE>;
>> @@ -748,8 +725,10 @@ template class RelocationSection<ELF32BE
>> template class RelocationSection<ELF64LE>;
>> template class RelocationSection<ELF64BE>;
>>
>> -template class InterpSection<false>;
>> -template class InterpSection<true>;
>> +template class InterpSection<ELF32LE>;
>> +template class InterpSection<ELF32BE>;
>> +template class InterpSection<ELF64LE>;
>> +template class InterpSection<ELF64BE>;
>>
>> template class HashTableSection<ELF32LE>;
>> template class HashTableSection<ELF32BE>;
>> @@ -766,8 +745,10 @@ template class OutputSection<ELF32BE>;
>> template class OutputSection<ELF64LE>;
>> template class OutputSection<ELF64BE>;
>>
>> -template class StringTableSection<false>;
>> -template class StringTableSection<true>;
>> +template class StringTableSection<ELF32LE>;
>> +template class StringTableSection<ELF32BE>;
>> +template class StringTableSection<ELF64LE>;
>> +template class StringTableSection<ELF64BE>;
>>
>> template class SymbolTableSection<ELF32LE>;
>> template class SymbolTableSection<ELF32BE>;
>>
>> Modified: lld/trunk/ELF/OutputSections.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/OutputSections.h (original)
>> +++ lld/trunk/ELF/OutputSections.h Thu Oct 15 17:27:29 2015
>> @@ -25,7 +25,7 @@ namespace elf2 {
>> class SymbolBody;
>> template <class ELFT> class SymbolTable;
>> template <class ELFT> class SymbolTableSection;
>> -template <bool Is64Bits> class StringTableSection;
>> +template <class ELFT> class StringTableSection;
>> template <class ELFT> class InputSection;
>> template <class ELFT> class OutputSection;
>> template <class ELFT> class ObjectFile;
>> @@ -54,19 +54,16 @@ bool shouldKeepInSymtab(
>> // input sections, others are created by the linker.
>> // The writer creates multiple OutputSections and assign them unique,
>> // non-overlapping file offsets and VAs.
>> -template <bool Is64Bits> class OutputSectionBase {
>> +template <class ELFT> class OutputSectionBase {
>> public:
>> - typedef typename std::conditional<Is64Bits, uint64_t, uint32_t>::type
>> uintX_t;
>> - typedef typename std::conditional<Is64Bits, llvm::ELF::Elf64_Shdr,
>> - llvm::ELF::Elf32_Shdr>::type HeaderT;
>> + typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> + typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
>>
>> OutputSectionBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags);
>> void setVA(uintX_t VA) { Header.sh_addr = VA; }
>> uintX_t getVA() const { return Header.sh_addr; }
>> void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
>> - template <llvm::object::endianness E>
>> - void writeHeaderTo(typename llvm::object::ELFFile<
>> - llvm::object::ELFType<E, Is64Bits>>::Elf_Shdr
>> *SHdr);
>> + void writeHeaderTo(Elf_Shdr *SHdr);
>> StringRef getName() { return Name; }
>> void setNameOffset(uintX_t Offset) { Header.sh_name = Offset; }
>>
>> @@ -89,13 +86,12 @@ public:
>>
>> protected:
>> StringRef Name;
>> - HeaderT Header;
>> + Elf_Shdr Header;
>> ~OutputSectionBase() = default;
>> };
>>
>> -template <class ELFT>
>> -class GotSection final : public OutputSectionBase<ELFT::Is64Bits> {
>> - typedef OutputSectionBase<ELFT::Is64Bits> Base;
>> +template <class ELFT> class GotSection final : public
>> OutputSectionBase<ELFT> {
>> + typedef OutputSectionBase<ELFT> Base;
>> typedef typename Base::uintX_t uintX_t;
>>
>> public:
>> @@ -112,9 +108,8 @@ private:
>> std::vector<const SymbolBody *> Entries;
>> };
>>
>> -template <class ELFT>
>> -class PltSection final : public OutputSectionBase<ELFT::Is64Bits> {
>> - typedef OutputSectionBase<ELFT::Is64Bits> Base;
>> +template <class ELFT> class PltSection final : public
>> OutputSectionBase<ELFT> {
>> + typedef OutputSectionBase<ELFT> Base;
>> typedef typename Base::uintX_t uintX_t;
>>
>> public:
>> @@ -136,19 +131,19 @@ template <class ELFT> struct DynamicRelo
>> };
>>
>> template <class ELFT>
>> -class SymbolTableSection final : public
>> OutputSectionBase<ELFT::Is64Bits> {
>> +class SymbolTableSection final : public OutputSectionBase<ELFT> {
>> public:
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym_Range
>> Elf_Sym_Range;
>> - typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
>> + typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> SymbolTableSection(SymbolTable<ELFT> &Table,
>> - StringTableSection<ELFT::Is64Bits> &StrTabSec);
>> + StringTableSection<ELFT> &StrTabSec);
>>
>> void finalize() override;
>> void writeTo(uint8_t *Buf) override;
>> void addSymbol(StringRef Name, bool isLocal = false);
>> - StringTableSection<ELFT::Is64Bits> &getStrTabSec() const { return
>> StrTabSec; }
>> + StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
>> unsigned getNumSymbols() const { return NumVisible + 1; }
>>
>> private:
>> @@ -156,13 +151,13 @@ private:
>> void writeGlobalSymbols(uint8_t *&Buf);
>>
>> SymbolTable<ELFT> &Table;
>> - StringTableSection<ELFT::Is64Bits> &StrTabSec;
>> + StringTableSection<ELFT> &StrTabSec;
>> unsigned NumVisible = 0;
>> unsigned NumLocals = 0;
>> };
>>
>> template <class ELFT>
>> -class RelocationSection final : public OutputSectionBase<ELFT::Is64Bits>
>> {
>> +class RelocationSection final : public OutputSectionBase<ELFT> {
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
>> typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> @@ -181,13 +176,13 @@ private:
>> };
>>
>> template <class ELFT>
>> -class OutputSection final : public OutputSectionBase<ELFT::Is64Bits> {
>> +class OutputSection final : public OutputSectionBase<ELFT> {
>> public:
>> - typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
>> + typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> OutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags);
>> void addSection(InputSection<ELFT> *C);
>> void writeTo(uint8_t *Buf) override;
>> @@ -196,18 +191,17 @@ private:
>> std::vector<InputSection<ELFT> *> Sections;
>> };
>>
>> -template <bool Is64Bits>
>> -class InterpSection final : public OutputSectionBase<Is64Bits> {
>> +template <class ELFT>
>> +class InterpSection final : public OutputSectionBase<ELFT> {
>> public:
>> InterpSection();
>> -
>> void writeTo(uint8_t *Buf);
>> };
>>
>> -template <bool Is64Bits>
>> -class StringTableSection final : public OutputSectionBase<Is64Bits> {
>> +template <class ELFT>
>> +class StringTableSection final : public OutputSectionBase<ELFT> {
>> public:
>> - typedef typename OutputSectionBase<Is64Bits>::uintX_t uintX_t;
>> + typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> StringTableSection(bool Dynamic);
>> void add(StringRef S) { StrTabBuilder.add(S); }
>> size_t getFileOff(StringRef S) const { return
>> StrTabBuilder.getOffset(S); }
>> @@ -227,7 +221,7 @@ private:
>> };
>>
>> template <class ELFT>
>> -class HashTableSection final : public OutputSectionBase<ELFT::Is64Bits> {
>> +class HashTableSection final : public OutputSectionBase<ELFT> {
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Word Elf_Word;
>>
>> public:
>> @@ -241,22 +235,22 @@ private:
>> };
>>
>> template <class ELFT>
>> -class DynamicSection final : public OutputSectionBase<ELFT::Is64Bits> {
>> - typedef OutputSectionBase<ELFT::Is64Bits> Base;
>> - typedef typename Base::HeaderT HeaderT;
>> +class DynamicSection final : public OutputSectionBase<ELFT> {
>> + typedef OutputSectionBase<ELFT> Base;
>> + typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
>> + typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
>> typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
>> - typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
>>
>> public:
>> DynamicSection(SymbolTable<ELFT> &SymTab);
>> void finalize() override;
>> void writeTo(uint8_t *Buf) override;
>>
>> - OutputSectionBase<ELFT::Is64Bits> *PreInitArraySec = nullptr;
>> - OutputSectionBase<ELFT::Is64Bits> *InitArraySec = nullptr;
>> - OutputSectionBase<ELFT::Is64Bits> *FiniArraySec = nullptr;
>> + OutputSectionBase<ELFT> *PreInitArraySec = nullptr;
>> + OutputSectionBase<ELFT> *InitArraySec = nullptr;
>> + OutputSectionBase<ELFT> *FiniArraySec = nullptr;
>>
>> private:
>> SymbolTable<ELFT> &SymTab;
>> @@ -271,14 +265,14 @@ template <class ELFT> struct Out {
>> static DynamicSection<ELFT> *Dynamic;
>> static GotSection<ELFT> *Got;
>> static HashTableSection<ELFT> *HashTab;
>> - static InterpSection<ELFT::Is64Bits> *Interp;
>> + static InterpSection<ELFT> *Interp;
>> static OutputSection<ELFT> *Bss;
>> - static OutputSectionBase<ELFT::Is64Bits> *Opd;
>> + static OutputSectionBase<ELFT> *Opd;
>> static uint8_t *OpdBuf;
>> static PltSection<ELFT> *Plt;
>> static RelocationSection<ELFT> *RelaDyn;
>> - static StringTableSection<ELFT::Is64Bits> *DynStrTab;
>> - static StringTableSection<ELFT::Is64Bits> *StrTab;
>> + static StringTableSection<ELFT> *DynStrTab;
>> + static StringTableSection<ELFT> *StrTab;
>> static SymbolTableSection<ELFT> *DynSymTab;
>> static SymbolTableSection<ELFT> *SymTab;
>> };
>> @@ -286,14 +280,14 @@ template <class ELFT> struct Out {
>> template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
>> template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
>> template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
>> -template <class ELFT> InterpSection<ELFT::Is64Bits> *Out<ELFT>::Interp;
>> +template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
>> template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
>> -template <class ELFT> OutputSectionBase<ELFT::Is64Bits> *Out<ELFT>::Opd;
>> +template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
>> template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
>> template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
>> template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
>> -template <class ELFT> StringTableSection<ELFT::Is64Bits>
>> *Out<ELFT>::DynStrTab;
>> -template <class ELFT> StringTableSection<ELFT::Is64Bits>
>> *Out<ELFT>::StrTab;
>> +template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
>> +template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
>> template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
>> template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
>> }
>>
>> Modified: lld/trunk/ELF/SymbolTable.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/SymbolTable.cpp (original)
>> +++ lld/trunk/ELF/SymbolTable.cpp Thu Oct 15 17:27:29 2015
>> @@ -71,9 +71,9 @@ SymbolBody *SymbolTable<ELFT>::addUndefi
>> }
>>
>> template <class ELFT>
>> -void SymbolTable<ELFT>::addSyntheticSym(
>> - StringRef Name, OutputSectionBase<ELFT::Is64Bits> &Section,
>> - typename ELFFile<ELFT>::uintX_t Value) {
>> +void SymbolTable<ELFT>::addSyntheticSym(StringRef Name,
>> + OutputSectionBase<ELFT> &Section,
>> + typename ELFFile<ELFT>::uintX_t
>> Value) {
>> typedef typename DefinedSynthetic<ELFT>::Elf_Sym Elf_Sym;
>> auto ESym = new (Alloc) Elf_Sym;
>> memset(ESym, 0, sizeof(Elf_Sym));
>>
>> Modified: lld/trunk/ELF/SymbolTable.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/SymbolTable.h (original)
>> +++ lld/trunk/ELF/SymbolTable.h Thu Oct 15 17:27:29 2015
>> @@ -15,7 +15,7 @@
>>
>> namespace lld {
>> namespace elf2 {
>> -template <bool Is64Bits> class OutputSectionBase;
>> +template <class ELFT> class OutputSectionBase;
>> struct Symbol;
>>
>> // SymbolTable is a bucket of all known symbols, including defined,
>> @@ -50,8 +50,7 @@ public:
>>
>> SymbolBody *addUndefined(StringRef Name);
>> SymbolBody *addUndefinedOpt(StringRef Name);
>> - void addSyntheticSym(StringRef Name,
>> - OutputSectionBase<ELFT::Is64Bits> &Section,
>> + void addSyntheticSym(StringRef Name, OutputSectionBase<ELFT> &Section,
>> typename llvm::object::ELFFile<ELFT>::uintX_t
>> Value);
>> void addIgnoredSym(StringRef Name);
>> bool isUndefined(StringRef Name);
>>
>> Modified: lld/trunk/ELF/Symbols.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Symbols.h (original)
>> +++ lld/trunk/ELF/Symbols.h Thu Oct 15 17:27:29 2015
>> @@ -37,7 +37,7 @@ class InputFile;
>> class SymbolBody;
>> template <class ELFT> class ObjectFile;
>> template <class ELFT> class OutputSection;
>> -template <bool Is64Bits> class OutputSectionBase;
>> +template <class ELFT> class OutputSectionBase;
>> template <class ELFT> class SharedFile;
>>
>> // Initializes global objects defined in this file.
>> @@ -193,8 +193,7 @@ template <class ELFT> class DefinedCommo
>> typedef typename Base::Elf_Sym Elf_Sym;
>>
>> public:
>> - typedef typename std::conditional<ELFT::Is64Bits, uint64_t,
>> uint32_t>::type
>> - uintX_t;
>> + typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
>> DefinedCommon(StringRef N, const Elf_Sym &Sym)
>> : Defined<ELFT>(Base::DefinedCommonKind, N, Sym) {
>> MaxAlignment = Sym.st_value;
>> @@ -234,14 +233,14 @@ template <class ELFT> class DefinedSynth
>> public:
>> typedef typename Base::Elf_Sym Elf_Sym;
>> DefinedSynthetic(StringRef N, const Elf_Sym &Sym,
>> - OutputSectionBase<ELFT::Is64Bits> &Section)
>> + OutputSectionBase<ELFT> &Section)
>> : Defined<ELFT>(Base::DefinedSyntheticKind, N, Sym),
>> Section(Section) {}
>>
>> static bool classof(const SymbolBody *S) {
>> return S->kind() == Base::DefinedSyntheticKind;
>> }
>>
>> - const OutputSectionBase<ELFT::Is64Bits> &Section;
>> + const OutputSectionBase<ELFT> &Section;
>> };
>>
>> // Undefined symbol.
>>
>> Modified: lld/trunk/ELF/Writer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250466&r1=250465&r2=250466&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Writer.cpp (original)
>> +++ lld/trunk/ELF/Writer.cpp Thu Oct 15 17:27:29 2015
>> @@ -72,13 +72,13 @@ private:
>>
>> SpecificBumpPtrAllocator<OutputSection<ELFT>> SecAlloc;
>> BumpPtrAllocator Alloc;
>> - std::vector<OutputSectionBase<ELFT::Is64Bits> *> OutputSections;
>> + std::vector<OutputSectionBase<ELFT> *> OutputSections;
>> unsigned getNumSections() const { return OutputSections.size() + 1; }
>>
>> - void addStartStopSymbols(OutputSectionBase<ELFT::Is64Bits> *Sec);
>> + void addStartStopSymbols(OutputSectionBase<ELFT> *Sec);
>> void setPhdr(Elf_Phdr *PH, uint32_t Type, uint32_t Flags, uintX_t
>> FileOff,
>> uintX_t VA, uintX_t Align);
>> - void copyPhdr(Elf_Phdr *PH, OutputSectionBase<ELFT::Is64Bits> *From);
>> + void copyPhdr(Elf_Phdr *PH, OutputSectionBase<ELFT> *From);
>>
>> SymbolTable<ELFT> &Symtab;
>> std::vector<Elf_Phdr> Phdrs;
>> @@ -91,11 +91,11 @@ private:
>> template <class ELFT> void lld::elf2::writeResult(SymbolTable<ELFT>
>> *Symtab) {
>> // Initialize output sections that are handled by Writer specially.
>> // Don't reorder because the order of initialization matters.
>> - InterpSection<ELFT::Is64Bits> Interp;
>> + InterpSection<ELFT> Interp;
>> Out<ELFT>::Interp = &Interp;
>> - StringTableSection<ELFT::Is64Bits> StrTab(false);
>> + StringTableSection<ELFT> StrTab(false);
>> Out<ELFT>::StrTab = &StrTab;
>> - StringTableSection<ELFT::Is64Bits> DynStrTab(true);
>> + StringTableSection<ELFT> DynStrTab(true);
>> Out<ELFT>::DynStrTab = &DynStrTab;
>> OutputSection<ELFT> Bss(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
>> Out<ELFT>::Bss = &Bss;
>> @@ -284,8 +284,8 @@ static int getPPC64SectionRank(StringRef
>>
>> // Output section ordering is determined by this function.
>> template <class ELFT>
>> -static bool compareOutputSections(OutputSectionBase<ELFT::Is64Bits> *A,
>> - OutputSectionBase<ELFT::Is64Bits> *B) {
>> +static bool compareOutputSections(OutputSectionBase<ELFT> *A,
>> + OutputSectionBase<ELFT> *B) {
>> typedef typename ELFFile<ELFT>::uintX_t uintX_t;
>>
>> uintX_t AFlags = A->getFlags();
>> @@ -403,7 +403,7 @@ template <class ELFT> void Writer<ELFT>:
>> if (!isOutputDynamic())
>> Symtab.addIgnoredSym("__tls_get_addr");
>>
>> - std::vector<OutputSectionBase<ELFT::Is64Bits> *> RegularSections;
>> + std::vector<OutputSectionBase<ELFT> *> RegularSections;
>>
>> for (const std::unique_ptr<ObjectFile<ELFT>> &F :
>> Symtab.getObjectFiles()) {
>> for (InputSection<ELFT> *C : F->getSections()) {
>> @@ -425,7 +425,7 @@ template <class ELFT> void Writer<ELFT>:
>> }
>> }
>>
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : RegularSections)
>> + for (OutputSectionBase<ELFT> *Sec : RegularSections)
>> addStartStopSymbols(Sec);
>>
>> Out<ELFT>::Dynamic->PreInitArraySec =
>> @@ -436,7 +436,7 @@ template <class ELFT> void Writer<ELFT>:
>> Map.lookup({".fini_array", SHT_FINI_ARRAY, SHF_WRITE | SHF_ALLOC});
>>
>> auto AddStartEnd = [&](StringRef Start, StringRef End,
>> - OutputSectionBase<ELFT::Is64Bits> *OS) {
>> + OutputSectionBase<ELFT> *OS) {
>> if (OS) {
>> Symtab.addSyntheticSym(Start, *OS, 0);
>> Symtab.addSyntheticSym(End, *OS, OS->getSize());
>> @@ -493,7 +493,7 @@ template <class ELFT> void Writer<ELFT>:
>> for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
>> OutputSections[I]->SectionIndex = I + 1;
>>
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections)
>> Out<ELFT>::StrTab->add(Sec->getName());
>>
>> // Fill the DynStrTab early because Dynamic adds strings to
>> @@ -501,7 +501,7 @@ template <class ELFT> void Writer<ELFT>:
>> Out<ELFT>::Dynamic->finalize();
>>
>> // Fill other section headers.
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections)
>> Sec->finalize();
>>
>> // If we have a .opd section (used under PPC64 for function
>> descriptors),
>> @@ -529,7 +529,7 @@ static bool isValidCIdentifier(StringRef
>> // respectively. This is not requested by the ELF standard, but GNU ld
>> and
>> // gold provide the feature, and used by many programs.
>> template <class ELFT>
>> -void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT::Is64Bits>
>> *Sec) {
>> +void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT> *Sec) {
>> StringRef S = Sec->getName();
>> if (!isValidCIdentifier(S))
>> return;
>> @@ -542,8 +542,7 @@ void Writer<ELFT>::addStartStopSymbols(O
>> Symtab.addSyntheticSym(Stop, *Sec, Sec->getSize());
>> }
>>
>> -template <class ELFT>
>> -static bool needsPhdr(OutputSectionBase<ELFT::Is64Bits> *Sec) {
>> +template <class ELFT> static bool needsPhdr(OutputSectionBase<ELFT>
>> *Sec) {
>> return Sec->getFlags() & SHF_ALLOC;
>> }
>>
>> @@ -561,7 +560,7 @@ template <class ELFT> void Writer<ELFT>:
>> if (isOutputDynamic())
>> ++NumPhdrs;
>> uintX_t Last = PF_R;
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections) {
>> if (!Sec->getSize() || !needsPhdr<ELFT>(Sec))
>> continue;
>> uintX_t Flags = toPhdrFlags(Sec->getFlags());
>> @@ -595,7 +594,7 @@ template <class ELFT> void Writer<ELFT>:
>> setPhdr(FileHeader, PT_LOAD, PF_R, 0, getVAStart(),
>> Target->getPageSize());
>>
>> SmallPtrSet<Elf_Phdr *, 8> Closed;
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections) {
>> if (Sec->getSize()) {
>> uintX_t Flags = toPhdrFlags(Sec->getFlags());
>> Elf_Phdr *Last = &Phdrs.back();
>> @@ -699,9 +698,9 @@ template <class ELFT> void Writer<ELFT>:
>> auto SHdrs = reinterpret_cast<Elf_Shdr *>(Buf + EHdr->e_shoff);
>> // First entry is null.
>> ++SHdrs;
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections) {
>> Sec->setNameOffset(Out<ELFT>::StrTab->getFileOff(Sec->getName()));
>> - Sec->template writeHeaderTo<ELFT::TargetEndianness>(SHdrs++);
>> + Sec->writeHeaderTo(SHdrs++);
>> }
>> }
>>
>> @@ -718,12 +717,12 @@ template <class ELFT> void Writer<ELFT>:
>>
>> // PPC64 needs to process relocations in the .opd section before
>> processing
>> // relocations in code-containing sections.
>> - if (OutputSectionBase<ELFT::Is64Bits> *Sec = Out<ELFT>::Opd) {
>> + if (OutputSectionBase<ELFT> *Sec = Out<ELFT>::Opd) {
>> Out<ELFT>::OpdBuf = Buf + Sec->getFileOff();
>> Sec->writeTo(Buf + Sec->getFileOff());
>> }
>>
>> - for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
>> + for (OutputSectionBase<ELFT> *Sec : OutputSections)
>> if (Sec != Out<ELFT>::Opd)
>> Sec->writeTo(Buf + Sec->getFileOff());
>> }
>> @@ -740,8 +739,7 @@ void Writer<ELFT>::setPhdr(Elf_Phdr *PH,
>> }
>>
>> template <class ELFT>
>> -void Writer<ELFT>::copyPhdr(Elf_Phdr *PH,
>> - OutputSectionBase<ELFT::Is64Bits> *From) {
>> +void Writer<ELFT>::copyPhdr(Elf_Phdr *PH, OutputSectionBase<ELFT> *From)
>> {
>> PH->p_flags = toPhdrFlags(From->getFlags());
>> PH->p_offset = From->getFileOff();
>> PH->p_vaddr = From->getVA();
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151016/b151c433/attachment.html>
More information about the llvm-commits
mailing list