Skip to content

Commit

Permalink
HACKs print linker info
Browse files Browse the repository at this point in the history
I think we're running an old buggy linker in GitHub Actions.
Let's print the linker info to help debug this.
  • Loading branch information
indygreg committed Feb 20, 2024
1 parent 2e11c03 commit db7b2c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/apple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ aarch64-apple-darwin:
- '-Wno-undef-prefix'
- '-fvisibility=hidden'
target_ldflags:
- '-v'
- '-arch'
- 'arm64'
- '-mmacosx-version-min=11.0'
Expand Down Expand Up @@ -569,6 +570,7 @@ x86_64-apple-darwin:
- '-Wno-undef-prefix'
- '-fvisibility=hidden'
target_ldflags:
- '-v'
- '-arch'
- 'x86_64'
- '-mmacosx-version-min=10.9'
Expand Down

0 comments on commit db7b2c8

Please sign in to comment.