Repository navigation
Enable -mbranch-protection=pac-ret on ARM - #119685
Conversation
Nothing currently protects a saved return address. An overflow of a stack local that reaches far enough rewrites it and control transfers wherever the overflow data points - demonstrated in #119680, where a 2200-byte MySQL `BIT` value moved control to `0x4141414141414141`. With `pac-ret` the prologue signs the return address with `paciasp` and the epilogue authenticates it, so a return address rewritten through memory no longer validates. Both instructions are in the `NOP` encoding space, so the same binary keeps running on cores without `FEAT_PAuth`, just unprotected there; Graviton3 and Graviton4 implement it. Measured on Neoverse V2: +0.78% and +1.36% of text on two translation units, and +0.20 ns per signed call, which is +19% for a function whose body is four instructions and unmeasurable (-0.07%) once a call processes a block of values. Leaf functions stay unsigned by default, so the real fraction of instrumented calls is lower than that microbenchmark suggests. Note this hardens only the ARM builds. `-mbranch-protection` is aarch64-only; the x86-64 counterpart is `-fcf-protection=return`, which needs CET support in both the hardware and the kernel and is a separate question. `bti` is deliberately not included here. The linker keeps the BTI property only when every input object carries it, including hand-written assembly and every contrib, and in my measurements it costs a further 1.7 to 3.6 points of text - so it wants its own audit rather than riding along. Draft: opened to get a performance comparison and a full CI run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [3c1fe49] Summary: ✅
AI ReviewSummaryEnables Signed-frame consumers checked: C++ exception unwinding, Missing context / blind spots
Tests
Final Verdict |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units15959 translation units recompiled, 33520 s compile time in total, 15918 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
No real degradations.
A signed return address on the stack is only readable by an unwinder that strips the signature, and the sanitizer runtimes shipped with the toolchain do not. `compiler-rt`'s frame-pointer unwinder (`BufferedStackTrace::UnwindFast`) collects the allocation and deallocation stacks behind every ASan and LSan report, and the `STRIP_PAC_PC` it applies to a saved return address expands to the identity unless `compiler-rt` itself was compiled with `-mbranch-protection` (`sanitizer_ptrauth.h` gates the `xpaclri` path on `__ARM_FEATURE_PAC_DEFAULT`). The runtime linked into this pull request's own `arm_asan_ubsan` build has no `xpaclri` in `UnwindFast`, so signed frames reach the reports verbatim: the signature sits in the bits above the virtual address, and every frame past the innermost one symbolizes to `<unknown module>`. It is also a memory leak in disguise. `paciasp` mixes `SP` into the signature, so one call site yields a different value at every stack depth, and each one takes a fresh entry in the stack depot, which is never freed. That is visible in CI: `Stateless tests (arm_asan_ubsan, azure, parallel)` hit the 9000 s budget at 8955/13957 on both runs of `db7f4493` with every test `OK`, having peaked at 80.8 and 81.9 GiB where 30 consecutive master runs of the same job peaked at 64 to 74 GiB and finished in ~4500 s. The server crossed the memory-pressure threshold of `clickhouse-test` 11 times and the worker pool drained from 12 to 1 (that regulator only sheds and never restores - issue #119791, fix #119793 - which turned the extra memory into a timeout instead of a slowdown). Our own unwinding is unaffected, which is why nothing else in CI noticed: `StackTrace` and jemalloc's profiler go through `unw_backtrace`, whose DWARF stepper follows `DW_CFA_AARCH64_negate_ra_state`, and the frame-pointer walk that `StackTrace::tryCapture` uses under TSan is abseil's, which strips the signature with `xpaclri` unconditionally. Related: #119791 Related: #119793 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Not every frame of the measured report lost its name: the saved return address in a frame is signed only if the function that spilled it was compiled to sign, and the compiler leaves some functions unsigned. 17 of 21 frames were lost, against 1 of 26 - the frame-pointer-less libc entry - for the same report on master. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 The one red job -
It is also a memory leak in disguise. Related: #119791 Our own unwinding was never at risk, which is why nothing else in CI noticed: |
|
🕵 The |
|
🕵 The sanitizer exclusion is confirmed by the job that caught the problem.
Both remaining reds on this head are unrelated and accounted for: |
The default `aarch64` binary links `skim`, `delta-kernel`, `chdig` and `wasmtime`, and none of that code is signed: `rustc` treats `-Zbranch-protection` as ABI-affecting and refuses it outright while `std` comes precompiled without it - `error: mixing -Zbranch-protection will cause an ABI mismatch in crate lib ... incompatible with unset -Zbranch-protection in dependency std` on the nightly this build uses (1.96.0-nightly). Extending the mitigation there needs either `std` built from source with the same flag - non-sanitizer builds do not pass `-Zbuild-std` - or an explicit `-Cunsafe-allow-abi-mismatch=branch-protection`, which is a decision of its own and not something to smuggle in here. So the flag's promise is the C, C++ and assembly objects, and the comment, the pull request body and the changelog entry now say that instead of "ARM binaries". Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`-mbranch-protection` is a code-generation option, so it says nothing about an input that is assembled rather than compiled: a `.s` file assembles to a byte-identical object with and without the flag (`cmp` on the two, 584 bytes each, no `paciasp` in either), while a non-leaf C function in the same build gains `paciasp` and `autiasp`. `longjmp.s` and `syscall.s` under `base/glibc-compatibility/musl/aarch64` therefore keep unsigned return addresses, as does every prebuilt library we link. What the flag covers is what the compiler generates from the C and C++ sources, and the comment, the pull request body and the changelog entry now say exactly that. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Enumerating the carve-outs one at a time keeps missing one - this time the in-tree `compiler-rt` runtimes, which `contrib/compiler-rt-cmake` builds after filtering the inherited flags down to an allowlist (`_compiler_rt_keep_re`) that drops the hardening ones. So the comment now states the rule instead: the flag covers the code the compiler generates from the sources it is given, and anything compiled with a flag set of its own, assembled rather than compiled, or built by another compiler keeps unsigned return addresses. That filter is also the reason the sanitizer runtimes do not strip the signature when they unwind: `sanitizer_ptrauth.h` gates stripping on `__ARM_FEATURE_PAC_DEFAULT`, and `clang -mbranch-protection=pac-ret -dM -E` shows that is exactly the macro this flag defines. Adding `-mbranch-protection` to that allowlist would therefore both sign those objects and make ASan and LSan reports readable under the flag, which is the way to retire the `NOT SANITIZE` exclusion - noted in the comment, not done here, because it rebuilds every ARM sanitizer runtime and wants its own round of validation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The coverage list said hand-written assembly stays unsigned, which is only true of the raw `.s` inputs. `COMPILER_FLAGS` also feeds `CMAKE_ASM_FLAGS`, and `-mbranch-protection=pac-ret` defines `__ARM_FEATURE_PAC_DEFAULT`, which is what `crypto/arm_arch.h` keys `AARCH64_SIGN_LINK_REGISTER` and `AARCH64_VALIDATE_LINK_REGISTER` on. So the preprocessed OpenSSL `.S` sources that include it do get signed returns. Measured with the toolchain of this build, `clang -c` on `contrib/openssl-cmake/asm/crypto/chacha/chacha-armv8.S`: | | `paciasp` | `autiasp` | object size | PAC property note | | --- | --- | --- | --- | --- | | without the flag | 0 | 0 | 8616 | absent | | with the flag | 4 | 6 | 8752 | present | 13 of the 19 AArch64 OpenSSL sources the build assembles carry those macros. The comment now says that, and separates it from the `.s` inputs and the prebuilt libraries, which do stay unsigned. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 The one red job, Master is merged in (clean, the branch was 2444 commits behind) and the remaining review thread is addressed in 3b31577, with the measurement in the thread: 13 of the 19 AArch64 OpenSSL |
Address review: the AArch64 `jump`/`make`/`ontop` trampolines of `boost::context` are BTI-aware only, so the saved continuation of a stackful coroutine is not signed by this change. Name them in the coverage list. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`clickhouse-test` shed one parallel worker every 30 s while the server's RSS stayed above 80% of `max_server_memory_usage`, and nothing ever started one again. The trigger is a level crossing, so a run whose memory *hovers* at the threshold - not one that runs away - loses its whole pool one worker at a time. On `Stateless tests (arm_asan_ubsan, azure, parallel)` for ClickHouse#119685, eleven sheds in 8 min 47 s took 12 workers down to 1, throughput fell from 144.8 to 11.6 tests/min - 12.5x, exactly the pool ratio - and the 9000 s job timeout killed the run at 8970 of 13957 tests with every test that ran reporting `OK` and no failing test anywhere. The fraction printed 80% or 81% at every one of the eleven sheds and spent 3 min 36 s below the threshold in between; and taking the pool from 12 workers to 4 did not move it by a printed point, because under ASan the server's RSS is allocator state and caches that do not shrink when queries stop. The mechanism was paying throughput for relief it was not getting. Add the missing direction: at or below `MEMORY_RECOVERY_THRESHOLD` a request no worker has claimed yet is withdrawn, or else one shed worker is started again against the same shared queue. The gap to the shed threshold is the hysteresis band that keeps a fraction sitting on the threshold from draining the pool. Give the pool a floor of `jobs // 2` where workers share a queue. Halving concurrency is the largest cut whose worst case, paid from the very first test, still fits a budget sized at about twice the median run; dropping to one worker fits it from no point in the run, so it trades a server that survived for a job killed mid-suite. Where each worker owns its queue (`--no-self-parallel`, used only with `--flaky-check`) a shed worker cannot be started again without re-running its own tests, and those runs are bounded by a time limit rather than a test count, so the pool may still drain to a single worker there, as before. Compute the shed cap from `jobs + workers_restored - shed_requests` instead of `len(processes) - workers_to_shed.value`. A worker claims a request, and commits to stopping, by decrementing `workers_to_shed`, but it stays in `processes` until it has actually exited, so the old cap lags by that window and lets one extra request through - enough, in a streak, to reach zero workers, which ends the parent loop and prints `All tests have finished` with part of the suite never run. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119685&sha=db7f44938b24dba4e56b3ebf049784c7a65532d1&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 Pull request: ClickHouse#119685 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Merged At |
|
But now there are more degradations. Let's investigate. |
|
🕵 I checked the ARM perf report at
Many of the not-reproduced queries are still a few percent slower locally, which fits the general per-call cost. Only the dictionary reload clears its threshold. Why the dictionary reload is slower. This is a different mechanism from the one in the description:
A standalone microbenchmark shows the same effect (clang 21,
That is about +1.8 ns per signed call when the call shares the loop with a cache-missing load. The description measured +0.20 ns for a cache-resident loop, so the cost is about 9 times higher here. The table in the description understates the cost for loops that are memory-latency-bound and call small non-inlined functions, such as hash-table builds, dictionary loads and probably joins. Ways to reduce the dictionary case without dropping the flag: in |
|
🕵 Merged |
`HashedDictionary::blockToAttributes` read every attribute value through a virtual `IColumn::get` into a `Field`, followed by `Field::safeGet`. When the column has the attribute type, read the value directly from `ColumnVector`, `ColumnDecimal` or `ColumnString` (with the null map of `ColumnNullable`). Other columns (`Array`, `Map`, `Object`, or a source returning a different type than the attribute) still go through `Field`. Reloading a 3M-key simple-key dictionary takes 0.20 s instead of 0.34 s on Neoverse V2, for both `HASHED` and `SPARSE_HASHED`. This also recovers the `hashed_dictionary_sharded` and `hashed_dictionary_load_factor` regressions of `-mbranch-protection=pac-ret` on ARM, which come from signing these per-row calls in a loop bound by cache misses. Related: ClickHouse#119685 Related: ClickHouse#119685 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI at I reproduced the The cause is the skip path. Every skipped field goes through Fix: #131462. It skips |
…tcher Reading a few columns from a wide `CustomSeparatedWithNames` file spends most of its time skipping fields. Each skipped field went through `skipFieldDelimiter` -> `assertString` -> `checkString` and `skipField` -> `skipFieldByEscapingRule` -> `readEscapedStringIntoImpl`. `skipFieldByEscapingRule` is a small out-of-line switch that tail-calls the reader, so with `-mbranch-protection=pac-ret` every field adds a serial `autiasp` -> `paciasp` dependency on `x30`. On Neoverse V2 this made `formats_columns_sampling` and `count_from_formats` on `CustomSeparated` 20-25% slower in ClickHouse#119685, while `TabSeparatedWithNames`, whose `skipField` calls the reader directly, changed by 1%. Read `Escaped` and `Raw` fields directly, as `TabSeparatedFormatReader::skipField` does, and check a one-character field delimiter with the inline `assertChar`. Other escaping rules and multi-character delimiters keep the previous path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
The ARM |
|
🕵 ARM perf at I don't think these come from
Each process stays in a fast or slow mode for all of its queries, and |
…ranch-protection-arm" This reverts commit 46106b1, reversing changes made to d88a8f1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#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]>
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 127836 124816 Revert "Avoid building stream names and substreams cache keys for every block in MergeTreeReaderWide" Changelog-revert: 128706 116083 Revert "Fit the insert pipeline and merges into a small server's memory" Changelog-revert: 128760 128658 Revert "Prewarm macOS code signature verification of the clickhouse binary after linking" Changelog-revert: 128947 127422 Revert "[GPU] `GDeflate` compression codec on the CPU" Changelog-revert: 129099 128947 Revert "Revert "[GPU] `GDeflate` compression codec on the CPU"" Changelog-revert: 129310 127149 Revert "Mark a query as cancelled in the process list when its TCP client cancels it" Changelog-revert: 129311 129310 Revert "Revert "Mark a query as cancelled in the process list when its TCP client cancels it"" Changelog-revert: 129862 129425 Revert "Add 7 tests for coverage gaps in 5 components" Changelog-revert: 129863 129862 Fix `GLOBAL IN` in projection `WHERE` with parallel replicas; restore coverage tests Changelog-revert: 129986 122871 Revert "Search long integer slices in 512-byte chunks on AArch64 in `hasAll` and `hasAny`" Changelog-revert: 130046 129986 Revert "Revert "Search long integer slices in 512-byte chunks on AArch64 in `hasAll` and `hasAny`"" Changelog-revert: 130368 114729 Revert "CI: run the full test suite only when review threads are resolved" Changelog-revert: 130509 130368 Revert "Revert "CI: run the full test suite only when review threads are resolved"" Changelog-revert: 130531 114923 Revert "Make a table read by a scalar subquery in a CONSTRAINT a loading dependency" Changelog-revert: 131043 129464 Revert "Sync shared files changed by the private `AmberMap` PR" Changelog-revert: 131045 130793 Revert "Fix wrong ORDER BY ... LIMIT results on Delta Lake tables with column mapping" Changelog-revert: 131270 128764 Re-enable the adaptive aggregator for queries generated from PromQL Changelog-revert: 131424 122826 Revert "Forbid renaming the source of incremental refreshable views" Changelog-revert: 131562 131454 Revert "Build the symbol index in the background at server startup" Changelog-revert: 131638 131562 Revert "Revert "Build the symbol index in the background at server startup"" Changelog-revert: 131691 130864 Revert "Use one source instead of N for parallel_inserts of AzureQueue/S3Queue" Changelog-revert: 131765 119685 Revert "Enable `-mbranch-protection=pac-ret` on ARM" Changelog-deleted-entry: 116083 [Performance Improvement] [section] * Reduce memory use for `INSERT` and background merges on servers with a few GiB of RAM. Write buffers, insert squashing, the `Parquet` reader and merge selection now scale with `max_server_memory_usage`, avoiding `MEMORY_LIMIT_EXCEEDED` during wide-table inserts and merges that repeatedly fail without reducing the part count. New `MergeTree` settings `max_memory_ratio_to_activate_adaptive_write_buffer` and `merge_memory_estimate_per_source_part_column` control adaptive write buffers and merge selection, respectively; set either to `0` to disable that adjustment. [#116083](#116083) ([Alexey Milovidov](https://github.com/alexey-milovidov)). Changelog-deleted-entry: 119685 [Build/Testing/Packaging Improvement] [raw] * 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; the AArch64 `.S` sources that key off `__ARM_FEATURE_PAC_DEFAULT` opt into the same signing. Sanitizer builds are excluded, because the sanitizer runtimes do not strip the signature when they unwind. [#119685](#119685) ([Alexey Milovidov](https://github.com/alexey-milovidov)). Changelog-deleted-entry: 122826 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Forbid renaming the source of incremental refreshable views closes #[#120082](#120082). [#122826](#122826) ([Smita Kulkarni](https://github.com/SmitaRKulkarni)). Changelog-deleted-entry: 128658 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Prewarm macOS code signature verification of the clickhouse binary after linking. [#128658](#128658) ([Azat Khuzhin](https://github.com/azat)). Changelog-deleted-entry: 128764 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Disable the adaptive aggregator for queries generated from PromQL. [#128764](#128764) ([Vitaly Baranov](https://github.com/vitlibar)). Changelog-deleted-entry: 129464 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Sync shared files changed by the private `AmberMap` PR. [#129464](#129464) ([Miсhael Stetsyuk](https://github.com/mstetsyuk)). Changelog-deleted-entry: 130793 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed wrong results of `ORDER BY ... LIMIT` on a Delta Lake table with column mapping when a renamed column has the name that another column is stored under: the top-K dynamic filter (`use_top_k_dynamic_filtering`) compared the other column against the threshold and dropped rows of the true result. [#130793](#130793) ([Groene AI](https://github.com/groeneai)). Changelog-deleted-entry: 130864 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Use one source instead of N for parallel_inserts of AzureQueue/S3Queue. [#130864](#130864) ([Azat Khuzhin](https://github.com/azat)).
Nothing currently protects a saved return address. An overflow of a stack local that reaches far enough rewrites it and control transfers wherever the overflow data points - demonstrated in #119680, where a 2200-byte MySQL
BITvalue moved control to0x4141414141414141.With
pac-retthe prologue signs the return address withpaciaspand the epilogue authenticates it, so a return address rewritten through memory no longer validates. Both instructions sit in theNOPencoding space, so the same binary keeps running on cores withoutFEAT_PAuth- unprotected there, but not broken. Graviton3 and Graviton4 implement it (pacaandpacgin/proc/cpuinfo).Measured on Neoverse V2:
pacinstructionsParsers/ExpressionElementParsersProcessors/Sources/MySQLSourcepac-retThat is +0.20 ns per signed call. The microbenchmark signs leaf functions to measure them at all (
pac-ret+leaf); the flag as proposed leaves leaves unsigned, which is the default and free, since they do not spill the return address - so the real blended cost is below what the table shows.Three limits worth stating plainly:
This hardens only the ARM builds, and within them only the code the compiler generates from the
CandC++sources it is given, plus the assembly sources that opt in themselves through the feature macro it defines. Anything compiled with a flag set of its own, assembled without that opt-in, or built by another compiler keeps unsigned return addresses - see the three cases below.-mbranch-protectionisaarch64-only; the x86-64 counterpart is-fcf-protection=return, which needs CET in both hardware and kernel, and is a separate question. The Rust objects the defaultaarch64binary links -skim,delta-kernel,chdig,wasmtime- keep unsigned return addresses, becauserustctreats-Zbranch-protectionas ABI-affecting and refuses it outright whilestdcomes precompiled without it:Signing them needs either
stdbuilt from source with the same flag (non-sanitizer builds do not pass-Zbuild-std) or an explicit-Cunsafe-allow-abi-mismatch=branch-protection, so it wants its own change rather than riding along here.The raw
.sinputs are not signed either, for a duller reason:-mbranch-protectionis a code-generation option and says nothing about an input that is assembled rather than compiled. A.sfile assembles to a byte-identical object with and without the flag (584 bytes either way, nopaciaspin either), while a non-leaf C function in the same build gainspaciasp/autiasp. Solongjmp.sandsyscall.sunderbase/glibc-compatibility/musl/aarch64keep unsigned return addresses, as does every prebuilt library we link.Preprocessed
.Ssources are the one case that goes the other way, and they do it themselves rather than through code generation.COMPILER_FLAGSalso feedsCMAKE_ASM_FLAGS, and the flag defines__ARM_FEATURE_PAC_DEFAULT, which is exactly whatcrypto/arm_arch.hkeysAARCH64_SIGN_LINK_REGISTERandAARCH64_VALIDATE_LINK_REGISTERon. 13 of the 19 AArch64 OpenSSL sources this build assembles include that header, so they gain signed returns and the AArch64 PAC property note.clang -concontrib/openssl-cmake/asm/crypto/chacha/chacha-armv8.Swith the toolchain of this build:paciaspautiaspThe
boost::contextswitch trampolines (jump_arm64_aapcs_elf_gas.S,make_arm64_aapcs_elf_gas.S,ontop_arm64_aapcs_elf_gas.S) do not opt in: they key only BTI off the feature macros, savex30into the suspended fiber's stack and resume through it with a plainret, so stackful-coroutine continuations stay outside this protection. Signing them cannot reusepaciasp, because a continuation resumes on a differentSPfrom the one it was saved on; that wants its own change.And the in-tree
compiler-rtruntimes are not signed:contrib/compiler-rt-cmakefilters the inherited flags down to an allowlist (_compiler_rt_keep_re) which drops the hardening ones. That filter is also why their unwinder does not strip the signature -sanitizer_ptrauth.hgates stripping on__ARM_FEATURE_PAC_DEFAULT, andclang -mbranch-protection=pac-ret -dM -Eshows that is exactly the macro this flag defines. So adding-mbranch-protectionto that allowlist would both sign those objects and make ASan and LSan reports readable under the flag, which is how theNOT SANITIZEexclusion above can be retired. Not done here: it rebuilds every ARM sanitizer runtime and wants its own round of validation.btiis deliberately excluded. The linker keepsGNU_PROPERTY_AARCH64_FEATURE_1_BTIonly when every input object carries it, including hand-written assembly and every contrib; otherwise it is dropped for the whole image and you pay the size for nothing. It measured a further 1.7 to 3.6 points of text, so it wants its own audit rather than riding along here.Sanitizer builds are excluded (
NOT SANITIZE), because a signed return address on the stack is only readable by an unwinder that strips the signature, and the sanitizer runtimes shipped with the toolchain do not.compiler-rt's frame-pointer unwinderBufferedStackTrace::UnwindFastcollects the allocation and deallocation stacks behind every ASan and LSan report, and theSTRIP_PAC_PCit applies to a saved return address expands to the identity unlesscompiler-rtitself was compiled with-mbranch-protection:sanitizer_ptrauth.hgates thexpaclripath on__ARM_FEATURE_PAC_DEFAULT.UnwindFastis byte-for-byte the same 87 instructions in thearm_asan_ubsanbinaries of both this branch and master, and neither contains anxpaclri, so the signature travels into the report unchanged - it occupies the bits above the virtual address, and 17 of these 21 frames are gone:The same query against the
arm_asan_ubsanbinary of masterd9049413- same toolchain, same runtime, andUnwindFastdisassembles to the same 87 instructions in both - prints the whole chain instead, all 26 frames frommallocthroughDB::InterpreterSystemQuery::executedown tomain, with only the final frame-pointer-less libc frame missing.It is also a memory leak in disguise.
paciaspmixesSPinto the signature, so one call site yields a different value at every stack depth and each one takes a fresh entry in the stack depot, which is never freed. That is what killedStateless tests (arm_asan_ubsan, azure, parallel)ondb7f4493: both of its runs peaked at 80.8 and 81.9 GiB where 30 consecutive master runs of the same job peaked at 64 to 74 GiB, the server crossed the memory-pressure threshold ofclickhouse-test11 times, the worker pool drained from 12 workers to 1, and the job hit its 9000 s budget at 8955 of 13957 tests with every testOKand noFAILline. The drain never reverses (issueclickhouse-testsheds parallel workers under memory pressure and never restores them, so a run that hovers at the threshold drains to one worker and is killed by the job timeout mid-suite #119791, fix Follow server memory in both directions when shedding test workers #119793), which is what turned the extra memory into a timeout rather than a slowdown.Our own unwinding is unaffected, which is why nothing else in CI noticed:
StackTraceand jemalloc's profiler go throughunw_backtrace, whose DWARF stepper followsDW_CFA_AARCH64_negate_ra_state, and the frame-pointer walk thatStackTrace::tryCaptureuses under TSan is abseil's, which strips the signature withxpaclriunconditionally.Related: #119680
Related: #119684
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Build the
CandC++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; the AArch64.Ssources that key off__ARM_FEATURE_PAC_DEFAULTopt into the same signing. Sanitizer builds are excluded, because the sanitizer runtimes do not strip the signature when they unwind.Workflow [PR]
Sync PR [sync-upstream/pr/119685]
Version info
26.11.1.2333-master(included in26.11and later)