Use a utility function to reduce repetition. NFC.

llvm-svn: 294117
This commit is contained in:
Rui Ueyama 2017-02-05 05:18:58 +00:00
parent f1fe87e605
commit 7ddd7a8b76
1 changed files with 34 additions and 30 deletions

View File

@ -301,6 +301,10 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
// you can call lld::elf::main more than once as a library. // you can call lld::elf::main more than once as a library.
memset(&Out<ELFT>::First, 0, sizeof(Out<ELFT>)); memset(&Out<ELFT>::First, 0, sizeof(Out<ELFT>));
auto Add = [](InputSectionBase<ELFT> *Sec) {
Symtab<ELFT>::X->Sections.push_back(Sec);
};
// Create singleton output sections. // Create singleton output sections.
Out<ELFT>::Bss = Out<ELFT>::Bss =
make<OutputSection<ELFT>>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); make<OutputSection<ELFT>>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
@ -320,13 +324,13 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
if (needsInterpSection<ELFT>()) { if (needsInterpSection<ELFT>()) {
In<ELFT>::Interp = createInterpSection<ELFT>(); In<ELFT>::Interp = createInterpSection<ELFT>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::Interp); Add(In<ELFT>::Interp);
} else { } else {
In<ELFT>::Interp = nullptr; In<ELFT>::Interp = nullptr;
} }
if (!Config->Relocatable) if (!Config->Relocatable)
Symtab<ELFT>::X->Sections.push_back(createCommentSection<ELFT>()); Add(createCommentSection<ELFT>());
if (Config->Strip != StripPolicy::All) { if (Config->Strip != StripPolicy::All) {
In<ELFT>::StrTab = make<StringTableSection<ELFT>>(".strtab", false); In<ELFT>::StrTab = make<StringTableSection<ELFT>>(".strtab", false);
@ -335,13 +339,13 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
if (Config->BuildId != BuildIdKind::None) { if (Config->BuildId != BuildIdKind::None) {
In<ELFT>::BuildId = make<BuildIdSection<ELFT>>(); In<ELFT>::BuildId = make<BuildIdSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::BuildId); Add(In<ELFT>::BuildId);
} }
InputSection<ELFT> *Common = createCommonSection<ELFT>(); InputSection<ELFT> *Common = createCommonSection<ELFT>();
if (!Common->Data.empty()) { if (!Common->Data.empty()) {
In<ELFT>::Common = Common; In<ELFT>::Common = Common;
Symtab<ELFT>::X->Sections.push_back(Common); Add(Common);
} }
// Add MIPS-specific sections. // Add MIPS-specific sections.
@ -349,94 +353,94 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
if (Config->EMachine == EM_MIPS) { if (Config->EMachine == EM_MIPS) {
if (!Config->Shared && HasDynSymTab) { if (!Config->Shared && HasDynSymTab) {
In<ELFT>::MipsRldMap = make<MipsRldMapSection<ELFT>>(); In<ELFT>::MipsRldMap = make<MipsRldMapSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::MipsRldMap); Add(In<ELFT>::MipsRldMap);
} }
if (auto *Sec = MipsAbiFlagsSection<ELFT>::create()) if (auto *Sec = MipsAbiFlagsSection<ELFT>::create())
Symtab<ELFT>::X->Sections.push_back(Sec); Add(Sec);
if (auto *Sec = MipsOptionsSection<ELFT>::create()) if (auto *Sec = MipsOptionsSection<ELFT>::create())
Symtab<ELFT>::X->Sections.push_back(Sec); Add(Sec);
if (auto *Sec = MipsReginfoSection<ELFT>::create()) if (auto *Sec = MipsReginfoSection<ELFT>::create())
Symtab<ELFT>::X->Sections.push_back(Sec); Add(Sec);
} }
if (HasDynSymTab) { if (HasDynSymTab) {
In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::DynStrTab); In<ELFT>::DynSymTab = make<SymbolTableSection<ELFT>>(*In<ELFT>::DynStrTab);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::DynSymTab); Add(In<ELFT>::DynSymTab);
In<ELFT>::VerSym = make<VersionTableSection<ELFT>>(); In<ELFT>::VerSym = make<VersionTableSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::VerSym); Add(In<ELFT>::VerSym);
if (!Config->VersionDefinitions.empty()) { if (!Config->VersionDefinitions.empty()) {
In<ELFT>::VerDef = make<VersionDefinitionSection<ELFT>>(); In<ELFT>::VerDef = make<VersionDefinitionSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::VerDef); Add(In<ELFT>::VerDef);
} }
In<ELFT>::VerNeed = make<VersionNeedSection<ELFT>>(); In<ELFT>::VerNeed = make<VersionNeedSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::VerNeed); Add(In<ELFT>::VerNeed);
if (Config->GnuHash) { if (Config->GnuHash) {
In<ELFT>::GnuHashTab = make<GnuHashTableSection<ELFT>>(); In<ELFT>::GnuHashTab = make<GnuHashTableSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::GnuHashTab); Add(In<ELFT>::GnuHashTab);
} }
if (Config->SysvHash) { if (Config->SysvHash) {
In<ELFT>::HashTab = make<HashTableSection<ELFT>>(); In<ELFT>::HashTab = make<HashTableSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::HashTab); Add(In<ELFT>::HashTab);
} }
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::Dynamic); Add(In<ELFT>::Dynamic);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::DynStrTab); Add(In<ELFT>::DynStrTab);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::RelaDyn); Add(In<ELFT>::RelaDyn);
} }
// Add .got. MIPS' .got is so different from the other archs, // Add .got. MIPS' .got is so different from the other archs,
// it has its own class. // it has its own class.
if (Config->EMachine == EM_MIPS) { if (Config->EMachine == EM_MIPS) {
In<ELFT>::MipsGot = make<MipsGotSection<ELFT>>(); In<ELFT>::MipsGot = make<MipsGotSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::MipsGot); Add(In<ELFT>::MipsGot);
} else { } else {
In<ELFT>::Got = make<GotSection<ELFT>>(); In<ELFT>::Got = make<GotSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::Got); Add(In<ELFT>::Got);
} }
In<ELFT>::GotPlt = make<GotPltSection<ELFT>>(); In<ELFT>::GotPlt = make<GotPltSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::GotPlt); Add(In<ELFT>::GotPlt);
In<ELFT>::IgotPlt = make<IgotPltSection<ELFT>>(); In<ELFT>::IgotPlt = make<IgotPltSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::IgotPlt); Add(In<ELFT>::IgotPlt);
if (Config->GdbIndex) { if (Config->GdbIndex) {
In<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>(); In<ELFT>::GdbIndex = make<GdbIndexSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::GdbIndex); Add(In<ELFT>::GdbIndex);
} }
// We always need to add rel[a].plt to output if it has entries. // We always need to add rel[a].plt to output if it has entries.
// Even for static linking it can contain R_[*]_IRELATIVE relocations. // Even for static linking it can contain R_[*]_IRELATIVE relocations.
In<ELFT>::RelaPlt = make<RelocationSection<ELFT>>( In<ELFT>::RelaPlt = make<RelocationSection<ELFT>>(
Config->Rela ? ".rela.plt" : ".rel.plt", false /*Sort*/); Config->Rela ? ".rela.plt" : ".rel.plt", false /*Sort*/);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::RelaPlt); Add(In<ELFT>::RelaPlt);
// The RelaIplt immediately follows .rel.plt (.rel.dyn for ARM) to ensure // The RelaIplt immediately follows .rel.plt (.rel.dyn for ARM) to ensure
// that the IRelative relocations are processed last by the dynamic loader // that the IRelative relocations are processed last by the dynamic loader
In<ELFT>::RelaIplt = make<RelocationSection<ELFT>>( In<ELFT>::RelaIplt = make<RelocationSection<ELFT>>(
(Config->EMachine == EM_ARM) ? ".rel.dyn" : In<ELFT>::RelaPlt->Name, (Config->EMachine == EM_ARM) ? ".rel.dyn" : In<ELFT>::RelaPlt->Name,
false /*Sort*/); false /*Sort*/);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::RelaIplt); Add(In<ELFT>::RelaIplt);
In<ELFT>::Plt = make<PltSection<ELFT>>(); In<ELFT>::Plt = make<PltSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::Plt); Add(In<ELFT>::Plt);
In<ELFT>::Iplt = make<IpltSection<ELFT>>(); In<ELFT>::Iplt = make<IpltSection<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::Iplt); Add(In<ELFT>::Iplt);
if (Config->EhFrameHdr) { if (Config->EhFrameHdr) {
In<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>(); In<ELFT>::EhFrameHdr = make<EhFrameHeader<ELFT>>();
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::EhFrameHdr); Add(In<ELFT>::EhFrameHdr);
} }
if (In<ELFT>::SymTab) if (In<ELFT>::SymTab)
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::SymTab); Add(In<ELFT>::SymTab);
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::ShStrTab); Add(In<ELFT>::ShStrTab);
if (In<ELFT>::StrTab) if (In<ELFT>::StrTab)
Symtab<ELFT>::X->Sections.push_back(In<ELFT>::StrTab); Add(In<ELFT>::StrTab);
} }
template <class ELFT> template <class ELFT>