Index: ELF/LinkerScript.h =================================================================== --- ELF/LinkerScript.h +++ ELF/LinkerScript.h @@ -133,9 +133,6 @@ bool hasPhdrsCommands(); private: - std::vector> - getSectionMap(); - std::vector *> getInputSections(const InputSectionDescription *); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -74,24 +74,6 @@ 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. -template -std::vector> -LinkerScript::getSectionMap() { - 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); - - return Ret; -} - // Returns input sections filtered by given glob patterns. template std::vector *> @@ -125,16 +107,22 @@ Sec->addSection(C); }; - 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 (const std::unique_ptr &Base1 : Opt.Commands) { + if (auto *OutCmd = dyn_cast(Base1.get())) { + for (const std::unique_ptr &Base2 : OutCmd->Commands) { + auto *InCmd = dyn_cast(Base2.get()); + if (!InCmd) + continue; + + for (InputSectionBase *S : getInputSections(InCmd)) { + if (OutCmd->Name == "/DISCARD/") { + S->Live = false; + reportDiscarded(S); + continue; + } + Add(S, OutCmd->Name); + } } - Add(S, OutputName); } }