Since we upgraded a Mac to the latest Xcode (coming from 12.4) to 13.1 or 13.2.1 / commandline tools 13.2 we're hitting an error when linking our executable.
clang: error: unable to execute command: Bus error: 10
clang: error: linker command failed due to signal (use -v to see invocation)
ninja: build stopped: subcommand failed.
It only happens when doing LTO builds. I disabled system hardening to be able to attach LLDB to the linker hoping to find more info on why it might crash and got a huge stack trace:
* frame #0: 0x00000001058087d0 libLTO.dylib`computeKnownBitsFromOperator(llvm::Operator const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) + 32
frame #1: 0x00000001057f6333 libLTO.dylib`computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) + 1523
frame #2: 0x00000001057f5cc9 libLTO.dylib`computeKnownBits(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) + 169
frame #3: 0x00000001058097cd libLTO.dylib`computeKnownBitsFromOperator(llvm::Operator const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) + 4125
total stack size is 24824 frames. There is a clear loop pattern here so either this triggers an endless loop causing the stack to get exhausted or we have something in our code that triggers this deepdive that eventually might resolve when stack room would be a plenty.
It actually looks to be the latter as we have a similar issue on Linux compiles which we fixed by changing the ulimit -s 16384
but that command seems to change absolutely nothing on the mac I'm working on. After changing this in the bash shell (users default shell) it still remains a stack of 24824 frames.
Working here on: Mac OS Monterey 12.1 Mac Pro (2019) - 2.5 GHz 28-Core, 96GB RAM
ld -v :
@(#)PROGRAM:ld PROJECT:ld64-711
BUILD 21:57:11 Nov 17 2021
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 13.0.0, (clang-1300.0.29.30) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 13.0.0 (tapi-1300.0.6.5)