diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 61b6dd42915c..310364a89e05 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -391,6 +391,13 @@ void ICF::forEachClass(std::function Fn) { ++Cnt; } +static void Print(const Twine &Prefix, InputSection *S) { + if (!Config->PrintIcfSections) + return; + std::string File = S->File ? S->File->getName() : ""; + message(Prefix + " section '" + S->Name + "' from file '" + File + "'"); +}; + // The main function of ICF. template void ICF::run() { // Collect sections to merge. @@ -424,22 +431,13 @@ template void ICF::run() { log("ICF needed " + Twine(Cnt) + " iterations"); - auto Print = [&](const Twine &Prefix, size_t I) { - if (!Config->PrintIcfSections) - return; - InputSection *S = Sections[I]; - std::string File = S->File ? S->File->getName() : ""; - message(Prefix + " section '" + S->Name + "' from file '" + File + "'"); - }; - // Merge sections by the equivalence class. forEachClassRange(0, Sections.size(), [&](size_t Begin, size_t End) { if (End - Begin == 1) return; - - Print("selected", Begin); + Print("selected", Sections[Begin]); for (size_t I = Begin + 1; I < End; ++I) { - Print(" removing identical", I); + Print(" removing identical", Sections[I]); Sections[Begin]->replace(Sections[I]); } });