Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -141,7 +141,7 @@ bool hasPhdrsCommands(); private: - std::vector> + std::vector>> getSectionMap(); std::vector *> Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -74,21 +74,19 @@ return false; } -// Create a vector of (, ). -// For example, if a returned vector contains (".text" (".foo.*" ".bar.*")), -// input sections start with ".foo." or ".bar." should be added to -// ".text" section. +// Create a vector of (, list of ). template -std::vector> +std::vector>> LinkerScript::getSectionMap() { - std::vector> Ret; - + std::vector>> Ret; for (const std::unique_ptr &Base1 : Opt.Commands) - if (auto *Cmd1 = dyn_cast(Base1.get())) - for (const std::unique_ptr &Base2 : Cmd1->Commands) - if (auto *Cmd2 = dyn_cast(Base2.get())) - Ret.emplace_back(Cmd1->Name, Cmd2); - + if (auto *Cmd1 = dyn_cast(Base1.get())) { + std::vector Commands; + for (const std::unique_ptr &Cmd : Cmd1->Commands) + if (auto *InCmd = dyn_cast(Cmd.get())) + Commands.push_back(InCmd); + Ret.emplace_back(Cmd1->Name, std::move(Commands)); + } return Ret; } @@ -138,14 +136,15 @@ for (auto &P : getSectionMap()) { StringRef OutputName = P.first; - const InputSectionDescription *I = P.second; - for (InputSectionBase *S : getInputSections(I)) { - if (OutputName == "/DISCARD/") { - S->Live = false; - reportDiscarded(S); - continue; + for (InputSectionDescription *InCmd : P.second) { + for (InputSectionBase *S : getInputSections(InCmd)) { + if (OutputName == "/DISCARD/") { + S->Live = false; + reportDiscarded(S); + continue; + } + Add(S, OutputName); } - Add(S, OutputName); } }