[lld] [lld] Merge equivalent symbols found during ICF (PR #134342)
Pranav Kant via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 15 10:58:16 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] =
----------------
pranavk wrote:
Ah, I recall discussing this offline but forgot to take care of it in the implementation. Let me see what I can do here.
https://github.com/llvm/llvm-project/pull/134342
More information about the llvm-commits
mailing list