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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 17 21:59:05 PDT 2025


================
@@ -352,6 +407,15 @@ bool ICF<ELFT>::variableEq(const InputSection *secA, Relocs<RelTy> ra,
     auto *da = cast<Defined>(&sa);
     auto *db = cast<Defined>(&sb);
 
+    // Prevent sections containing local symbols from merging into sections with
+    // global symbols, or vice-versa. This is to prevent local-global symbols
+    // getting merged into each other (done later in ICF). We do this as
+    // post-ICF passes cannot handle duplicates when iterating over local
+    // symbols. There are also assertions that prevent this.
+    if ((!da->isGlobal() || !db->isGlobal()) &&
----------------
MaskRay wrote:

No test seems to cover this block . Actually I don't understand why we need this check (https://github.com/llvm/llvm-project/pull/134342#discussion_r2044177042). If we merge two sections, symbols defined relative to them, even if global, can be merged as well, regardless whether there are GOT/TLS relocations.

If we delete the `isTrivialRelocation` check from #136641 , we can get rid of the OffsetGetter complexity.

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


More information about the llvm-commits mailing list