[lld] [lld][ICF] Don't merge symbols with different addends (PR #139493)

Pranav Kant via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 14:03:55 PDT 2025


================
@@ -287,7 +287,11 @@ bool ICF<ELFT>::constantEq(const InputSection *secA, Relocs<RelTy> ra,
     // Relocations referring to InputSections are constant-equal if their
     // section offsets are equal.
     if (isa<InputSection>(da->section)) {
-      if (da->value + addA == db->value + addB)
+      // Our symbol folding logic later merges symbols in two folded sections
+      // We should not merge sections in the first place if their symbols 
+      // cannot be merged together.
+      bool canMergeSymbols = addA == addB;
+      if (da->value + addA == db->value + addB && canMergeSymbols)
----------------
pranavk wrote:

i can simplify this condition too but i think this is more readable in its current form.

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


More information about the llvm-commits mailing list