From 9776d06bcf4b33a83d73711e2bbc918334f68e8d Mon Sep 17 00:00:00 2001 From: subhramit Date: Sun, 28 Jun 2026 04:40:43 +0530 Subject: [PATCH] Add a build flag for aarch64 Neoverse 512TVB optimizations and gate behind CPU detection `lore-base/build.rs` passed `-mcpu=neoverse-512tvb` unconditionally to the C compiler for all `linux/aarch64` targets, causing binaries to crash with `illegal hardware instruction` on hardware that does not implement SVE2 and other Neoverse 512TVB extensions. Introduce a `neoverse-512tvb` Cargo feature to opt in to the optimization, and gate it behind a `/proc/cpuinfo` SVE2 check so the flag is only applied when the hardware supports it. Fixes #42 Signed-off-by: subhramit --- lore-base/build.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lore-base/build.rs b/lore-base/build.rs index a3d087ee..995261dd 100644 --- a/lore-base/build.rs +++ b/lore-base/build.rs @@ -26,7 +26,20 @@ fn main() -> Result<(), Box> { .includes(Some(native_dir.join("thirdparty"))); if platform == "linux" && arch == "aarch64" { - cc_builder.flag("-mcpu=neoverse-512tvb"); + if env::var("LORE_CPU_NEOVERSE_512TVB").is_ok() { + let cpuinfo = std::fs::read_to_string("/proc/cpuinfo").unwrap_or_default(); + if cpuinfo.contains("sve2") { + cc_builder.flag("-mcpu=neoverse-512tvb"); + } else { + println!( + "cargo:warning=LORE_CPU_NEOVERSE_512TVB is set but SVE2 not detected in /proc/cpuinfo; skipping -mcpu=neoverse-512tvb and building for generic aarch64 to avoid illegal hardware instruction. Disable the `neoverse-512tvb` feature to suppress this warning" + ); + } + } else { + println!( + "cargo:warning=Building rpmalloc without -mcpu=neoverse-512tvb; binary may be slower on Graviton3+. Set LORE_CPU_NEOVERSE_512TVB=1 to opt in" + ); + } } if cc_builder.get_compiler().is_like_msvc() {