Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: LLD based macOS toolchain #21778

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Apr 26, 2021

This switches us to using a LLD based toolchain for macOS builds.

Benefits

  • Less complicated macOS toolchain.
  • Drop FORCE_USE_SYSTEM_CLANG in favour of always using the system Clang.
  • No longer beholden to Apple releasing it's source for cctools, ld64 & libtapi.
  • No more reliance on third parties to modify those sources for us. i.e apple-libtapi, cctools-port (cctools + ld64).

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 26, 2021

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
Concept ACK theuni, hebasto, michaelfolkson

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29790 ([DO NOT MERGE] cmake: Migrate CI scripts to CMake-based build system -- WIP by hebasto)
  • #29739 (depends: swap some cctools tools for LLVM tools by fanquake)
  • #29725 (depends: build libqrencode with CMake by fanquake)
  • #29723 (depends: build zeromq with CMake by fanquake)
  • #29708 (depends: build libnatpmp with CMake by fanquake)
  • #29707 (depends: build miniupnpc with CMake by fanquake)
  • #25573 ([POC] guix: produce a fully -static-pie bitcoind by fanquake)
  • #25391 (guix: Use LTO to build releases by fanquake)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ryanofsky
Copy link
Contributor

ryanofsky commented Apr 26, 2021

This definitely seems like a good thing to add support for, but it seems sad to have to drop support for the open source compiler at the same time as adding support for the closed source one. I don't know enough about this to have an informed opinion, though.

EDIT: Just a misunderstanding

@fanquake
Copy link
Member Author

but it seems sad to have to drop support for the open source compiler at the same time as adding support for the closed source one.

I might be misunderstanding your comment, but the opposite is happening here. We're migrating away from using Apples, irregularly open sourced tools (cctools, ld64), to just vanilla LLVM (lld), which is entirely open source.

@ryanofsky
Copy link
Contributor

I might be misunderstanding your comment, but the opposite is happening here. We're migrating away from using Apples, irregularly open sourced tools (cctools, ld64), to just vanilla LLVM (lld), which is entirely open source.

My bad! I thought this was switching from an unsupported apple open-source toolchain to an supported apple closed source toolchain, not to a vanilla toolchain. My blinding hate of apple has kept me from seeing reality! Thanks for the clarification. This all seems very good.

@theuni
Copy link
Member

theuni commented Apr 26, 2021

Very nice! Strong concept ACK, but obviously we can't use this until all features we need are supported. But it's great to see that linking finally works!

For a little extra context beyond what @fanquake said above, the macOS clang+cctools build has always been a wonky outlier because we have to build our own (very unsupported) toolchain first. LD64 is apple's libre/open-source linker, and there is a community project that maintains a build environment for cross builds.

For a few years, there has been slow development on a darwin functionality for llvm's lld, but it's only really picked up speed and become usable in the last year or two. This PR would bring our Apple builds much more inline with others in that it would finally be using a supported libre/open-source compiler/linker combo.

@fanquake Is cctools still needed at all? LLVM ships bitcode equivalents of most binutils tools (ar, nm, ranlib, etc), I wonder if we can use those instead. Maybe they require lto?

@fanquake
Copy link
Member Author

Is cctools still needed at all? LLVM ships bitcode equivalents of most binutils tools (ar, nm, ranlib, etc), I wonder if we can use those instead. Maybe they require lto?

@theuni no cctools is no longer required. I drop the native_cctools as part of this PR and we just use the LLVM tools.

@theuni
Copy link
Member

theuni commented Apr 28, 2021

@theuni no cctools is no longer required. I drop the native_cctools as part of this PR and we just use the LLVM tools.

Apologies for reading too quickly, I see now that I only looked at the first commit. Turns out the 3rd one is the one I expected :)

@fanquake
Copy link
Member Author

fanquake commented May 1, 2021

Rebased for #21793, and rebased on top of #19817. Made some additional changes, such as renaming the native_cctools package to native_llvm, and removed some now-redundant info from the macdeploy documentation.

Note: I'm pretty sure the use of ZERO_AR_DATE can now be dropped entirely, but have left that out for now.

Use LLD when compiling for macOS.
Always use the system Clang when compiling for macOS (remove
FORCE_USE_SYSTEM_CLANG).
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.
LLD enables ZERO_AR_DATE by default, setting it to zero would enable
non-determinism, setting it to any other value is ignored.

See:
https://github.com/llvm/llvm-project/blob/main/lld/docs/MachO/ld64-vs-lld.rst.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 4, 2024
ff42d81 guix: use clang-toolchain-15 for macOS compilation (fanquake)
94955b4 depends: use LLVM/Clang 15.0.6 for macOS cross-compile (fanquake)

Pull request description:

  This will end up being a blocker for bitcoin#28210, and is already part of bitcoin#21778, even though an even newer LLVM/Clang combination is required (and still missing from upstream Guix). Seems straight-forward enough to just bump the macOS compiler to a more modern Clang.

ACKs for top commit:
  TheCharlatan:
    re-ACK ff42d81

Tree-SHA512: 8af4b54c3a56abb3825c6470444a28e14e9c69820c09ec4a33acebb8ae434df9ae18163c088a582130cc68755293a7e2bde5d065763919d94064ff9b3f83730f
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 5, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 5, 2024

🐙 This pull request conflicts with the target branch and needs rebase.

janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Apr 6, 2024
This is already used in multiple CIs, and will soon become a requirement
for most CIs, i.e when we migrate depends packages to use CMake, for
example:
bitcoin/bitcoin#21778 (comment).

Some of the CIs in 21778 are failing because CMake isn't available, so
just break this out and make CMake globally available.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 9, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 9, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 12, 2024
ff42d81 guix: use clang-toolchain-15 for macOS compilation (fanquake)
94955b4 depends: use LLVM/Clang 15.0.6 for macOS cross-compile (fanquake)

Pull request description:

  This will end up being a blocker for bitcoin#28210, and is already part of bitcoin#21778, even though an even newer LLVM/Clang combination is required (and still missing from upstream Guix). Seems straight-forward enough to just bump the macOS compiler to a more modern Clang.

ACKs for top commit:
  TheCharlatan:
    re-ACK ff42d81

Tree-SHA512: 8af4b54c3a56abb3825c6470444a28e14e9c69820c09ec4a33acebb8ae434df9ae18163c088a582130cc68755293a7e2bde5d065763919d94064ff9b3f83730f
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 16, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 16, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 23, 2024
ff42d81 guix: use clang-toolchain-15 for macOS compilation (fanquake)
94955b4 depends: use LLVM/Clang 15.0.6 for macOS cross-compile (fanquake)

Pull request description:

  This will end up being a blocker for bitcoin#28210, and is already part of bitcoin#21778, even though an even newer LLVM/Clang combination is required (and still missing from upstream Guix). Seems straight-forward enough to just bump the macOS compiler to a more modern Clang.

ACKs for top commit:
  TheCharlatan:
    re-ACK ff42d81

Tree-SHA512: 8af4b54c3a56abb3825c6470444a28e14e9c69820c09ec4a33acebb8ae434df9ae18163c088a582130cc68755293a7e2bde5d065763919d94064ff9b3f83730f
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Apr 24, 2024
I need to try and patch around Qts buildsystem to keep bitcoin#21778 moving
along (the issue being that even when you tell Qt to build using
Clang on Linux, it still calls out to GCC, breaking our ability to have
a macOS release build env that doesn't have a GCC toolchain installed,
and thus no ld binary).

Before trying to patch Qt any further, update to the latest LTS
release, and update the current patch set.

Github-Pull: bitcoin#29732
Rebased-From: 430f319
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 24, 2024
ff42d81 guix: use clang-toolchain-15 for macOS compilation (fanquake)
94955b4 depends: use LLVM/Clang 15.0.6 for macOS cross-compile (fanquake)

Pull request description:

  This will end up being a blocker for bitcoin#28210, and is already part of bitcoin#21778, even though an even newer LLVM/Clang combination is required (and still missing from upstream Guix). Seems straight-forward enough to just bump the macOS compiler to a more modern Clang.

ACKs for top commit:
  TheCharlatan:
    re-ACK ff42d81

Tree-SHA512: 8af4b54c3a56abb3825c6470444a28e14e9c69820c09ec4a33acebb8ae434df9ae18163c088a582130cc68755293a7e2bde5d065763919d94064ff9b3f83730f
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 25, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 26, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 27, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 27, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 29, 2024
… prepare for building with upstream LLVM

3df6070 contrib: remove macOS lazy_bind check (fanquake)
9bc357e build: explicitly opt-in to new fixup_chains functionality for darwin (Cory Fields)
fb61bc0 depends: Bump MacOS minimum runtime requirement to 11.0 (Cory Fields)
c2cd472 depends: bump darwin clang to 11.1 (Cory Fields)

Pull request description:

  This (I believe) resolves the last of the blockers for [switching us away from cctools and instead using out-of-the-box llvm and lld](bitcoin#21778) for building Darwin binaries.

  For now, we continue building with a pre-packaged llvm and cctools, but after this PR the clang+lld combo should just work for anyone trying it. Additionally after this PR, the new runtime `fixup_chains` behavior will be in-use, as ld64 uses it as well.

  The commits may seem unrelated, so in detail:

  lld (llvm's linker) has been a work-in-progress for Darwin for years. Recently though, it has gained nearly all of the features we require. The last missing feature from ld64, `-Wl,-bind_at_load`, is not implemented in lld; as far as I can tell [lazy loading has conceptually been replaced by fixup chains](https://www.emergetools.com/blog/posts/iOS15LaunchTime).

  So that means we don't need ld64's `bind_at_load` as long as lld can handle `-Wl,-fixup_chains` (which it can). I've added it to our configure as a linker option mostly so that we can see it in the logs; it's default-on as long as the minimum version is >11.0.

  About that: the runtime functionality required for `-Wl,-fixup_chains` [requires macOS >=11.0](https://github.com/llvm/llvm-project/blob/release/16.x/lld/MachO/Driver.cpp#L1021). Hence the commit that bumps the minimum version. Our current min runtime of `10.15` has been unsupported since September 2022, so I don't expect this bump to be controversial.

  Lastly, with the minimum runtime version bumped to 11.0, our current version of pre-compiled clang we use for macOS is too old to understand `-mmacosx-version-min=11.0` because it expects `=10.x`. So I've made the smallest possible bump (from 10.0.1 to 11.1.0) to a version that understands. This bump is arbitrary and unfortunate, but likely to be short-lived as we may end up replacing it with llvm+lld for v26 anyway. I've held off on bumping the SDK as I think that makes sense to do as part of the lld switch instead.

ACKs for top commit:
  hebasto:
    ACK 3df6070
  gruve-p:
    ACK bitcoin@3df6070
  fanquake:
    ACK 3df6070
  TheCharlatan:
    ACK 3df6070

Tree-SHA512: 0200ec4a3b88df33877ae82c15b5c04d745852550923f491a354b391cac65f88e4df116a40055c23a8cbcfcdfb9a376c6ae8fdd0e898e7b966bc213dcb5857cf
fanquake added a commit to fanquake/bitcoin that referenced this pull request May 3, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
fanquake added a commit to fanquake/bitcoin that referenced this pull request May 3, 2024
Similar to libtool, (llvm-)otool only exists with a version suffix
on some systems (Ubuntu), which makes it annoying to use/find. Avoid
this, by switching to objdump. Which is a drop-in replacement.

This is related to bitcoin#21778, and the switchover to using vanilla LLVM for
macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants