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,14 @@ 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); - + Ret.emplace_back(Cmd1->Name, Cmd1->Commands); return Ret; } @@ -138,14 +131,19 @@ 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); + for (const std::unique_ptr &Cmd : P.second) { + auto *InCmd = dyn_cast(Cmd.get()); + if (!InCmd) continue; + + for (InputSectionBase *S : getInputSections(InCmd)) { + if (OutputName == "/DISCARD/") { + S->Live = false; + reportDiscarded(S); + continue; + } + Add(S, OutputName); } - Add(S, OutputName); } }