diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 606953e94bba..80ddc3c32cf5 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -459,11 +459,6 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec, isec->eqClass[(cnt + 1) % 2] = hash | (1U << 31); } -static void print(Ctx &ctx, const Twine &s) { - if (ctx.arg.printIcfSections) - Msg(ctx) << s; -} - // The main function of ICF. template void ICF::run() { // Compute isPreemptible early. We may add more symbols later, so this loop @@ -544,13 +539,16 @@ template void ICF::run() { Log(ctx) << "ICF needed " << cnt << " iterations"; + auto print = [&ctx = ctx]() -> ELFSyncStream { + return {ctx, ctx.arg.printIcfSections ? DiagLevel::Msg : DiagLevel::None}; + }; // Merge sections by the equivalence class. forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) { if (end - begin == 1) return; - print(ctx, "selected section " + toStr(ctx, sections[begin])); + print() << "selected section " << sections[begin]; for (size_t i = begin + 1; i < end; ++i) { - print(ctx, " removing identical section " + toStr(ctx, sections[i])); + print() << " removing identical section " << sections[i]; sections[begin]->replace(sections[i]); // At this point we know sections merged are fully identical and hence