[lld] [lld] Merge equivalent symbols found during ICF (PR #134342)
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 16 00:34:41 PDT 2025
================
@@ -535,14 +557,35 @@ template <class ELFT> void ICF<ELFT>::run() {
auto print = [&ctx = ctx]() -> ELFSyncStream {
return {ctx, ctx.arg.printIcfSections ? DiagLevel::Msg : DiagLevel::None};
};
+
+ DenseMap<Symbol *, Symbol *> symbolMap;
// Merge sections by the equivalence class.
+ // Merge symbols identified as equivalent during ICF
forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) {
if (end - begin == 1)
return;
print() << "selected section " << sections[begin];
+ SmallVector<Symbol *> syms = getRelocTargetSyms<ELFT>(sections[begin]);
for (size_t i = begin + 1; i < end; ++i) {
print() << " removing identical section " << sections[i];
sections[begin]->replace(sections[i]);
+ SmallVector<Symbol *> replacedSyms =
+ getRelocTargetSyms<ELFT>(sections[i]);
+ assert(syms.size() == replacedSyms.size() &&
+ "Should have same number of syms!");
+ for (size_t i = 0; i < syms.size(); i++) {
+ if (syms[i] == replacedSyms[i] || !syms[i]->isGlobal() ||
+ !replacedSyms[i]->isGlobal())
+ continue;
+ auto [it, inserted] =
----------------
jyknight wrote:
Oh, nice! I didn't know we had that data structure. I couldn't really tell by inspection, but I assume the new test code you added would've failed before this change to use EquivalenceClasses?
https://github.com/llvm/llvm-project/pull/134342
More information about the llvm-commits
mailing list