[ELF] Simplify --print-icf-sections

This commit is contained in:
Fangrui Song
2024-11-29 18:26:29 -08:00
parent 58389b220a
commit 10b98473e8

View File

@@ -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 <class ELFT> void ICF<ELFT>::run() {
// Compute isPreemptible early. We may add more symbols later, so this loop
@@ -544,13 +539,16 @@ template <class ELFT> void ICF<ELFT>::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