Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Apr 26, 2021

From ##bitcoin-core-gui IRC channel:

<fanquake> hebasto: I think I might have solved the darkmode issue, or at least some of the macOS qt problems. Will PR shortly
<hebasto> was I on the right way?
<fanquake> Yes I think it's related to how the SDK is being setup
<hebasto> fanquake: expecting of adding -Wl,-sdk_version to linker flags :)
<fanquake> hebasto: heh. That may be added at some point, however I think the solution here will be even simpler

Assuming, that fanquake's solution does not involve linker flags, I'm suggesting an alternative one that does use them.

When doing static builds, for some reasons, SDK version is not handled correctly when Darwin Driver passes it to a linker via the
-platform_version option.

With this PR we pass the -platform_version option to a linker explicitly.

Fix #21771.

This change causes harmless warnings:

ld: warning: passed two min versions (10.14.0, 10.14) for platform macOS. Using 10.14.

Building with depends on macOS Big Sur 11.2.3 (20D91):

% ld -v
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 12.0.0, (clang-1200.0.32.29) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 12.0.0 (tapi-1200.0.23.5)
% otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION
Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk n/a
   ntools 1
     tool 3
  version 609.8
  • with this PR
% otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION                       
Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 11.1
   ntools 1
     tool 3
  version 609.8

@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

macOS 10.14 SDK doesn't seem to have -platform_version available. When trying to perform a native depends build on macOS 10.14 I get the following error when building libevent:

ld: unknown option: -platform_version
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:4267: $? = 1
configure:4307: result: no

The above error would mean this PR wouldn't work in its current form.

Besides broken compatibility with 10.14, this PR seems to be a step in the right direction. The following will be based on my testing of the state of dark mode: bitcoin-core/gui#275 (review)

macOS 10.15

Master PR
115327729-6e549700-a15d-11eb-8c46-7c830007d71e 10 15
otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION  
       
Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 10.15.6
   ntools 1
     tool 3
  version 609.8

macOS 11.2.3

Master PR
115330418-fccb1780-a161-11eb-84ca-1c87a6b5f448 11 2
Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 11.1
   ntools 1
     tool 3
  version 609.8

@hebasto
Copy link
Member Author

hebasto commented Apr 27, 2021

@RandyMcMillan

Tested on macOS 10.14.6 (18G103)

Did you test a static build?

When doing static builds, for some reasons, SDK version is not handled
correctly when Darwin Driver passes it to a linker via the
-platform_version option.

This change makes passing the -platform_version option to a linker
explicit.
@hebasto
Copy link
Member Author

hebasto commented Apr 27, 2021

Updated 15d41b3 -> d7c83cb (pr21782.01 -> pr21782.02, diff):

  • fixed compatibility with macOS Mojave

@RandyMcMillan
Copy link
Contributor

For clarity:

brew install mingw-w64
was required to build depends on Mojave

Screen Shot 2021-04-27 at 8 01 27 AM
Screen Shot 2021-04-27 at 8 02 08 AM

@hebasto
Copy link
Member Author

hebasto commented Apr 27, 2021

@RandyMcMillan

For clarity:

brew install mingw-w64
was required to build depends on Mojave

Sorry, I don't understand this.

mingw-w64 is required only when cross-compiling for Windows target.

This pr deals with macOS target only.

UPDATE:
To make a static build with depends on Mojave 10.14.6:

$ make -C depends
$ ./autogen.sh
$ CONFIG_SITE=$PWD/depends/x86_64-apple-darwin18.7.0/share/config.site ./configure
$ make

@RandyMcMillan
Copy link
Contributor

RandyMcMillan commented Apr 27, 2021

Almost got thru it.

Darwin ₿ 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

Screen Shot 2021-04-27 at 11 43 01 AM

commit
d7c83cb

Used commands:

$ make -C depends
$ ./autogen.sh
$ CONFIG_SITE=$PWD/depends/x86_64-apple-darwin18.7.0/share/config.site ./configure
$ make

Screen Shot 2021-04-27 at 11 32 12 AM

@hebasto
Copy link
Member Author

hebasto commented Apr 27, 2021

@RandyMcMillan
Could make clean && make help?

@RandyMcMillan
Copy link
Contributor

Error:

Screen Shot 2021-04-27 at 4 38 09 PM

Disabled Tests:

CONFIG_SITE=$PWD/depends/x86_64-apple-darwin18.7.0/share/config.site ./configure --disable-tests
make

Screen Shot 2021-04-27 at 4 55 15 PM

Besides the test error d7c83cb seems good - This may have fixed a dbus issue I was seeing as well.

@jarolrod
Copy link
Contributor

jarolrod commented Apr 27, 2021

@RandyMcMillan I'm not sure what's wrong there, but, d7c83cb builds just fine for me on macOS 10.14

@hebasto
Copy link
Member Author

hebasto commented Apr 27, 2021

@RandyMcMillan

To figure out problems with this PR, could you confirm a successful build the master branch with depends on macOS 10.14?

@fanquake
Copy link
Member

How is this comment:

macOS 10.14 SDK doesn't seem to have -platform_version available. When trying to perform a native depends build on macOS 10.14 I get the following error

solved with the current change? If the linker doesn't support -platform_version, then building with a depends prefix would still be broken, because -platform_version still gets added to LDFLAGS when configuring.

@jarolrod It's not the 10.14 SDK that doesn't support -platform_version, it's the linker. What version of ld are you using where -platform_version isn't supported?

@jarolrod
Copy link
Contributor

@fanquake on my macOS 10.14.6 partition:

ld -v

@(#)PROGRAM:ld  PROJECT:ld64-450.3
BUILD 18:16:53 Apr  5 2019
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 10.0.1, (clang-1001.0.46.4) (static support for 22, runtime is 22)
TAPI support using: Apple TAPI version 10.0.1 (tapi-1001.0.4.1)

I failed to build natively on macOS with depends using 15d41b3, but it builds using d7c83cb. Also, I don't see -platform_version under the LDFLAGS section of my configure output on 10.14.6. I do see it on 10.15 and 11.

@fanquake
Copy link
Member

Right, because ld actually throws an error, AX_CHECK_LINK_FLAG wont append the flags. I had been thinking it was just warning, and because the call wasn't using $LDFLAG_WERROR they would end up appended and then we'd fail to link.

Regardless, as-is, this change is a bit of an undocumented hack. It need explanation either in depends, or in configure.

Just to clarify, as I understand it, static builds aren't "broken", it's just that our current macOS toolchain, whether cross-compiling via depends, or building on macOS, doesn't fill out the sdk field in the LC_BUILD_VERSION command. This is an issue because Qt is now detecting at runtime, via the version in that field, whether or not to enable some features, such as "Dark mode"?

@jarolrod
Copy link
Contributor

jarolrod commented Apr 28, 2021

@fanquake hopefully this can clarify a bit, going by my "state of dark mode" testing bitcoin-core/gui#275 (review)

From the linked review, we can see that this sdk field issue, seemingly, manifests itself only on native depends builds and with the bumped toolchain cross-compile (did not test bumped toolchain native depends build).

Linux Cross Compile
The sdk field is filled in when cross-compiling for macOS. Albeit, with a (maybe) strange value for sdk. Anyways, Dark Mode is enabled. Below is the output of otool on a bitcoin-qt binary cross-compiled from linux on master:

otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION

Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 505.0
   ntools 1
     tool 3
  version 530.0

Native macOS Depends Build
On a native macOS depends build, the SDK value is not filled in. it registers as N/A using otool. Dark Mode is disabled. The only exception, before this PR, is macOS 10.14 where there is a value for sdk.

Bumped Toolchain Cross Compile
Building a macOS cross-compile using the bumped toolchain (#19817). The sdk field is not filled in and Dark Mode is disabled. Here is the output of otool on a bitcoin-qt binary cross-compiled from Linux on the bumped toolchain branch:

bitcoin % otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION

Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk n/a
   ntools 1
     tool 3
  version 609.0

Where this PR fits in
From my testing, this PR fills in the sdk field of the affected builds (native depends, and bumped toolchain cross-compile)

Native depends build have the sdk field filled in and Dark Mode works ✅

I combined the bumped toolchain and this PR on this branch: https://github.com/jarolrod/bitcoin/tree/ctool-and-static-darwin. Bumped Toolchain Cross Compile otool output with this pr:

otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION

Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 10.15.6
   ntools 1
     tool 3
  version 609.0

Another (welcome) side-effect of this PR is that the sdk field is properly filled in on a cross-compile from the current master. otool reports back the expected value of 10.15.1 instead of 505.0 that we currently get without this PR.

otool -l src/qt/bitcoin-qt | grep -A 7 -B 1 BUILD_VERSION

Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 10.15.1
   ntools 1
     tool 3
  version 530.0

Qt
The inference here is that the sdk version has a role in whether or not 'Dark Mode' is enabled.

@DrahtBot
Copy link
Contributor

Gitian builds

File commit f8f5552
(master)
commit ef4c52d980021ee89e4e45e781657ca49b8cc736
(master and this pull)
bitcoin-core-linux-22-res.yml d273ec877cddaf98... 6abb1328d3f9409b...
bitcoin-core-osx-22-res.yml 08d13a0cb2d974a2... ba7f640bbcd7afed...
bitcoin-core-win-22-res.yml ede99ec33c5a8d56... 39274666f0a21b1e...
*-aarch64-linux-gnu-debug.tar.gz 1de746dfaa67f9c4... 1e8f86ad5942a76a...
*-aarch64-linux-gnu.tar.gz 7b273c1e3aa31429... 25a4bc14c35a10b9...
*-arm-linux-gnueabihf-debug.tar.gz 18221fa46c7add35... b0a49fd9d8ad6cf3...
*-arm-linux-gnueabihf.tar.gz d5deb88e186a2364... a43cd5227bec8515...
*-osx-unsigned.dmg 604184eac9e1a1f3... b9a38e0b009274fe...
*-osx64.tar.gz 1f00241bdd70b453... 5d0a3c2a7b4a0cb1...
*-powerpc64-linux-gnu-debug.tar.gz d270a69fd2282a9a... 101c1dd1ccc731c7...
*-powerpc64-linux-gnu.tar.gz 074b0c3f3b97a9da... 57fbfbaaad1f68c9...
*-powerpc64le-linux-gnu-debug.tar.gz ec241e33b68b4884... 5dfe0b83166c99bb...
*-powerpc64le-linux-gnu.tar.gz d4ed9cfa2b07a865... 064cc1c427a1343a...
*-riscv64-linux-gnu-debug.tar.gz 8cc40fa9d29ff86c... f2669743db7b54cb...
*-riscv64-linux-gnu.tar.gz 6b7fa831a17028f5... faa34c775c2d75fb...
*-win64-debug.zip 4164b00781ed2f3c... 4a285a79874fe6af...
*-win64-setup-unsigned.exe 5bcfe14df146cb9d... af46cf71ea85452a...
*-win64.zip 18c7aab75e106c71... 87583f4945b08104...
*-x86_64-linux-gnu-debug.tar.gz 8fcb8a5289c16944... 76320b69e446713e...
*-x86_64-linux-gnu.tar.gz bd6c67109928d0e8... eeda642239c10d9b...
*.tar.gz 6e60d9ec8da1a7df... a4a7e6d193d15dda...
linux-build.log 44ff3907b0e24252... 1e57bea95ea78312...
osx-build.log 9c4a058a6161e80e... cb4c58d92f0f1ca2...
win-build.log 722bf1061e446819... db14ca9338d878ed...
bitcoin-core-linux-22-res.yml.diff 18737c624495b3af...
bitcoin-core-osx-22-res.yml.diff ad05356a1d0801fe...
bitcoin-core-win-22-res.yml.diff c5850541825899cc...
linux-build.log.diff 20453e65173389b4...
osx-build.log.diff dc8709e5d117fcea...
win-build.log.diff d4833329b78364f7...

@fanquake
Copy link
Member

From the linked review, we can see that this sdk field issue, seemingly, manifests itself only on native depends builds and with the bumped toolchain cross-compile (did not test bumped toolchain native depends build).

The SDK field has also been present in the LC_VERSION_MIN_MACOSX command; LC_BUILD_VERSION is actually fairly new. I'm not convinced this approach is the way to solve our issue. I think the more correct fix is #21793.

@hebasto
Copy link
Member Author

hebasto commented Apr 28, 2021

Closing in favor of #21793 which is more correct solution for #21771.

@hebasto hebasto closed this Apr 28, 2021
@hebasto
Copy link
Member Author

hebasto commented Apr 28, 2021

@fanquake

The SDK field has also been present in the LC_VERSION_MIN_MACOSX command; LC_BUILD_VERSION is actually fairly new.

I cannot see LC_VERSION_MIN_MACOSX in the otool output on macOS.

@fanquake
Copy link
Member

I cannot see LC_VERSION_MIN_MACOSX in the otool output on macOS.

It's going to depend on which toolchain you've used. The most recently released binaries have LC_VERSION_MIN_MACOSX not LC_BUILD_VERSION.

@hebasto hebasto deleted the 210426-darwin branch April 29, 2021 07:27
fanquake added a commit that referenced this pull request May 1, 2021
cf971c9 build: use -isysroot over --sysroot on macOS (fanquake)

Pull request description:

  Not only does this seem to be the more correct behaviour when targeting Darwin, but if you use `-isysroot`, Clangs Darwin driver will [infer the deployment target](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L1652) from the SDK and use other SDK info when parsing arguments to the linker. In the case of [`-platform_version`](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L2656), which is added if the linker is [new enough](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L342), the version tuple is constructed from the SDKInfo, and SDKInfo, as far as I can tell, only exists when `-isysroot` has been passed, see [parseSDKSettings](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L1785)

  As a result, the SDK version field in the `LC_BUILD_VERSION` command is filled out. i.e when building master:
  ```bash
        cmd LC_BUILD_VERSION
    cmdsize 32
   platform 1
      minos 10.14
        sdk n/a
     ntools 1
       tool 3
    version 650.9
  ```
  vs this PR:
  ```bash
        cmd LC_BUILD_VERSION
    cmdsize 32
   platform 1
      minos 10.14
        sdk 11.3
     ntools 1
       tool 3
    version 650.9
  ```

  This, from what I understand, will fix the issue we are having with Qt deciding wether or not to enable features like "Dark mode" on macOS, see #21771, however I have not tested that. Thus this is an alternative to #21782.

  Our usage of `--sysroot` was added in #17118.

  ```bash
  -isysroot <dir>         Set the system root directory (usually /)
  ```

ACKs for top commit:
  Sjors:
    tACK cf971c9
  hebasto:
    re-ACK cf971c9, only rebased and addressed comments since my [previous](#21793 (review)) review.

Tree-SHA512: f01138179fb85083b5505bbaa48810451098ffa4da5d3c9b673785448790aa76f2e64b2aab6e698f6ee378a21f70626445a3fabee7c61dbfc44e96f3e3964656
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 1, 2021
cf971c9 build: use -isysroot over --sysroot on macOS (fanquake)

Pull request description:

  Not only does this seem to be the more correct behaviour when targeting Darwin, but if you use `-isysroot`, Clangs Darwin driver will [infer the deployment target](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L1652) from the SDK and use other SDK info when parsing arguments to the linker. In the case of [`-platform_version`](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L2656), which is added if the linker is [new enough](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L342), the version tuple is constructed from the SDKInfo, and SDKInfo, as far as I can tell, only exists when `-isysroot` has been passed, see [parseSDKSettings](https://github.com/llvm/llvm-project/blob/3e037f8f0e26acab8cc784ea4c7d05da79f7c22e/clang/lib/Driver/ToolChains/Darwin.cpp#L1785)

  As a result, the SDK version field in the `LC_BUILD_VERSION` command is filled out. i.e when building master:
  ```bash
        cmd LC_BUILD_VERSION
    cmdsize 32
   platform 1
      minos 10.14
        sdk n/a
     ntools 1
       tool 3
    version 650.9
  ```
  vs this PR:
  ```bash
        cmd LC_BUILD_VERSION
    cmdsize 32
   platform 1
      minos 10.14
        sdk 11.3
     ntools 1
       tool 3
    version 650.9
  ```

  This, from what I understand, will fix the issue we are having with Qt deciding wether or not to enable features like "Dark mode" on macOS, see bitcoin#21771, however I have not tested that. Thus this is an alternative to bitcoin#21782.

  Our usage of `--sysroot` was added in bitcoin#17118.

  ```bash
  -isysroot <dir>         Set the system root directory (usually /)
  ```

ACKs for top commit:
  Sjors:
    tACK cf971c9
  hebasto:
    re-ACK cf971c9, only rebased and addressed comments since my [previous](bitcoin#21793 (review)) review.

Tree-SHA512: f01138179fb85083b5505bbaa48810451098ffa4da5d3c9b673785448790aa76f2e64b2aab6e698f6ee378a21f70626445a3fabee7c61dbfc44e96f3e3964656
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
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.

build: Static build behavior depends on the used compiler

6 participants