#35197 guix: add -Wl,--icf=safe to darwin build

full analysis

https://github.com/bitcoin/bitcoin/pull/35197 · fanquake · +5/-0 in 1 files, 1 commits · labels: Build system

Goal

  • Shrink macOS release binary sizes and disk footprint by eliminating duplicate code

This pull request adds linker flags to CMakeLists.txt to attempt safe identical code folding (-Wl,--icf=safe_thunks and -Wl,--icf=safe). The change targets macOS binaries built with lld to eliminate duplicate function bodies and reduce final binary sizes.

Problem: Release binaries for macOS contain duplicate identical function code across template instantiations and small helpers, increasing download size and disk footprint for macOS users.

Category: Build and CI (#14 of 55)

P3 · speedup

  • P3 because shrinking macOS binaries by roughly 5% is a modest, deferrable optimization
  • The reduction saves download bandwidth and disk space for macOS users
  • It does not fix bugs, enhance security, or unblock other development

A 5% reduction in release binary sizes (around 0.5 MB for bitcoind and 1.3 MB for bitcoin-qt) is a clear, measured benefit for download distribution and disk footprint on macOS. However, binary size reduction is deferrable optimization work that does not fix a bug, improve security, or unblock other development.

Membership: Modifies CMakeLists.txt linker flags for Darwin Guix release builds.

Factors: security/stability 0, bug 0, performance 1, user value 1, leverage 0

Reviewability: Paused: Waiting on author

  • Waiting on author to address missing compiler flags and probe ordering
  • Reviewing the current code is paused until the author updates the patch

Reviewers proved that -Wl,--icf=safe unsafely folds address-taken functions on Darwin unless -faddrsig is passed during compilation. Reviewing the current patch is unhelpful until the author addresses the toolchain flags and probe order.

Author status: silent since 2026-08-10 after opening an upstream LLVM documentation PR

Open concerns:

  • On Mach-O targets with LLVM 19, -Wl,--icf=safe without -faddrsig folds address-significant functions, breaking C++ function pointer uniqueness invariants (Sjors, 151henry151).
  • Enabling true safe folding requires adding -faddrsig to Darwin compilation flags across core and depends (151henry151).
  • Probe order in CMakeLists.txt will cause safe to override safe_thunks on toolchains supporting both (hebasto, 151henry151).

Resolved concerns:

  • Moving the linker probe from REDUCE_EXPORTS into general linker flags (theuni, fanquake).

Agreement: Disputed

  • Broad agreement on shrinking binary sizes with identical code folding
  • Verified roughly 5% size reduction in Darwin builds (davidgumberg)
  • Unaddressed objection: breaks function pointer uniqueness without extra flags (Sjors, 151henry151)
  • Probe order causes the linker to override safer settings (hebasto, 151henry151)

Disputed: safe ICF requires -faddrsig on Darwin to avoid folding address-taken functions (151henry151, hebasto, Sjors)

There is clear concept agreement on ICF to reduce binary size, but reviewers have withheld approval because the current implementation behaves identically to unsafe ICF on Mach-O without -faddrsig. The author acknowledged the issue upstream but has not updated the PR.

  • davidgumberg ACKed an earlier revision with Guix benchmark data showing ~5% size savings
  • Sjors provided a reproducer demonstrating function pointer comparison failures when address-significant folding occurs
  • 151henry151 reviewed at 24ad7419de stating 'Not an ACK in its current shape' and showed that adding -faddrsig preserves almost all size savings while preventing incorrect symbol collisions
  • hebasto agreed that -faddrsig must be enabled explicitly for macOS targets and noted the probe order issue

Review verdicts (DrahtBot): 0 (+1)

Files

0 lines under test/bench/ci.

  • CMakeLists.txt +5/-0

Card

This pull request configures linker identical code folding in CMakeLists.txt to reduce Darwin release binary sizes by approximately 5%. The change benefits macOS users by reducing download and installation sizes. While reviewers support the size reduction in concept, investigation by reviewers revealed that the current patch folds address-taken functions on Darwin without the -faddrsig compiler flag, causing subtle runtime correctness issues. The PR is currently paused waiting on the author to incorporate the necessary compiler flags and fix the linker probe ordering.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T16:19, confidence high, input hash 6ae5e8d2e15552af