Skip to content

fix a crash on Linux arm64 non-SVE CPU - #201

Closed
dimpase wants to merge 1 commit into
kimwalisch:masterfrom
dimpase:arm_sve_fix
Closed

dimpase wants to merge 1 commit into
kimwalisch:masterfrom
dimpase:arm_sve_fix

Conversation

@dimpase

@dimpase dimpase commented Nov 10, 2026 •

Copy link
Copy Markdown

Built with gcc-13 primesieve 12.17 Linux ARM bottle crashes on a CPU without SVE, e.g.

 primesieve 1000000 --count --threads=1

would crash. A register/disassembly capture shows

  cntb x9

executing in the baseline PreSieve::preSieve path even though its SVE runtime flag is false.

More details in dimpase/homebrew-tap#111

Built with gcc-13 primesieve 12.17 Linux ARM bottle crashes on a CPU without SVE,
including primesieve 1000000 --count --threads=1

A register/disassembly capture shows

  cntb x9

executing in the baseline PreSieve::preSieve path even though its SVE
runtime flag is false.

More details in dimpase/homebrew-tap#111
@kimwalisch

Copy link
Copy Markdown
Owner

Hi Dima,

Thanks for the bug report.

I was able to reproduce the bug on an AWS Graviton2 CPU on both Ubuntu 24.04 and Ubuntu 26.04. This crash is caused by a bug in GCC < 14 (tested with GCC 12 and 13); GCC 14 and later compile the code correctly.
The problem is that GCC < 14 inlines functions marked as __attribute__((target("+sve"))) which then causes SVE instructions to be executed on ARM CPUs without ARM SVE support.

Even though this is a GCC bug, not a primesieve bug, I will still add a fix to primesieve (and primecount) to disable ARM SVE for GCC < 14. I will implement that fix in the multiarch_arm_sve.cmake CMake script using the workaround below:

// GCC < 14 inlines the ARM SVE functions into
// the non-SVE caller, which then crashes on
// CPUs without ARM SVE.
#if defined(__GNUC__) && \
    !defined(__clang__) && \
    __GNUC__ < 14
  Error: ARM SVE multiarch requires GCC >= 14!
#endif

@kimwalisch kimwalisch added the bug label Nov 10, 2026
@kimwalisch kimwalisch self-assigned this Nov 10, 2026
@dimpase

dimpase commented Nov 10, 2026 via email

Copy link
Copy Markdown
Author

@kimwalisch

Copy link
Copy Markdown
Owner

I have now committed the fix from my previous post: 989e5b2. In my tests using an AWS Graviton2 CPU with Ubuntu 24.04 and GCC 12 and 13, this fixes the bug (no illegal instruction crash anymore).

This fix disables ARM SVE runtime dispatching for GCC < 14, hence using those compilers the ARM NEON kernels will be used instead. The ARM NEON kernels are virtually as fast as the ARM SVE kernels, so I don't expect any slowdown because of this fix.

@dimpase Can you please confirm that my bug fix also fixes your issue?

@dimpase

dimpase commented Nov 11, 2026 via email

Copy link
Copy Markdown
Author

dimpase commented Nov 12, 2026

Copy link
Copy Markdown
Author

@kimwalisch Confirmed: 989e5b2 fixes our issue, without the patch proposed in this PR.

I built its exact parent (v12.17) and the fix in fresh directories on the same non-SVE Linux ARM64 VM, using Ubuntu 24.04.5 / GCC 13.3.0 and matching -O2 -march=armv8-a flags, with WITH_MULTIARCH=ON. The parent still reproduces SIGILL in primesieve, ECM and Sage; the fixed GCC < 14 probe deliberately disables SVE dispatch and the fixed build passes.

The fix passed all 34 CTests, --test, π(10⁶), π(10¹⁰), and the billionth-prime check. The original ECM and Sage regressions also pass, including all 29 libecm doctests and the complete guarded exp_integral test. ECM and Sage integration used per-process absolute LD_PRELOAD; I checked consumer linkage, Sage process maps and subprocess loader logs to exclude our patched installed primesieve.

Both primesieve source trees were unmodified upstream commits, and installed packages were left unchanged. This confirms the fix for our GCC 13 / non-SVE ARM64 setup. Thanks for the fix!

@kimwalisch

Copy link
Copy Markdown
Owner

Thanks for the feedback. I will do a new bug fix release of both primesieve and primecount in the next days. In primecount-9.0 there was another issue with a unit test that fails on i586 that I only discovered after the release. The new release will fix this issue as well.

@kimwalisch kimwalisch closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants