LLVM Linker Crash on ARM64 with bfloat16 Symbols (Xcode 17.0.0)
We're encountering a critical linker crash in Xcode 17.0.0 (clang-1700.4.4.1) on macOS 15.1.0 (Darwin 25.1.0) with Apple Silicon M3 Max when linking a pybind11 C++ extension against the MLX framework (v0.30.1). The linker consistently crashes with LLVM ERROR: No way to correctly truncate anything but float to bfloat during the linking phase, even though our code uses only integer types (int64, uint32) for BPE tokenization and never directly references bfloat16 types.
Error Details: [100%] Linking CXX shared module _metal_trainer.cpython-312-darwin.so LLVM ERROR: No way to correctly truncate anything but float to bfloat clang++: error: unable to execute command: Abort trap: 6 clang++: error: linker command failed due to signal (use -v to see invocation)
Reproduction:
- Install MLX framework: pip install mlx (any version with bfloat16 support)
- Create a minimal pybind11 extension that links against MLX:
- Compiler: AppleClang 17.0.0.17000404
- Target: arm64-apple-darwin25.1.0
- Flags: -std=c++17 -O2 -march=native
- Link against: libmlx.dylib (contains bfloat16 symbols)
- Run: cmake .. && make
- Linker crashes during final linking phase
Root Cause: The LLVM ARM64 backend in Xcode 17.0.0 has a code generation bug when processing bfloat16 truncation operations during link-time. The crash occurs when the linker processes bfloat16 symbols from libmlx.dylib, regardless of whether the application code uses them. The error originates from LLVM's type legalization pass attempting to truncate bfloat16 values, but the ARM64 backend lacks a valid code path for this operation.
Workarounds Attempted (all failed):
- Disabling LTO: INTERPROCEDURAL_OPTIMIZATION FALSE
- Linker flags: -Wl,-no_compact_unwind, -fno-lto
- Runtime symbol resolution: -undefined dynamic_lookup
- Compiler optimizations: Changed from -O3 to -O2
- Impact: This blocks any C++ extension development that links against libraries containing bfloat16 symbols on Xcode 17.0.0. The issue does not occur on Xcode 16.x.
Linker Crash Dump Location: /var/folders/gn/7_g6wy1j66b8z3lkywyrbsx00000gn/T/linker-crash-*
Expected Behavior: Linker should successfully link the extension, or at minimum, gracefully handle bfloat16 symbols without crashing.
Temporary Solution: Downgrade to Xcode 16.x or use Python-only implementations until this is fixed in a future Xcode release.