From db7b2c8ec6547bacebcb0b8a72e30b246c2f2e06 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Mon, 19 Feb 2024 14:58:53 -0800 Subject: [PATCH] HACKs print linker info I think we're running an old buggy linker in GitHub Actions. Let's print the linker info to help debug this. --- .github/workflows/apple.yml | 5 +++++ cpython-unix/build.py | 15 +++++++++++++++ cpython-unix/targets.yml | 2 ++ 3 files changed, 22 insertions(+) diff --git a/.github/workflows/apple.yml b/.github/workflows/apple.yml index c9426f51..a8e8f525 100644 --- a/.github/workflows/apple.yml +++ b/.github/workflows/apple.yml @@ -234,6 +234,11 @@ jobs: - name: Build run: | + # Our LLVM toolchain doesn't provide a linker. And the /usr/bin/ld on macOS + # runners may contain a bug where weak references aren't preserved during LTO. + # So force the use of a modern LLVM linker. + export FORCE_LINKER=$(brew --prefix llvm)/bin/lld + if [ "${{ matrix.build.target_triple }}" = "aarch64-apple-darwin" ]; then export APPLE_SDK_PATH=/Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk elif [ "${{ matrix.build.target_triple }}" = "x86_64-apple-darwin" ]; then diff --git a/cpython-unix/build.py b/cpython-unix/build.py index 8eff1977..b22d3b57 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -205,6 +205,21 @@ def add_target_env(env, build_platform, target_triple, build_env): extra_host_cflags.extend(["-isysroot", host_sdk_path]) extra_host_ldflags.extend(["-isysroot", host_sdk_path]) + # Our custom LLVM toolchain doesn't include an lld. Our clang driver + # will pick up /usr/bin/ld by default. On some macOS, /usr/bin/ld is + # an older version of LLVM and won't preserve weak references when doing + # LTO. + if "FORCE_LINKER" in os.environ: + # We can't use -fuse-ld=/absolute/path. So we deconstruct the full path + # and specify the filename in -fuse-ld and put the linker path at the front + # of PATH. + ld = pathlib.Path(os.environ["FORCE_LINKER"]) + flag = "-fuse-ld=%s" % ld.name + + env["PATH"] = "%s:%s" % (ld.parent, env["PATH"]) + extra_host_ldflags.append(flag) + extra_target_ldflags.append(flag) + env["EXTRA_HOST_CFLAGS"] = " ".join(extra_host_cflags) env["EXTRA_HOST_LDFLAGS"] = " ".join(extra_host_ldflags) env["EXTRA_TARGET_CFLAGS"] = " ".join(extra_target_cflags) diff --git a/cpython-unix/targets.yml b/cpython-unix/targets.yml index fd81e286..8061d1af 100644 --- a/cpython-unix/targets.yml +++ b/cpython-unix/targets.yml @@ -85,6 +85,7 @@ aarch64-apple-darwin: - '-Wno-undef-prefix' - '-fvisibility=hidden' target_ldflags: + - '-v' - '-arch' - 'arm64' - '-mmacosx-version-min=11.0' @@ -569,6 +570,7 @@ x86_64-apple-darwin: - '-Wno-undef-prefix' - '-fvisibility=hidden' target_ldflags: + - '-v' - '-arch' - 'x86_64' - '-mmacosx-version-min=10.9'