Linker crashes when building tools

I think the linker is crashing when attempting to build some of the compiler repository tools.

I just rebased to the latest commit on main, so it's at 36a15ceaf4230e658a9453d2f14532bb99fd5dd4, and I ran update-checkout and deleted the previous build directory, so everything should be fresh.

macOS Sonoma 14.0 (23A344)
M1 Pro
Xcode 15.0 (15A240d)

[1351/2166][ 62%][557.124s] Linking CXX executable bin/lldb-moduleimport-test
FAILED: bin/lldb-moduleimport-test 
0  0x102b3f648  __assert_rtn + 72
1  0x102afa0f0  ___Z13dispatchApplyIRKmZ15dispatchForEachIKN6mach_o13CompactUnwind11Diff24FixupEZNK2ld16LayoutExecutable18writeCompactUnwindENSt3__14spanIhLm18446744073709551615EEEyRKNS7_13SectionLayoutEE4$_26EvNSA_IT_Lm18446744073709551615EEEmT0_EUlmE_EvOSG_SI__block_invoke + 0
2  0x18c541950  _dispatch_client_callout2 + 20
3  0x18c5561a4  _dispatch_apply_invoke_and_wait + 176
4  0x18c555464  _dispatch_apply_with_attr_f + 1176
5  0x18c555650  dispatch_apply + 96
6  0x102afa398  ld::LayoutExecutable::writeContentWithoutLinkEdit(std::__1::span<unsigned char, 18446744073709551615ul>, unsigned long long) + 672
7  0x102b00020  ld::LayoutExecutable::writeToFile(char const*) + 15248
8  0x102ab22e8  main + 9424
ld: Assertion failed: (false && "compact unwind compressed function offset doesn't fit in 24 bits"), function operator(), file Layout.cpp, line 5758.
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And the same for bin/swift-refactor.

Build command:

utils/build-script \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --debug-swift --swift-disable-dead-stripping

Apparently this is something of a known issue in Xcode 15, and there are suggestions that adding the -ld_classic linker flag might resolve it. I checked the release notes for 15.0.1 and 15.1 beta, and neither of them mention it.

Has anybody else encountered this issue? What did you do to resolve it?


Seems to be not fixed as of Xcode 15.1.

What is the correct way to pass -ld_classic through build-script?

I've tried:

  --extra-cmake-options " -DCMAKE_EXE_LINKER_FLAGS_INIT=-ld_classic" \
  --extra-cmake-options " -DCMAKE_STATIC_LINKER_FLAGS_INIT=-ld_classic" \
  --extra-cmake-options " -DCMAKE_MODULE_LINKER_FLAGS_INIT=-ld_classic" \

, but it did not work.

1 Like

For anyone who is working on the compiler and encounters this, cd to your swift build directory and build just the standard library (which builds the compiler) with ninja swift-stdlib-macosx, not everything like build-script does. Chances are you don’t need lldb-moduleimport-test anyway.

1 Like

Settings it through LDFLAGS seems to have worked:

LDFLAGS="-ld_classic" swift/utils/build-script ...

After initial configuration using build-script I see it being applied to incremental builds with ninja even if LDFLAGS is no longer set in the environment.

1 Like

Ran into the same issue, and @anthonylatsis's solution worked for me! In my case (Xcode 15.1) with a clean build, I stopped the build-script once it built the compiler and then built just the standard library with ninja.