Skip to content

illegal hardware instruction on M4 Max CPU #35

@bergkvist

Description

@bergkvist

The C++ benchmarking example works fine on the main branch:

cmake -B build_release -D CMAKE_BUILD_TYPE=Release
cmake --build build_release --config Release
time NBODY_COUNT=128 NBODY_ITERATIONS=1000000 NBODY_BACKEND=fork_union_static build_release/fork_union_nbody
time NBODY_COUNT=128 NBODY_ITERATIONS=1000000 NBODY_BACKEND=fork_union_dynamic build_release/fork_union_nbody

But when running the Rust nbody program, it crashes with an illegal hardware instruction error:

cargo run --release --example nbody
[1]    51963 illegal hardware instruction  cargo run --release --example nbody

By adding some println! statements, I narrowed this down to happening somewhere inside the following statement:

let mut pool = fu::ThreadPool::try_spawn(threads).unwrap_or_else(|e| panic!("Failed to start Fork-Union pool: {e}"))

Running git bisect, shows that the illegal hardware instruction crash was introduced by this commit: 243a6be

Git bisect log
git checkout main
git bisect start
cargo run --release --example nbody && git bisect good || git bisect bad
# [1]    67318 illegal hardware instruction  cargo run --release --example nbody
# status: waiting for good commit(s), bad commit known

git checkout v2.2.0
cargo run --release --example nbody && git bisect good || git bisect bad
# Bisecting: 45 revisions left to test after this (roughly 6 steps)
# [92cf3e6b4f6785ea6fefb160f9331cf57589faab] Make: Check for `-fcf-protection`

cargo run --release --example nbody && git bisect good || git bisect bad
# [1]    69606 illegal hardware instruction  cargo run --release --example nbody
# Bisecting: 22 revisions left to test after this (roughly 5 steps)
# [24f060a5973741394df89437442190e1342180c6] Fix: Missing `+wfxt` for `arch=armv8-a`

cargo run --release --example nbody && git bisect good || git bisect bad
# Bisecting: 11 revisions left to test after this (roughly 4 steps)
# [6e3b4657f5960db7321944d75b5f70ffe335dcef] Merge branch 'main-dev' of # https://github.com/ashvardanian/fork_union into main-dev

cargo run --release --example nbody && git bisect good || git bisect bad
# [1]    71471 illegal hardware instruction  cargo run --release --example nbody
# Bisecting: 5 revisions left to test after this (roughly 3 steps)
# [cc14f8094c25c64ed2c4f9eaa00950a01d13788f] Docs: Wording inconsistency

cargo run --release --example nbody && git bisect good || git bisect bad
# [1]    72092 illegal hardware instruction  cargo run --release --example nbody
# Bisecting: 2 revisions left to test after this (roughly 1 step)
# [243a6be821d913ed80a23a36467a6b9018ed50d8] Fix: Wrong macro conditions

cargo run --release --example nbody && git bisect good || git bisect bad
# [1]    72568 illegal hardware instruction  cargo run --release --example nbody
# Bisecting: 0 revisions left to test after this (roughly 0 steps)
# [c613f501a02c3d6b0f4f82ed8638f2427ae2923e] Release: v2.2.5 [skip ci] ### Patch

cargo run --release --example nbody && git bisect good || git bisect bad
# 243a6be821d913ed80a23a36467a6b9018ed50d8 is the first bad commit
# commit 243a6be821d913ed80a23a36467a6b9018ed50d8
# Author: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com>
# Date:   Fri Sep 5 12:19:21 2025 +0100
# 
#     Fix: Wrong macro conditions
#
# c/lib.cpp | 40 ++++++++++++++++++++--------------------
# 1 file changed, 20 insertions(+), 20 deletions(-)

My system information:

  • OS: macOS 15.6.1 24G90 arm64
  • CPU/GPU: Apple M4 Max (36GB RAM)
  • cargo version: cargo 1.91.0-nightly (761c4658d 2025-09-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions