Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -46,11 +46,16 @@ // SectionKind is a description of output section, like ".data :..." enum SectionsCommandKind { SectionKind, AssignmentKind }; +struct OutputSectionDescription { + std::vector Phdrs; + std::vector Filler; +}; + struct SectionsCommand { SectionsCommandKind Kind; std::vector Expr; StringRef Name; - std::vector Phdrs; + OutputSectionDescription Section; }; struct PhdrsCommand { @@ -65,9 +70,6 @@ // SECTIONS commands. std::vector Sections; - // Section fill attribute for each section. - llvm::StringMap> Filler; - // Used to assign addresses to sections. std::vector Commands; Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -402,10 +402,10 @@ template ArrayRef LinkerScript::getFiller(StringRef Name) { - auto I = Opt.Filler.find(Name); - if (I == Opt.Filler.end()) - return {}; - return I->second; + for (SectionsCommand &Cmd : Opt.Commands) + if (Cmd.Kind == SectionKind && Cmd.Name == Name) + return Cmd.Section.Filler; + return {}; } // Returns the index of the given section name in linker script @@ -455,8 +455,9 @@ if (Cmd.Kind != SectionKind || Cmd.Name != Name) continue; + OutputSectionDescription &OutSec = Cmd.Section; std::vector Indices; - for (StringRef PhdrName : Cmd.Phdrs) { + for (StringRef PhdrName : OutSec.Phdrs) { auto ItPhdr = std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(), [&](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; }); @@ -710,7 +711,7 @@ void ScriptParser::readOutputSectionDescription(StringRef OutSec) { Opt.Commands.push_back({SectionKind, {}, OutSec, {}}); - SectionsCommand &Cmd = Opt.Commands.back(); + OutputSectionDescription &S = Opt.Commands.back().Section; expect(":"); expect("{"); @@ -734,7 +735,7 @@ setError("unknown command " + Tok); } } - Cmd.Phdrs = readOutputSectionPhdrs(); + S.Phdrs = readOutputSectionPhdrs(); StringRef Tok = peek(); if (Tok.startswith("=")) { @@ -743,7 +744,7 @@ return; } Tok = Tok.substr(3); - Opt.Filler[OutSec] = parseHex(Tok); + S.Filler = parseHex(Tok); next(); } }