Create Out members using make() to simplify.

llvm-svn: 285764
This commit is contained in:
Rui Ueyama 2016-11-01 23:12:51 +00:00
parent 95642b95bd
commit cfadbd9478
2 changed files with 51 additions and 92 deletions

View File

@ -741,6 +741,8 @@ private:
template <class ELFT> struct Out {
typedef typename ELFT::uint uintX_t;
typedef typename ELFT::Phdr Elf_Phdr;
static uint8_t First;
static DynamicSection<ELFT> *Dynamic;
static EhFrameHeader<ELFT> *EhFrameHdr;
static EhOutputSection<ELFT> *EhFrame;
@ -769,7 +771,6 @@ template <class ELFT> struct Out {
static OutputSectionBase<ELFT> *DebugInfo;
static OutputSectionBase<ELFT> *ElfHeader;
static OutputSectionBase<ELFT> *ProgramHeaders;
static OutputSectionBase<ELFT> *PreinitArray;
static OutputSectionBase<ELFT> *InitArray;
static OutputSectionBase<ELFT> *FiniArray;
@ -808,6 +809,7 @@ template <class ELFT> uint64_t getHeaderSize() {
return Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
}
template <class ELFT> uint8_t Out<ELFT>::First;
template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame;

View File

@ -129,122 +129,79 @@ template <class ELFT> void elf::writeResult() {
typedef typename ELFT::uint uintX_t;
typedef typename ELFT::Ehdr Elf_Ehdr;
// Initialize all pointers with NULL.
memset(&Out<ELFT>::First, 0, sizeof(Out<ELFT>));
// Create singleton output sections.
OutputSection<ELFT> Bss(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
DynamicSection<ELFT> Dynamic;
EhOutputSection<ELFT> EhFrame;
GotSection<ELFT> Got;
PltSection<ELFT> Plt;
RelocationSection<ELFT> RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn",
Config->ZCombreloc);
StringTableSection<ELFT> ShStrTab(".shstrtab", false);
VersionTableSection<ELFT> VerSym;
VersionNeedSection<ELFT> VerNeed;
Out<ELFT>::Bss =
make<OutputSection<ELFT>>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
Out<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
Out<ELFT>::EhFrame = make<EhOutputSection<ELFT>>();
Out<ELFT>::Got = make<GotSection<ELFT>>();
Out<ELFT>::Plt = make<PltSection<ELFT>>();
Out<ELFT>::RelaDyn = make<RelocationSection<ELFT>>(
Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
Out<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false);
Out<ELFT>::VerSym = make<VersionTableSection<ELFT>>();
Out<ELFT>::VerNeed = make<VersionNeedSection<ELFT>>();
OutputSectionBase<ELFT> ElfHeader("", 0, SHF_ALLOC);
ElfHeader.setSize(sizeof(Elf_Ehdr));
OutputSectionBase<ELFT> ProgramHeaders("", 0, SHF_ALLOC);
ProgramHeaders.updateAlignment(sizeof(uintX_t));
// Instantiate optional output sections if they are needed.
std::unique_ptr<InterpSection<ELFT>> Interp;
std::unique_ptr<BuildIdSection<ELFT>> BuildId;
std::unique_ptr<StringTableSection<ELFT>> DynStrTab;
std::unique_ptr<SymbolTableSection<ELFT>> DynSymTab;
std::unique_ptr<EhFrameHeader<ELFT>> EhFrameHdr;
std::unique_ptr<GdbIndexSection<ELFT>> GdbIndex;
std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab;
std::unique_ptr<GotPltSection<ELFT>> GotPlt;
std::unique_ptr<HashTableSection<ELFT>> HashTab;
std::unique_ptr<RelocationSection<ELFT>> RelaPlt;
std::unique_ptr<StringTableSection<ELFT>> StrTab;
std::unique_ptr<SymbolTableSection<ELFT>> SymTabSec;
std::unique_ptr<OutputSection<ELFT>> MipsRldMap;
std::unique_ptr<VersionDefinitionSection<ELFT>> VerDef;
Out<ELFT>::ElfHeader = make<OutputSectionBase<ELFT>>("", 0, SHF_ALLOC);
Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
Out<ELFT>::ProgramHeaders = make<OutputSectionBase<ELFT>>("", 0, SHF_ALLOC);
Out<ELFT>::ProgramHeaders->updateAlignment(sizeof(uintX_t));
if (needsInterpSection<ELFT>())
Interp.reset(new InterpSection<ELFT>);
if (Config->BuildId == BuildIdKind::Fast)
BuildId.reset(new BuildIdFastHash<ELFT>);
else if (Config->BuildId == BuildIdKind::Md5)
BuildId.reset(new BuildIdMd5<ELFT>);
else if (Config->BuildId == BuildIdKind::Sha1)
BuildId.reset(new BuildIdSha1<ELFT>);
else if (Config->BuildId == BuildIdKind::Uuid)
BuildId.reset(new BuildIdUuid<ELFT>);
else if (Config->BuildId == BuildIdKind::Hexstring)
BuildId.reset(new BuildIdHexstring<ELFT>);
Out<ELFT>::Interp = make<InterpSection<ELFT>>();
if (!Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic) {
DynStrTab.reset(new StringTableSection<ELFT>(".dynstr", true));
DynSymTab.reset(new SymbolTableSection<ELFT>(*DynStrTab));
Out<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
Out<ELFT>::DynSymTab =
make<SymbolTableSection<ELFT>>(*Out<ELFT>::DynStrTab);
}
if (Config->EhFrameHdr)
EhFrameHdr.reset(new EhFrameHeader<ELFT>);
Out<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>();
if (Config->GnuHash)
GnuHashTab.reset(new GnuHashTableSection<ELFT>);
Out<ELFT>::GnuHashTab = make<GnuHashTableSection<ELFT>>();
if (Config->SysvHash)
HashTab.reset(new HashTableSection<ELFT>);
Out<ELFT>::HashTab = make<HashTableSection<ELFT>>();
if (Config->GdbIndex)
GdbIndex.reset(new GdbIndexSection<ELFT>);
Out<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>();
StringRef S = Config->Rela ? ".rela.plt" : ".rel.plt";
GotPlt.reset(new GotPltSection<ELFT>);
RelaPlt.reset(new RelocationSection<ELFT>(S, false /*Sort*/));
Out<ELFT>::GotPlt = make<GotPltSection<ELFT>>();
Out<ELFT>::RelaPlt = make<RelocationSection<ELFT>>(S, false /*Sort*/);
if (Config->Strip != StripPolicy::All) {
StrTab.reset(new StringTableSection<ELFT>(".strtab", false));
SymTabSec.reset(new SymbolTableSection<ELFT>(*StrTab));
Out<ELFT>::StrTab = make<StringTableSection<ELFT>>(".strtab", false);
Out<ELFT>::SymTab = make<SymbolTableSection<ELFT>>(*Out<ELFT>::StrTab);
}
if (Config->EMachine == EM_MIPS && !Config->Shared) {
// This is a MIPS specific section to hold a space within the data segment
// of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
// See "Dynamic section" in Chapter 5 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
MipsRldMap.reset(new OutputSection<ELFT>(".rld_map", SHT_PROGBITS,
SHF_ALLOC | SHF_WRITE));
MipsRldMap->setSize(sizeof(uintX_t));
MipsRldMap->updateAlignment(sizeof(uintX_t));
Out<ELFT>::MipsRldMap = make<OutputSection<ELFT>>(".rld_map", SHT_PROGBITS,
SHF_ALLOC | SHF_WRITE);
Out<ELFT>::MipsRldMap->setSize(sizeof(uintX_t));
Out<ELFT>::MipsRldMap->updateAlignment(sizeof(uintX_t));
}
if (!Config->VersionDefinitions.empty())
VerDef.reset(new VersionDefinitionSection<ELFT>());
Out<ELFT>::Bss = &Bss;
Out<ELFT>::DynStrTab = DynStrTab.get();
Out<ELFT>::DynSymTab = DynSymTab.get();
Out<ELFT>::Dynamic = &Dynamic;
Out<ELFT>::EhFrame = &EhFrame;
Out<ELFT>::EhFrameHdr = EhFrameHdr.get();
Out<ELFT>::GdbIndex = GdbIndex.get();
Out<ELFT>::GnuHashTab = GnuHashTab.get();
Out<ELFT>::Got = &Got;
Out<ELFT>::GotPlt = GotPlt.get();
Out<ELFT>::HashTab = HashTab.get();
Out<ELFT>::Interp = Interp.get();
Out<ELFT>::Plt = &Plt;
Out<ELFT>::RelaDyn = &RelaDyn;
Out<ELFT>::RelaPlt = RelaPlt.get();
Out<ELFT>::ShStrTab = &ShStrTab;
Out<ELFT>::StrTab = StrTab.get();
Out<ELFT>::SymTab = SymTabSec.get();
Out<ELFT>::VerDef = VerDef.get();
Out<ELFT>::VerSym = &VerSym;
Out<ELFT>::VerNeed = &VerNeed;
Out<ELFT>::MipsRldMap = MipsRldMap.get();
Out<ELFT>::Opd = nullptr;
Out<ELFT>::OpdBuf = nullptr;
Out<ELFT>::TlsPhdr = nullptr;
Out<ELFT>::ElfHeader = &ElfHeader;
Out<ELFT>::ProgramHeaders = &ProgramHeaders;
Out<ELFT>::PreinitArray = nullptr;
Out<ELFT>::InitArray = nullptr;
Out<ELFT>::FiniArray = nullptr;
Out<ELFT>::VerDef = make<VersionDefinitionSection<ELFT>>();
// Initialize linker generated sections
In<ELFT>::BuildId = BuildId.get();
In<ELFT>::Sections = {BuildId.get()};
if (Config->BuildId == BuildIdKind::Fast)
In<ELFT>::BuildId = make<BuildIdFastHash<ELFT>>();
else if (Config->BuildId == BuildIdKind::Md5)
In<ELFT>::BuildId = make<BuildIdMd5<ELFT>>();
else if (Config->BuildId == BuildIdKind::Sha1)
In<ELFT>::BuildId = make<BuildIdSha1<ELFT>>();
else if (Config->BuildId == BuildIdKind::Uuid)
In<ELFT>::BuildId = make<BuildIdUuid<ELFT>>();
else if (Config->BuildId == BuildIdKind::Hexstring)
In<ELFT>::BuildId = make<BuildIdHexstring<ELFT>>();
In<ELFT>::Sections = {In<ELFT>::BuildId};
Writer<ELFT>().run();
}