[lld] [lld-macho] Make safe ICF conservative without __llvm_addrsig (PR #188400)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 19:58:13 PDT 2026
alx32 wrote:
Yes, a linker-side fix is preferable here. I'd have `markSymAsAddrSig` only set `keepUnique` when the symbol is in a code section.
In lld-macho today, `keepUnique` is only consumed inside `ICF.cpp`, and within it `equalsConstant` already only consults `keepUnique` on code sections, so gating `markSymAsAddrSig` on `isCodeSection` so both setting and consuming of keepUnique end up scoped to code sections. The non-code sections `foldIdenticalSections` will ever fold are `__cfstring`, `__objc_classrefs`, `__objc_selrefs`, and `__gcc_except_tab` (and in practice the compiler only emits addrsig entries into the first three), all of which ld64 either unconditionally coalesces or isn't user-addressable, so dropping `keepUnique` on them is safe and matches ld64's behavior.
It also matches the documentation: `--icf=safe` / `--icf=safe_thunks` are both described in terms of folding *functions* as defined by `__addrsig`, so scoping addrsig handling to code is consistent with what the flags promise.
https://github.com/llvm/llvm-project/pull/188400
More information about the llvm-commits
mailing list