Skip to content

Enable -mbranch-protection=pac-ret on ARM, except for SimSIMD - #131784

Merged
alexey-milovidov merged 3 commits into
masterfrom
revert-131765-groeneai/revert-119685
Nov 15, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
revert-131765-groeneai/revert-119685

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Re-lands #119685 (-mbranch-protection=pac-ret on ARM), which was reverted in #131765 because the binary died with SIGILL on cores without FEAT_PAuth (Graviton2, Ampere Altra) on the first SimSIMD call.

The cause: SimSIMD compiles its CPU probe _simsimd_capabilities_arm and five bf16 NEON kernels for ARMv8.3+ (target("arch=armv8.5-a+sve") and the like), and in such functions clang folds autiasp; ret into retaa, which, unlike paciasp/autiasp, is not in the NOP space. This PR adds on top of the original change:

Closes: #131748
Related: #119685
Related: #131765
Related: #131762

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Build the C and C++ code of the ARM binaries with -mbranch-protection=pac-ret, which signs the return address so that overwriting it on the stack cannot redirect control flow. Code compiled for ARMv8.3 and later (SimSIMD) is excluded, so the binary still runs on cores without pointer authentication. Sanitizer builds are excluded, because the sanitizer runtimes do not strip the signature when they unwind.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131784]

Version info

  • Merged into: 26.11.1.2377-master (included in 26.11 and later)

@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [643cefd]

Summary: ✅


AI Review

Summary

PR #131784, reviewed at 643cefd965eacfcf238b8809dbe9d4390030d96e, restores ARM return-address signing, excludes the SimSIMD targets that generated incompatible returns, and adds a packaged-binary check for retaa/retab. The previous SimSIMD blocker is addressed in the current code. No new actionable findings.

Missing context / blind spots
  • ⚠️ The current head has no completed ARM release build or compatibility result yet. Successful Build (arm_release) and Compatibility check (arm_release) results will close packaged-binary validation. Eight focused local scanner checks passed; a full ClickHouse build and runtime tests were not run locally.
Final Verdict

✅ Approve. No unresolved code findings; the normal ARM CI checks still need to complete.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 15, 2026
Comment thread CMakeLists.txt Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-build-system Build system (CMake, compilation, platform builds). label Nov 15, 2026
#119685 was reverted in #131765 because the `arm_release` binary died with
SIGILL on cores without `FEAT_PAuth` (Graviton2, Ampere Altra) on the first
SimSIMD call: SimSIMD compiles its CPU probe `_simsimd_capabilities_arm` and
five bf16 NEON kernels for ARMv8.3+, where clang folds `autiasp; ret` into
`retaa`, which is not in the `NOP` space.

Build `_simsimd` with `-mbranch-protection=none` (the same fix as #131762).
Compiled with the `arm_release` flags, `c/lib.c` goes from 7 `retaa` to 0.

Add a check to the `arm_release` compatibility check that scans the code
sections of the packaged binary for `retaa` and `retab` and names the
functions through `system.symbols`. A test run on Graviton3 would never notice
the next such case. On the `arm_release` package of #131745 (pac-ret on) it
reports exactly the 6 SimSIMD functions; on that of d88a8f1 (the master
commit before #119685) it passes.

Closes: #131748
Related: #131762
Related: #131765

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Revert "Revert "Enable -mbranch-protection=pac-ret on ARM"" Enable -mbranch-protection=pac-ret on ARM, except for SimSIMD Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Nov 15, 2026
Building all of `_simsimd` with `-mbranch-protection=none` broke the
`arm_release` link: a callee whose branch protection differs from the
caller's is not inlined, so ThinLTO stopped inlining `simsimd_bf16_to_f32`
from `c/lib.c` into the `vectorize(enable)` loops of usearch, and
`-Wpass-failed` turned "loop not vectorized" into a link error (also in
#131762). Reproduced with a two-file ThinLTO example on clang 21.

Revert that and bump `contrib/SimSIMD` to ClickHouse/SimSIMD@7cd5fbe8bb08
(branch `pac-ret-no-retaa`, on top of the previous pin e81e1c2de244), which
adds `branch-protection=none` to the ARMv8.3+ targets only: the CPU probe
(`arch=armv8.5-a+sve`) and the bf16 kernels (`arch=armv8.6-a+...`).
Compiled with the `arm_release` flags plus `pac-ret`, `c/lib.c` has 0
`retaa` (7 before) and 102 signed functions (109 before).

CI report: https://github.com/ClickHouse/ClickHouse/actions/runs/43723362796/job/132846622615

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 643cefd96 with master f30d7ec4f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 828.88 MiB 828.50 MiB -398.25 KiB (-0.05%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

21 translation units recompiled, 214 s compile time in total, 21 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, send PRs to SIMSIMD upstream.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

I've merged the submodule PR.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I'm checking which ClickHouse/SimSIMD fork fixes (including the merged ClickHouse/SimSIMD#32) are still missing in upstream ashvardanian/NumKong (SimSIMD was renamed there); I'll follow up here with the upstream PR links (or my findings) shortly.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I checked every fix of the ClickHouse/SimSIMD fork against upstream ashvardanian/NumKong (main-dev, where contributions land, now 8.0.0-rc.16). I did not open a PR, because nothing is left there to send:

For #128293, which moves to unpatched v7.8.6: built the way its contrib/NumKong-cmake does, v7.8.6 with pac-ret has 16 retaa, all in *_neonbfdot kernels (taken only when the CPU reports BF16), and none in the CPU probe.

alexey-milovidov pushed a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
…h protection

Bumps `contrib/SimSIMD` to the merge of ClickHouse/SimSIMD#33. The CPU
probe `_simsimd_capabilities_arm` reads `ID_AA64ZFR0_EL1` by its encoding instead of being
compiled for `arch=armv8.5-a+sve`, and the bf16 kernels use `+simd+bf16` / `+sve+sve2+bf16`
instead of `arch=armv8.6-a+...`. Nothing in `SimSIMD` is compiled for ARMv8.3 or later anymore,
so it no longer needs `branch-protection=none` and all of its functions are signed under
`-mbranch-protection=pac-ret`, without `retaa` that would raise SIGILL on cores without
`FEAT_PAuth`.

The bump also brings ClickHouse/SimSIMD#30 (typed kernel dispatch).

Related: ClickHouse/SimSIMD#33
Related: ClickHouse#131748
Related: ClickHouse#131784

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-build-system Build system (CMake, compilation, platform builds). pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIGILL on AArch64 cores without PAuth: SimSIMD CPU probe returns via retaa

3 participants