Skip to content

Commit 27741d9

Browse files
nickitatclaude
andcommitted
Keep the BTI landing pads in functions built for ARMv8.3 and later
`branch-protection=none` on the ARMv8.3+ targets (the CPU probe and the bf16 kernels) removed `bti c` along with the return-address signing. In an executable with the BTI property, the kernels are called through the dispatch table, so the first call of `simsimd_dot_bf16_neon` from `simsimd_capabilities` raises SIGILL. Use `branch-protection=bti`: it keeps the landing pad, which is a `NOP` on older cores, and still does not sign, so there is still no `retaa`. Related: ClickHouse/ClickHouse#130510 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
1 parent 7cd5fbe commit 27741d9

6 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎include/simsimd/curved.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ SIMSIMD_PUBLIC void simsimd_bilinear_f16c_neon(simsimd_f16c_t const *a, simsimd_
501501

502502
#if SIMSIMD_TARGET_NEON_BF16
503503
#pragma GCC push_options
504-
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=none")
505-
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=none"))), apply_to = function)
504+
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=bti")
505+
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=bti"))), apply_to = function)
506506

507507
SIMSIMD_PUBLIC void simsimd_bilinear_bf16_neon(simsimd_bf16_t const *a, simsimd_bf16_t const *b,
508508
simsimd_bf16_t const *c, simsimd_size_t n, simsimd_distance_t *result) {

‎include/simsimd/dot.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ SIMSIMD_PUBLIC void simsimd_vdot_f16c_neon(simsimd_f16c_t const *a_pairs, simsim
525525

526526
#if SIMSIMD_TARGET_NEON_BF16
527527
#pragma GCC push_options
528-
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=none")
529-
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=none"))), apply_to = function)
528+
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=bti")
529+
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=bti"))), apply_to = function)
530530

531531
SIMSIMD_INTERNAL bfloat16x8_t _simsimd_partial_load_bf16x8_neon(simsimd_bf16_t const *x, simsimd_size_t n) {
532532
union {

‎include/simsimd/elementwise.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,8 @@ SIMSIMD_PUBLIC void simsimd_fma_f32_neon( //
20532053

20542054
#if SIMSIMD_TARGET_NEON_BF16
20552055
#pragma GCC push_options
2056-
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=none")
2057-
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=none"))), apply_to = function)
2056+
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=bti")
2057+
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=bti"))), apply_to = function)
20582058

20592059
SIMSIMD_PUBLIC void simsimd_sum_bf16_neon(simsimd_bf16_t const *a, simsimd_bf16_t const *b, simsimd_size_t n,
20602060
simsimd_bf16_t *result) {

‎include/simsimd/simsimd.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,17 @@ SIMSIMD_PUBLIC simsimd_capability_t _simsimd_capabilities_x86(void) {
471471
* Suppressing assembler errors is very complicated, so when dealing with older ARM CPUs it's simpler to compile this
472472
* function targeting newer ones.
473473
*
474-
* `branch-protection=none` here and on every other target of ARMv8.3 or later: such a target has `FEAT_PAuth`, so
474+
* `branch-protection=bti` here and on every other target of ARMv8.3 or later: such a target has `FEAT_PAuth`, so
475475
* under `-mbranch-protection=pac-ret` the compiler folds `autiasp; ret` into `retaa`, which, unlike `autiasp`, is not
476476
* a `NOP` on older cores and raises SIGILL there - in this probe, before anything is dispatched. Code for ARMv8.2 and
477477
* older keeps the signing, and its attributes must match the callers' for (Thin)LTO to inline it.
478+
* It is `bti` rather than `none`, because the kernels are called through the dispatch table: in an executable with
479+
* the BTI property, a function without the `bti c` landing pad raises SIGILL when called through a pointer. `bti c`
480+
* is in the `NOP` space too.
478481
*/
479482
#pragma GCC push_options
480-
#pragma GCC target("arch=armv8.5-a+sve,branch-protection=none")
481-
#pragma clang attribute push(__attribute__((target("arch=armv8.5-a+sve,branch-protection=none"))), apply_to = function)
483+
#pragma GCC target("arch=armv8.5-a+sve,branch-protection=bti")
484+
#pragma clang attribute push(__attribute__((target("arch=armv8.5-a+sve,branch-protection=bti"))), apply_to = function)
482485

483486
#if _SIMSIMD_HAS_POSIX_EXTENSIONS
484487
/** @brief SIGILL handler for `mrs` instruction testing on Linux ARM */

‎include/simsimd/sparse.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,8 @@ SIMSIMD_PUBLIC void simsimd_spdot_counts_u16_sve2( //
12921292

12931293
#if SIMSIMD_TARGET_SVE2 && SIMSIMD_TARGET_SVE_BF16
12941294
#pragma GCC push_options
1295-
#pragma GCC target("arch=armv8.6-a+sve+sve2+bf16,branch-protection=none")
1296-
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+sve+sve2+bf16,branch-protection=none"))), apply_to = function)
1295+
#pragma GCC target("arch=armv8.6-a+sve+sve2+bf16,branch-protection=bti")
1296+
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+sve+sve2+bf16,branch-protection=bti"))), apply_to = function)
12971297

12981298
SIMSIMD_PUBLIC void simsimd_spdot_weights_u16_sve2( //
12991299
simsimd_u16_t const *a, simsimd_u16_t const *b, //

‎include/simsimd/spatial.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ SIMSIMD_PUBLIC void simsimd_cos_f16_neon(simsimd_f16_t const *a, simsimd_f16_t c
469469

470470
#if SIMSIMD_TARGET_NEON_BF16
471471
#pragma GCC push_options
472-
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=none")
473-
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=none"))), apply_to = function)
472+
#pragma GCC target("arch=armv8.6-a+simd+bf16,branch-protection=bti")
473+
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16,branch-protection=bti"))), apply_to = function)
474474

475475
SIMSIMD_PUBLIC void simsimd_cos_bf16_neon(simsimd_bf16_t const *a, simsimd_bf16_t const *b, simsimd_size_t n,
476476
simsimd_distance_t *result) {

0 commit comments

Comments
 (0)