[lld] [lld-macho] Relax safe ICF's keepUnique for ld64-coalesced data sections (PR #193125)
Zhaoxuan Jiang via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 05:29:24 PDT 2026
================
@@ -583,19 +583,29 @@ void macho::foldIdenticalSections(bool onlyCfStrings) {
bool isCodeSec = isCodeSection(isec);
- // When keepUnique is true, the section is not foldable. Unless we are at
- // icf level safe_thunks, in which case we still want to fold code sections.
- // When using safe_thunks we'll apply the safe_thunks logic at merge time
- // based on the 'keepUnique' flag.
- bool noUniqueRequirement =
- !isec->keepUnique ||
- ((config->icfLevel == ICFLevel::safe_thunks) && isCodeSec);
+ // Determine whether keepUnique forbids folding this section.
+ // - __cfstring / __objc_classrefs / __objc_selrefs always fold
+ // regardless of keepUnique. Compilers currently emit over-broad
+ // __llvm_addrsig entries that can cover non-address-significant data
+ // symbols in these sections; ld64 coalesces them unconditionally, and
+ // we match that behavior.
+ // - Under safe_thunks, keepUnique code sections still fold; the
+ // safe_thunks logic is applied later at merge time based on the
+ // keepUnique flag.
+ // - Otherwise, keepUnique sections are not foldable.
+ bool isUnconditionallyCoalescedData = isCfStringSection(isec) ||
+ isClassRefsSection(isec) ||
+ isSelRefsSection(isec);
----------------
nocchijiang wrote:
Sorry, I jumped to a conclusion too early. On a closer look `__objc_protolist` / `__objc_protorefs` aren't in ICF's scope, so the two lists don't diverge after all. Applied your suggestion with a short comment noting that the two may diverge in the future so readers know it's safe to change.
https://github.com/llvm/llvm-project/pull/193125
More information about the llvm-commits
mailing list