Skip to content

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Dec 13, 2023

This reduces the size of the binary by ~1% when building with --enable-reduce-exports.

-no_exported_symbols
Useful for main executable that don't have plugins and thus need no symbol exports.

Can be tested with dyld_info -exports src/bitcoind. The only exported symbol should be __mh_execute_header.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 13, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theuni, hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@fanquake fanquake mentioned this pull request Dec 13, 2023
@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from b9ec822 to 5f1113a Compare December 18, 2023 13:34
@DrahtBot
Copy link
Contributor

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit 2cecbbb
(master)
commit 1fe6fcc
(master and this pull)
SHA256SUMS.part 1f368fc0b919a15b... 24a9fae739fcac48...
*-aarch64-linux-gnu-debug.tar.gz 315e735a62f72596... 80dda329c1f454f5...
*-aarch64-linux-gnu.tar.gz 23e8c5a190f24aae... a68620e9f80a2522...
*-arm-linux-gnueabihf-debug.tar.gz 0d547828cc41009b... c7c155e5816764e2...
*-arm-linux-gnueabihf.tar.gz cbf6968c09b7f976... adf23f8418237033...
*-arm64-apple-darwin-unsigned.tar.gz 7d200cff7ecb340d... a9d1a5144186f96a...
*-arm64-apple-darwin-unsigned.zip 828dbef7e6f7be71... d79632b3499930c2...
*-arm64-apple-darwin.tar.gz 41d97e93aa7e6e26... 8277d885d6589f33...
*-powerpc64-linux-gnu-debug.tar.gz 8f274dd5bc7cf050... b44c384c4fbb0b9c...
*-powerpc64-linux-gnu.tar.gz 5c84b6692302d4a6... 501e3936e465d736...
*-riscv64-linux-gnu-debug.tar.gz d3f0b5cbfc2a516b... 44ffd8629b0a6734...
*-riscv64-linux-gnu.tar.gz 93791691e60c8ee2... af8fe6bbe703197c...
*-x86_64-apple-darwin-unsigned.tar.gz 13940223843590d9... b4862477543e975e...
*-x86_64-apple-darwin-unsigned.zip 98c9938d456fe1a2... d1003ceb784e5c11...
*-x86_64-apple-darwin.tar.gz 96655f56524eed9a... 075f70e980c2c924...
*-x86_64-linux-gnu-debug.tar.gz e9a81bfe41942bb6... 30a56cc387d07345...
*-x86_64-linux-gnu.tar.gz 4ad4c227eaeb50d4... fac094b8092b284e...
*.tar.gz 605e4204e1262b8e... fdda4cd1c750cacd...
guix_build.log 92253d3d25e61b0e... 7504c7d212dc2eb6...
guix_build.log.diff 65038b0618896e1b...

@fanquake
Copy link
Member Author

Based on #21778, so the flag is usable in release builds.

@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from 438851e to d2ea115 Compare May 13, 2024 12:12
@fanquake fanquake marked this pull request as draft May 13, 2024 12:12
@fanquake
Copy link
Member Author

Rebased, but drafted while based on #21778.

@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from d2ea115 to 6213ac9 Compare May 29, 2024 08:47
@fanquake fanquake marked this pull request as ready for review May 29, 2024 08:48
@fanquake
Copy link
Member Author

Binary size comparison for arm64-apple-darwin of a Guix build of master (be100cf) vs this PR (6213ac9):

Binary master PR
bitcoin-cli 481248 477056
bitcoin-qt 30559072 30511316
bitcoin-tx 2246456 2245808
bitcoin-util 324200 324168
bitcoin-wallet 5091904 5054440
bitcoind 11867476 11820592
test_bitcoin 20097440 20054668

@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from 6213ac9 to 44b6c7b Compare May 31, 2024 14:50
@fanquake
Copy link
Member Author

@theuni do you have any thoughts here?

@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from 44b6c7b to ff83833 Compare June 11, 2024 15:42
@theuni
Copy link
Member

theuni commented Jun 11, 2024

Does __attribute__ ((visibility ("default"))) override this? Otherwise I assume we'd need to make sure this flag doesn't make it to shared libs.

@theuni
Copy link
Member

theuni commented Jun 11, 2024

Does __attribute__ ((visibility ("default"))) override this? Otherwise I assume we'd need to make sure this flag doesn't make it to shared libs.

Oh whoops, already asked and answered. Nevermind!

This reduces the size of the binary by 2-3% when building with
`--enable-reduce-exports`.
@fanquake fanquake force-pushed the use_no_exported_symbols_macos branch from ff83833 to 81d4dc8 Compare June 18, 2024 12:03
@fanquake
Copy link
Member Author

Guix Build (aarch64):

45f5a3e38b5e2f8ef7f83f8b1e509d60cb933c52a0110dd6de6e43252869a62f  guix-build-81d4dc8e8739/output/arm64-apple-darwin/SHA256SUMS.part
94e4578d894e61d6b96278a293e2c17fc19a8431bd77c996346fc7e126fc6b3e  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.tar.gz
8f94554c9fdf356cbefd926944ece1ac39af26a80039d245e350b9194861af4a  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.zip
434880815054e5e858fcc8c219b1932cf769fef0d1a30cae58b0ed99f06dddf6  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin.tar.gz
5318e5bc920ea58e11736fd5ae1df761d0ea07ace76d609413375c1bb677f5e1  guix-build-81d4dc8e8739/output/dist-archive/bitcoin-81d4dc8e8739.tar.gz
a9352792d12c202385b2c170aa4cad3837a9f59f427a00e17e98f6b5b7c902d4  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/SHA256SUMS.part
d619422056dae796cca302498a227f7ed3b6db80c9068dc48f6e330f5b0c7da5  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.tar.gz
18af2ca7d2765d0b1fc925e37d2dadf3536d56dec381788e01fb3d908e1410a9  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.zip
5dde2d2f531a3d93789313e31c6f69ecefb80ba564a8f16854b0165d4abbda62  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin.tar.gz

@TheCharlatan
Copy link
Contributor

Guix build (aarch64):

544f33855573c49ff642be39c54603c9afbf64076e6575cb19c5a64fea1522e4  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/SHA256SUMS.part
a8a3c29fe1a2a21f677cfbd8fadb1d65f5901b6f133531f6fce736f1e1e163e5  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/bitcoin-81d4dc8e8739-aarch64-linux-gnu-debug.tar.gz
d059d19cb255b3f555eb2be6b89e0d000a9476278aa783efdc1ba0c3faac6236  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/bitcoin-81d4dc8e8739-aarch64-linux-gnu.tar.gz
1ab4dac0ea883f5d295db9d5b56dc73a757b308ba70caf741687a45703c0a97f  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/SHA256SUMS.part
4956a1fd36d63928e432d4ec56df8a3827c9921c8ab548b5056eef9a61b0cae4  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/bitcoin-81d4dc8e8739-arm-linux-gnueabihf-debug.tar.gz
569338c1150a3727433ab626a89e937f2d0dcc6af7bb841982710421e575701a  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/bitcoin-81d4dc8e8739-arm-linux-gnueabihf.tar.gz
45f5a3e38b5e2f8ef7f83f8b1e509d60cb933c52a0110dd6de6e43252869a62f  guix-build-81d4dc8e8739/output/arm64-apple-darwin/SHA256SUMS.part
94e4578d894e61d6b96278a293e2c17fc19a8431bd77c996346fc7e126fc6b3e  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.tar.gz
8f94554c9fdf356cbefd926944ece1ac39af26a80039d245e350b9194861af4a  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.zip
434880815054e5e858fcc8c219b1932cf769fef0d1a30cae58b0ed99f06dddf6  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin.tar.gz
5318e5bc920ea58e11736fd5ae1df761d0ea07ace76d609413375c1bb677f5e1  guix-build-81d4dc8e8739/output/dist-archive/bitcoin-81d4dc8e8739.tar.gz
5be5fad185d093a812f4473b1fe8817f1c747c2b0607ddd1dfb732bc6ad5a2e8  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/SHA256SUMS.part
95e1b0908fcd9954b4bfaf896bcd3320cc4cca06103d1815de0727785959c800  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/bitcoin-81d4dc8e8739-powerpc64-linux-gnu-debug.tar.gz
cfd390532dafed4bd8d2cceade33024b4d374c46490d6a19115f5ce31aa314da  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/bitcoin-81d4dc8e8739-powerpc64-linux-gnu.tar.gz
10b586c4c652118286e6e98ed1059b1cd91284c78756e48c7fdc7937321822ea  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/SHA256SUMS.part
af620e2a7ba962b0cc6e2ffed46339d335fe1a7a812ea45adba34eb4c69e77a7  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/bitcoin-81d4dc8e8739-riscv64-linux-gnu-debug.tar.gz
d07d9fafefca1cd27edcdd42450179fb2da20f04006a665a432a3e19385e55d1  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/bitcoin-81d4dc8e8739-riscv64-linux-gnu.tar.gz
a9352792d12c202385b2c170aa4cad3837a9f59f427a00e17e98f6b5b7c902d4  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/SHA256SUMS.part
d619422056dae796cca302498a227f7ed3b6db80c9068dc48f6e330f5b0c7da5  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.tar.gz
18af2ca7d2765d0b1fc925e37d2dadf3536d56dec381788e01fb3d908e1410a9  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.zip
5dde2d2f531a3d93789313e31c6f69ecefb80ba564a8f16854b0165d4abbda62  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin.tar.gz
2639a3295ed5100fbea97060c13336561f7acf1dbfa49f3dfa82af6ac9fd1f04  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/SHA256SUMS.part
aea69259dabc44eae1320f2a1dbfe4feba7116c6dd27bb329372635a4e6cc42b  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/bitcoin-81d4dc8e8739-x86_64-linux-gnu-debug.tar.gz
1c0b95d606890c0b6ee6f054a423f1329a2c4a40ea007e9fa983ef13ac072c98  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/bitcoin-81d4dc8e8739-x86_64-linux-gnu.tar.gz
1cd412f1f0a6556f9ee8edfd680eef6de3c8f2bdbf4df15a317e10a1d83ef365  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/SHA256SUMS.part
d7458071414528533f6b4523c93c455079889ab68df23671f54b84b7c71b11d2  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-debug.zip
e0c2c9da623f55d9e0ff87f850325039a71c1dbc3f13758296ff9570e753e332  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-setup-unsigned.exe
e37874cb9de634aef3b28f7d1290613798411545f8dd32effeaed665d06a1147  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-unsigned.tar.gz
9fa4964c426bd0afbec43539ed96184035e84baf2c48fdd72c285d1ea45fbd29  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64.zip

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 81d4dc8 on macOS 14.5 Sonoma (Apple Silicon):

% nm --extern-only src/bitcoind | wc -l                                                    
     579
  • this PR:
% nm --extern-only src/bitcoind | wc -l     
     537

I don't know the reasons, but bitcoind still exports

0000000100000000 T __mh_execute_header

The new -no_exported_symbols linker flag is not printed in the configure summary.

@fanquake
Copy link
Member Author

I don't know the reasons, but bitcoind still exports

That is expected. See the PR description.

The new -no_exported_symbols linker flag is not printed in the configure summary.

That's expected. We don't print the RE LD flags.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 81d4dc8

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 81d4dc8.

The new -no_exported_symbols linker flag is not printed in the configure summary.

That's expected. We don't print the RE LD flags.

Not related to this PR changes, but that's odd as it undermines the summary's goal.

@fanquake fanquake merged commit 24dffdd into bitcoin:master Jul 16, 2024
@fanquake fanquake deleted the use_no_exported_symbols_macos branch July 16, 2024 14:50
@hebasto
Copy link
Member

hebasto commented Jul 19, 2024

Ported to the CMake-based build system in hebasto#271.

hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 20, 2024
4228b9b fixup! cmake: Add `REDUCE_EXPORTS` option (Hennadii Stepanov)

Pull request description:

  This PR ports bitcoin#29072.

ACKs for top commit:
  fanquake:
    ACK 4228b9b

Tree-SHA512: 86c3f4db941f2e5c7625c98192d1f23fda68a82feb6e40334055376e2cd44aa8c7bc9904cfe326835211270a95aab3525f90a052343f12cec67ef877a601e854
kwvg added a commit to kwvg/dash that referenced this pull request Nov 15, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Nov 16, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Nov 17, 2024
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Nov 17, 2024
, bitcoin#28622, bitcoin#28880, bitcoin#29185, bitcoin#29170, bitcoin#29233, bitcoin#29298, bitcoin#29598, bitcoin#29732, bitcoin#29890, bitcoin#29739, bitcoin#30074, bitcoin#30198, bitcoin#29072 (toolchain backports: part 2)

1506d9d merge bitcoin#29072: use `-no_exported_symbols` on macOS (Kittywhiskers Van Gogh)
9247960 merge bitcoin#30198: qt 5.15.14 and fix macOS build with Clang 18 (Kittywhiskers Van Gogh)
5585e7a merge bitcoin#30074: use ENV flags in get_arch (Kittywhiskers Van Gogh)
decd420 merge bitcoin#29739: swap cctools otool for llvm-objdump (Kittywhiskers Van Gogh)
0f8c420 merge bitcoin#29890: remove some tools when cross-compiling for macOS (Kittywhiskers Van Gogh)
936da1a merge bitcoin#29732: qt 5.15.13 (Kittywhiskers Van Gogh)
c294b47 revert: patch qt to make placeholders differ from actual text (Kittywhiskers Van Gogh)
af7090c merge bitcoin#29598: don't use -h with touch on OpenBSD (Kittywhiskers Van Gogh)
ebf8ff2 merge bitcoin#29298: patch libtool out of libnatpmp/miniupnpc (Kittywhiskers Van Gogh)
070b876 merge bitcoin#29233: depends move macOS C(XX) FLAGS out of C & CXX (Kittywhiskers Van Gogh)
d838481 revert dash#2398: Force fvisibility=hidden when compiling on macos (Kittywhiskers Van Gogh)
59a18f9 merge bitcoin#29170: add macho branch protection check (Kittywhiskers Van Gogh)
cb024d9 merge bitcoin#29185: remove `--enable-lto` (Kittywhiskers Van Gogh)
6d75a81 merge bitcoin#28880: switch to using LLVM 17.x for macOS builds (Kittywhiskers Van Gogh)
7b0a1f2 merge bitcoin#28622: use macOS 14 SDK (Xcode 15.0) (Kittywhiskers Van Gogh)
02eb735 merge bitcoin#24948: fix typo in permissions (Kittywhiskers Van Gogh)
2739107 merge bitcoin#24534: make gen-sdk deterministic (Kittywhiskers Van Gogh)
ab10bf9 merge bitcoin#24241: cleanup doc on need of Developer Account to obtain macOS SDK (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependent on #6384
  * Dependency for #6389
  * The Qt patch introduced in [dash#5596](#5596), `fix_qt_placeholders.patch`, was a portion of a suggested workaround for QTBUG-92199 ([source](https://bugreports.qt.io/browse/QTBUG-92199?focusedId=669719&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-669719)) but since then, a fix ([here](https://codereview.qt-project.org/c/qt/qtbase/+/434310)) has made its way to 5.15.12 and we are upgrading to 5.15.14 from 5.15.11.

    So we can safely remove this patch.

  ## Breaking Changes

  None expected

  ## Checklist

  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)**
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have made corresponding changes to the documentation **(note: N/A)**
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK 1506d9d
  PastaPastaPasta:
    utACK 1506d9d

Tree-SHA512: df8e4ea0ce9e7b269d248518698f0566b5eca1a54cdfb53f5b213b90fb5177e5a5df44eaeb6f3fc014cd93351c9245736bb2fd52bc2af4ae274d8fa93e601b07
@bitcoin bitcoin locked and limited conversation to collaborators Jul 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants