Repository navigation
Conversation
A function now clears the general purpose registers it used before it returns, so its epilogue cannot hand their values to a return-oriented programming chain. The flag goes into COMPILER_FLAGS next to the stack protector, so it reaches src/, programs/, base/ and contrib, including libc++, libunwind and the glibc compatibility layer. It is set only for x86-64 and AArch64: clang 22 rejects it for powerpc64le, riscv64, s390x, loongarch64 and wasm64. Sanitizer and fuzzer builds do not get it: they are not shipped, and their images are already close to the 2 GiB reach of 32-bit PC-relative references. contrib/compiler-rt-cmake resets inherited flags to an allowlist, so the builtins stay out, as they do for the stack protector. In a local build with the amd_release PR configuration, 17285 of 17643 compile commands carry the flag (the rest are compiler-rt and the NASM sources of isa-l), and the MSan, ASan+UBSan, fuzzer and riscv64 configurations carry it nowhere. In the linked ThinLTO binary 72.9% of `ret` instructions follow a register-zeroing `xor`, against 1.2% without the flag. Return blocks that grow past LLVM's tail-duplication threshold are no longer copied into their predecessors, so some functions (for example `memcmp` and `bcmp`) now reach one shared exit through a `jmp`. `.text` grows by 4.1 MB (+0.78%), the compressed binary by 0.46 MB (+0.16%). Related: ClickHouse#127959 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 runs on this tree, the second after the description was narrowed) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20261027-184000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261027-183000 |
|
cc @Algunenano @pamarcos, could you review this and add the |
|
Workflow [PR], commit [f2cd0fc] Summary: ❌
AI ReviewSummaryThis enables Findings❌ Blockers
Missing context / blind spots
Tests
Performance & SafetyThe current Praktika reports and machine-readable metrics contain these ARM changes exceeding 10% that are classified as changed or unstable, plus the separately confirmed
No changed-query improvements appear in the four fresh ARM shards. The additional confirmations strengthen the same global-overhead finding; they do not warrant separate inline comments. Final Verdict❌ Block. Address the repeatable hot-path regressions or obtain explicit maintainer acceptance of the revised performance budget, and complete the requested x86-64 and AArch64 measurements for the final configuration. |
| # fuzzer builds: they are not shipped, and their images are already close to the 2 GiB reach of 32-bit PC-relative | ||
| # references. contrib/compiler-rt-cmake resets it like the flags above. | ||
| if ((ARCH_AMD64 OR ARCH_AARCH64) AND NOT SANITIZE AND NOT ENABLE_FUZZING) | ||
| set (COMPILER_FLAGS "${COMPILER_FLAGS} -fzero-call-used-regs=used-gpr") |
There was a problem hiding this comment.
❌ Avoid enabling register clearing unconditionally with these hot-path regressions
Adding this to COMPILER_FLAGS makes the overhead mandatory in production builds, including per-row hashing, formatting, and OpenSSL calls. The ARM comparison reports encrypt_decrypt #2 at +17.3%, general_purpose_hashes_on_UUID #7 at +15.7%, and bigint_formatting #4 at +15.7%; the latter two still regress by +15.9% and +11.6% after restarting the servers. Master history for 2026-09-28 through 2026-10-28 has zero slower results for these cases in 932, 192, and 1,065 runs respectively. This exceeds the linked issue's requirement to enable only hardening whose cost is within noise.
Please keep this behind an opt-in build option, or mitigate the measured hot paths before enabling it globally, then measure the final configuration on both architectures. Accepting these regressions instead needs an explicit maintainer decision to change that performance budget.
CI finish ledger - f2cd0fcEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The per-arch geomean (+0.57% amd, +0.78% arm) and the attribution are in the PR description; this PR stays a draft until that decision. The first run of this head stopped at Session id: cron:our-pr-ci-monitor:20261028-073003 |
|
Closing as rejected: +0.57% amd64 and +0.78% arm64 geomean cost, with reproducible individual regressions up to 26%. The other two proposals in #127959 merged; no hot-function exemptions proposed here. |
|
Closed as rejected; see outcome above. |
Related: #127959
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Build with
-fzero-call-used-regs=used-gpron x86-64 and AArch64, so that a function clears the general purpose registers it used before it returns, and its epilogue cannot hand their values to a return-oriented programming chain.Description
This is the first of the three items of #127959; the other two are handled separately, so that each one is measured on its own.
-fzero-call-used-regs=used-gprgoes intoCOMPILER_FLAGSafter-fstack-clash-protection, so it reachessrc/,programs/,base/andcontrib(exceptcontrib/compiler-rt-cmake, which resets flags to an allowlist). It is set only for x86-64 and AArch64: clang 22 rejects it for powerpc64le, riscv64, s390x, loongarch64 and wasm64. Builds withSANITIZEorENABLE_FUZZINGset do not get it: they are not shipped, and the MSan and fuzzer images are already close to the 2 GiB reach of 32-bit PC-relative references.Every return path now zeroes all the caller-saved general purpose registers that the function uses anywhere, and many functions that returned from several places now branch to one shared exit.
src/Common/remapExecutable.cpponly gainsxors before itsrets, and thememcpydispatch stays a frameless tailjmp. No query can observe the change, so no test is added; in a 5% slice of the stateless tests, no test fails with the flag and passes without it.Performance Comparison (
b4fae47plus this change againstb4fae47):arm_releasegeomean +0.78% over 4,190 queries (+0.67% to +1.00% per shard), slowerencrypt_decrypt#2 +17%,general_purpose_hashes_on_UUID#7 +16%,bigint_formatting#4 +16%,json_to_string#1 +69% (noisy: 142 other PRs in 30 days);amd_release+0.57% over 4,186 queries (+0.43% to +0.71%), slowerset_in_clustered_keys#0 +26%,uint64_to_string#2 +20%,trim_numbers#2 +18%, fasteruint64_to_string#5 -25%. Exceptjson_to_string, all reproduce locally with the CI x86-64 binaries (+7% to +21%, and -25%);perfputs the difference in per-row functions whose returns now zero registers, mostly at one shared exit: OpenSSL EVP,farmHash64,itoa/toChars,bcmp, andpowfor the faster one.CI binary size: compressed +0.17% (x86-64) and +0.31% (AArch64),
.text+0.78% and +2.29%.Per-function zeroing, local numbers, largest slowdowns
reton AArch64 (CI binaries):farmhashxo::Hash6417mov xN, #0(7 returns merged into 1),itoa(UInt128)15 (9 into 1),CityHash6417 (7 into 1; its 9 to 16 byte path is 22 instructions), OpenSSLCRYPTO_ctr128_encrypt_ctr3216,evp_cipher_init_internal12,EVP_EncryptUpdate6. On x86-64,farmhashxo::Hash64,itoa(UInt128)andCityHash64get 6 to 8xors. The set is computed over the whole function (insertZeroCallUsedRegsin LLVM'sPrologEpilogInserter.cpp).encrypt('aes-128-ctr', ...)+7.0%,farmHash64(generateUUIDv4())+10.6%,toString(toUInt128(number))+20.8%,cityHash64(toDecimal128(number, 23))+22.1%,set_in_clustered_keys#0 +19.4%,uint64_to_stringRepair subtree2 #2 +14.3%,trim_numbersRepair subtree2 #2 (100M rows) +13.8%,uint64_to_stringExtra include for std::mt19937_64 #5 -24.7%; controls -2.8% to +0.5%.perf:bcmp821 to 1,596 samples (FixedSizeKeySlices::rowsEqualcallsmemcmpper row);avx512ifma::toChars(3 returns into 1, 8xors) +18% to +41%,itoa(UInt64)(7 into 1) +50% to +65%;pow2,935 to 1,733 (2 returns into 1, 9xors; I have not established why it is faster).arm_releasejson_to_stringRepair subtree2 #1 +69%,index_bulk_filteringRepair subtree2 #2 +29%,consistent_hashes#0 +27% (unstable),array_compactRepair subtree2 #2 +26%,consistent_hashesRepair subtree2 #2 +26% (unstable);amd_releaseset_in_clustered_keys#0 +26%,distinct_in_orderdoc: fix typo #4 +25%,split_filter#0 +24%,uint64_to_stringRepair subtree2 #2 +20%,general_purpose_hashes_on_UUIDRepair subtree2 #1 +19%. A re-run of fourarm_releaseshards gave +0.90% over 2,695 queries; it flaggedgeneral_purpose_hashes_on_UUIDfix docs #6 +25% (farmHash64again).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127995]