Skip to content

Commit 10b9847

Browse files
committed
[ELF] Simplify --print-icf-sections
1 parent 58389b2 commit 10b9847

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lld/ELF/ICF.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,6 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec,
459459
isec->eqClass[(cnt + 1) % 2] = hash | (1U << 31);
460460
}
461461

462-
static void print(Ctx &ctx, const Twine &s) {
463-
if (ctx.arg.printIcfSections)
464-
Msg(ctx) << s;
465-
}
466-
467462
// The main function of ICF.
468463
template <class ELFT> void ICF<ELFT>::run() {
469464
// Compute isPreemptible early. We may add more symbols later, so this loop
@@ -544,13 +539,16 @@ template <class ELFT> void ICF<ELFT>::run() {
544539

545540
Log(ctx) << "ICF needed " << cnt << " iterations";
546541

542+
auto print = [&ctx = ctx]() -> ELFSyncStream {
543+
return {ctx, ctx.arg.printIcfSections ? DiagLevel::Msg : DiagLevel::None};
544+
};
547545
// Merge sections by the equivalence class.
548546
forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) {
549547
if (end - begin == 1)
550548
return;
551-
print(ctx, "selected section " + toStr(ctx, sections[begin]));
549+
print() << "selected section " << sections[begin];
552550
for (size_t i = begin + 1; i < end; ++i) {
553-
print(ctx, " removing identical section " + toStr(ctx, sections[i]));
551+
print() << " removing identical section " << sections[i];
554552
sections[begin]->replace(sections[i]);
555553

556554
// At this point we know sections merged are fully identical and hence

0 commit comments

Comments
 (0)