build: use -no_exported_symbols on macOS #29072

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:use_no_exported_symbols_macos changing 1 files +1 −0
  1. fanquake commented at 12:03 pm on December 13, 2023: member

    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.

  2. DrahtBot commented at 12:03 pm on December 13, 2023: contributor

    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.

  3. DrahtBot added the label Build system on Dec 13, 2023
  4. fanquake force-pushed on Dec 18, 2023
  5. in configure.ac:1535 in 5f1113a2df outdated
    1531@@ -1532,6 +1532,7 @@ if test "$use_reduce_exports" = "yes"; then
    1532   AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fvisibility=hidden"],
    1533   [AC_MSG_ERROR([Cannot set hidden symbol visibility. Use --disable-reduce-exports.])], [$CXXFLAG_WERROR])
    1534   AX_CHECK_LINK_FLAG([-Wl,--exclude-libs,ALL], [RELDFLAGS="-Wl,--exclude-libs,ALL"], [], [$LDFLAG_WERROR])
    1535+  AX_CHECK_LINK_FLAG([-Wl,-no_exported_symbols], [RELDFLAGS="$RELDFLAGS -Wl,-no_exported_symbols"], [], [$LDFLAG_WERROR])
    


    hebasto commented at 3:25 pm on January 2, 2024:

    This makes libbitcoinconsensus.0.dylib export no symbols, which is not what we want, right?

    0% dyld_info -exports src/.libs/libbitcoinconsensus.0.dylib        
    1src/.libs/libbitcoinconsensus.0.dylib [arm64]:
    2    -exports:
    3        offset      symbol
    

    fanquake commented at 10:56 am on February 27, 2024:
    Moved this into LIBTOOL_APP_LDFLAGS.
  6. DrahtBot added the label CI failed on Jan 16, 2024
  7. fanquake force-pushed on Feb 27, 2024
  8. DrahtBot removed the label CI failed on Feb 27, 2024
  9. maflcko added the label DrahtBot Guix build requested on Apr 23, 2024
  10. DrahtBot commented at 2:00 am on April 24, 2024: contributor

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

    File commit 2cecbbb98683844a642899f4563aab8b856ffd3b(master) commit 1fe6fccee937953f4a3c7696e6c636e03a4880f2(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...
  11. DrahtBot removed the label DrahtBot Guix build requested on Apr 24, 2024
  12. hebasto added the label Needs CMake port on Apr 24, 2024
  13. fanquake force-pushed on May 10, 2024
  14. fanquake commented at 1:32 pm on May 10, 2024: member
    Based on #21778, so the flag is usable in release builds.
  15. DrahtBot added the label Needs rebase on May 13, 2024
  16. fanquake force-pushed on May 13, 2024
  17. fanquake marked this as a draft on May 13, 2024
  18. fanquake commented at 12:13 pm on May 13, 2024: member
    Rebased, but drafted while based on #21778.
  19. DrahtBot removed the label Needs rebase on May 13, 2024
  20. fanquake force-pushed on May 29, 2024
  21. fanquake marked this as ready for review on May 29, 2024
  22. fanquake commented at 9:36 am on May 29, 2024: member

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

    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
  23. fanquake force-pushed on May 31, 2024
  24. fanquake commented at 4:23 pm on May 31, 2024: member
    @theuni do you have any thoughts here?
  25. fanquake force-pushed on Jun 11, 2024
  26. theuni commented at 3:49 pm on June 11, 2024: member
    Does __attribute__ ((visibility ("default"))) override this? Otherwise I assume we’d need to make sure this flag doesn’t make it to shared libs.
  27. theuni commented at 3:51 pm on June 11, 2024: member

    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!

  28. build: use -no_exported_symbols on macOS
    This reduces the size of the binary by 2-3% when building with
    `--enable-reduce-exports`.
    81d4dc8e87
  29. fanquake force-pushed on Jun 18, 2024
  30. fanquake commented at 12:30 pm on June 18, 2024: member

    Guix Build (aarch64):

    045f5a3e38b5e2f8ef7f83f8b1e509d60cb933c52a0110dd6de6e43252869a62f  guix-build-81d4dc8e8739/output/arm64-apple-darwin/SHA256SUMS.part
    194e4578d894e61d6b96278a293e2c17fc19a8431bd77c996346fc7e126fc6b3e  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.tar.gz
    28f94554c9fdf356cbefd926944ece1ac39af26a80039d245e350b9194861af4a  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.zip
    3434880815054e5e858fcc8c219b1932cf769fef0d1a30cae58b0ed99f06dddf6  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin.tar.gz
    45318e5bc920ea58e11736fd5ae1df761d0ea07ace76d609413375c1bb677f5e1  guix-build-81d4dc8e8739/output/dist-archive/bitcoin-81d4dc8e8739.tar.gz
    5a9352792d12c202385b2c170aa4cad3837a9f59f427a00e17e98f6b5b7c902d4  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/SHA256SUMS.part
    6d619422056dae796cca302498a227f7ed3b6db80c9068dc48f6e330f5b0c7da5  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.tar.gz
    718af2ca7d2765d0b1fc925e37d2dadf3536d56dec381788e01fb3d908e1410a9  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.zip
    85dde2d2f531a3d93789313e31c6f69ecefb80ba564a8f16854b0165d4abbda62  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin.tar.gz
    
  31. DrahtBot added the label CI failed on Jun 18, 2024
  32. DrahtBot removed the label CI failed on Jun 18, 2024
  33. TheCharlatan commented at 4:14 pm on June 25, 2024: contributor

    Guix build (aarch64):

     0544f33855573c49ff642be39c54603c9afbf64076e6575cb19c5a64fea1522e4  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/SHA256SUMS.part
     1a8a3c29fe1a2a21f677cfbd8fadb1d65f5901b6f133531f6fce736f1e1e163e5  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/bitcoin-81d4dc8e8739-aarch64-linux-gnu-debug.tar.gz
     2d059d19cb255b3f555eb2be6b89e0d000a9476278aa783efdc1ba0c3faac6236  guix-build-81d4dc8e8739/output/aarch64-linux-gnu/bitcoin-81d4dc8e8739-aarch64-linux-gnu.tar.gz
     31ab4dac0ea883f5d295db9d5b56dc73a757b308ba70caf741687a45703c0a97f  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/SHA256SUMS.part
     44956a1fd36d63928e432d4ec56df8a3827c9921c8ab548b5056eef9a61b0cae4  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/bitcoin-81d4dc8e8739-arm-linux-gnueabihf-debug.tar.gz
     5569338c1150a3727433ab626a89e937f2d0dcc6af7bb841982710421e575701a  guix-build-81d4dc8e8739/output/arm-linux-gnueabihf/bitcoin-81d4dc8e8739-arm-linux-gnueabihf.tar.gz
     645f5a3e38b5e2f8ef7f83f8b1e509d60cb933c52a0110dd6de6e43252869a62f  guix-build-81d4dc8e8739/output/arm64-apple-darwin/SHA256SUMS.part
     794e4578d894e61d6b96278a293e2c17fc19a8431bd77c996346fc7e126fc6b3e  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.tar.gz
     88f94554c9fdf356cbefd926944ece1ac39af26a80039d245e350b9194861af4a  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin-unsigned.zip
     9434880815054e5e858fcc8c219b1932cf769fef0d1a30cae58b0ed99f06dddf6  guix-build-81d4dc8e8739/output/arm64-apple-darwin/bitcoin-81d4dc8e8739-arm64-apple-darwin.tar.gz
    105318e5bc920ea58e11736fd5ae1df761d0ea07ace76d609413375c1bb677f5e1  guix-build-81d4dc8e8739/output/dist-archive/bitcoin-81d4dc8e8739.tar.gz
    115be5fad185d093a812f4473b1fe8817f1c747c2b0607ddd1dfb732bc6ad5a2e8  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/SHA256SUMS.part
    1295e1b0908fcd9954b4bfaf896bcd3320cc4cca06103d1815de0727785959c800  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/bitcoin-81d4dc8e8739-powerpc64-linux-gnu-debug.tar.gz
    13cfd390532dafed4bd8d2cceade33024b4d374c46490d6a19115f5ce31aa314da  guix-build-81d4dc8e8739/output/powerpc64-linux-gnu/bitcoin-81d4dc8e8739-powerpc64-linux-gnu.tar.gz
    1410b586c4c652118286e6e98ed1059b1cd91284c78756e48c7fdc7937321822ea  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/SHA256SUMS.part
    15af620e2a7ba962b0cc6e2ffed46339d335fe1a7a812ea45adba34eb4c69e77a7  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/bitcoin-81d4dc8e8739-riscv64-linux-gnu-debug.tar.gz
    16d07d9fafefca1cd27edcdd42450179fb2da20f04006a665a432a3e19385e55d1  guix-build-81d4dc8e8739/output/riscv64-linux-gnu/bitcoin-81d4dc8e8739-riscv64-linux-gnu.tar.gz
    17a9352792d12c202385b2c170aa4cad3837a9f59f427a00e17e98f6b5b7c902d4  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/SHA256SUMS.part
    18d619422056dae796cca302498a227f7ed3b6db80c9068dc48f6e330f5b0c7da5  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.tar.gz
    1918af2ca7d2765d0b1fc925e37d2dadf3536d56dec381788e01fb3d908e1410a9  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin-unsigned.zip
    205dde2d2f531a3d93789313e31c6f69ecefb80ba564a8f16854b0165d4abbda62  guix-build-81d4dc8e8739/output/x86_64-apple-darwin/bitcoin-81d4dc8e8739-x86_64-apple-darwin.tar.gz
    212639a3295ed5100fbea97060c13336561f7acf1dbfa49f3dfa82af6ac9fd1f04  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/SHA256SUMS.part
    22aea69259dabc44eae1320f2a1dbfe4feba7116c6dd27bb329372635a4e6cc42b  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/bitcoin-81d4dc8e8739-x86_64-linux-gnu-debug.tar.gz
    231c0b95d606890c0b6ee6f054a423f1329a2c4a40ea007e9fa983ef13ac072c98  guix-build-81d4dc8e8739/output/x86_64-linux-gnu/bitcoin-81d4dc8e8739-x86_64-linux-gnu.tar.gz
    241cd412f1f0a6556f9ee8edfd680eef6de3c8f2bdbf4df15a317e10a1d83ef365  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/SHA256SUMS.part
    25d7458071414528533f6b4523c93c455079889ab68df23671f54b84b7c71b11d2  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-debug.zip
    26e0c2c9da623f55d9e0ff87f850325039a71c1dbc3f13758296ff9570e753e332  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-setup-unsigned.exe
    27e37874cb9de634aef3b28f7d1290613798411545f8dd32effeaed665d06a1147  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64-unsigned.tar.gz
    289fa4964c426bd0afbec43539ed96184035e84baf2c48fdd72c285d1ea45fbd29  guix-build-81d4dc8e8739/output/x86_64-w64-mingw32/bitcoin-81d4dc8e8739-win64.zip
    
  34. hebasto commented at 2:27 pm on July 16, 2024: member

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

    • the master branch @ 9c5cdf07f30f816cd134e2cd2dca9c27ef7067a5:
    0% nm --extern-only src/bitcoind | wc -l                                                    
    1     579
    
    • this PR:
    0% nm --extern-only src/bitcoind | wc -l     
    1     537
    

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

    00000000100000000 T __mh_execute_header
    

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

  35. fanquake commented at 2:29 pm on July 16, 2024: member

    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.

  36. theuni approved
  37. theuni commented at 2:33 pm on July 16, 2024: member
    utACK 81d4dc8e8739df0e9a8e92f55071733f6500617b
  38. hebasto approved
  39. hebasto commented at 2:36 pm on July 16, 2024: member

    ACK 81d4dc8e8739df0e9a8e92f55071733f6500617b.

    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.

  40. fanquake merged this on Jul 16, 2024
  41. fanquake closed this on Jul 16, 2024

  42. fanquake deleted the branch on Jul 16, 2024
  43. hebasto commented at 9:57 pm on July 19, 2024: member
    Ported to the CMake-based build system in https://github.com/hebasto/bitcoin/pull/271.
  44. hebasto removed the label Needs CMake port on Jul 19, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me