[lld] [lld] Merge equivalent symbols found during ICF (PR #134342)

Pranav Kant via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 3 21:03:13 PDT 2025


================
@@ -561,11 +604,17 @@ template <class ELFT> void ICF<ELFT>::run() {
           d->folded = true;
         }
   };
-  for (Symbol *sym : ctx.symtab->getSymbols())
+  for (Symbol *sym : ctx.symtab->getSymbols()) {
     fold(sym);
+    if (Symbol *s = symbolMap.lookup(sym))
+      ctx.symtab->redirect(sym, s);
+  }
   parallelForEach(ctx.objectFiles, [&](ELFFileBase *file) {
     for (Symbol *sym : file->getLocalSymbols())
       fold(sym);
+    for (Symbol *&sym : file->getMutableGlobalSymbols())
+      if (Symbol *s = symbolMap.lookup(sym))
----------------
pranavk wrote:

@MaskRay Input file symbols are replaced here.
In addition, we also replace symbols in symbol table few lines above.

https://github.com/llvm/llvm-project/pull/134342


More information about the llvm-commits mailing list