# Linker crashes when building tools

**URL:** <https://forums.swift.org/t/linker-crashes-when-building-tools/68332>\
**Category:** Compiler\
**Tags:** build-script, help-needed, buildin-the-compiler\
**Created:** [November 8, 2023, 3:19pm UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332 "2023-11-08T15:19:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [November 8, 2023, 3:19pm UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/1 "2023-11-08T15:19:50Z")

</div>

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)

```swift
[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:

```swift
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](https://developer.apple.com/forums/thread/735426) 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?

---

<div class="post-metadata">

**Author:** ![Nickolas\_Pohilets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nickolas_pohilets/32/10659_2.png) [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Post date:** [December 20, 2023, 6:17pm UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/2 "2023-12-20T18:17:50Z")

</div>

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:

```bash
  ...
  --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.

---

<div class="post-metadata">

**Author:** ![anthonylatsis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anthonylatsis/32/39232_2.png) [@anthonylatsis](https://forums.swift.org/u/anthonylatsis)\
**Post date:** [December 25, 2023, 2:09am UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/3 "2023-12-25T02:09:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nickolas\_Pohilets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nickolas_pohilets/32/10659_2.png) [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Post date:** [December 25, 2023, 4:47pm UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/4 "2023-12-25T16:47:41Z")

</div>

Settings it through `LDFLAGS` seems to have worked:

```bash
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.

---

<div class="post-metadata">

**Author:** ![simanerush](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/simanerush/32/30785_2.png) [@simanerush](https://forums.swift.org/u/simanerush)\
**Post date:** [December 27, 2023, 7:11am UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/5 "2023-12-27T07:11:21Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![rayayay](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@rayayay](https://forums.swift.org/u/rayayay)\
**Post date:** [May 19, 2024, 11:53pm UTC](https://forums.swift.org/t/linker-crashes-when-building-tools/68332/6 "2024-05-19T23:53:42Z")

</div>

Unfortunately using this flag with the `build-script` (as provided in the Getting Started page) will cause the following error

```swift
[3861/5208][74%][51.916s] Linking CXX shared library lib/libclang-cpp.dylib
FAILED: lib/libclang-cpp.dylib
....
ld: unknown option: -no_warn_duplicate_libraries

```

I suspect that flag is not available when using `-ld_classic`?
