Repository navigation
Link with --icf=safe: --icf=all merges address-taken functions and crashes gRPC compression - #122668
Conversation
`-Wl,--icf=all` (ClickHouse#99474) lets lld fold byte-identical functions even when their address is taken, which breaks the guarantee that different functions have different addresses. In ThinLTO builds `gpr_free` is inlined into gRPC's zlib free callback `zfree_gpr`, which becomes `mov %rsi,%rdi; jmp free`, byte-identical to zlib-ng's default `zcfree`, so both get one address. Measured with llvm-nm: the official 26.8.10.6 image and a local ThinLTO build of master fold them (12 functions share that address locally); 26.3.33.24 and the no-LTO amd_binary do not. zlib-ng 2.1.7 (`zutil.c`) chooses the buffer layout by comparing the stream's callbacks with its defaults. `alloc_aligned` sees `zalloc_gpr != zcalloc`, allocates 8 + n + 64 bytes and returns the 64-byte aligned pointer with the original one stored below it. `free_aligned` sees `zfree_gpr == zcfree` and frees the aligned pointer itself. jemalloc places a large allocation at a random cache line of the extent's first page (JEMALLOC_CACHE_OBLIVIOUS); when it is the last line (1 in 64), the freed pointer is the extent's second page, which the emap does not register, and `ifree` -> `prof_free` reads `e_prof_tctx` from a NULL `edata_t`: `Address: 0x50`, as in the CI crashes. Otherwise an interior pointer is freed. Every gRPC call with transport compression goes through this path: `deflateEnd` for the result and `inflateEnd` for a compressed request. In CI only the WeeklyCFI integration jobs showed it, because amd_cfi is the only integration build with ThinLTO. In safe mode lld does not fold functions whose address is significant according to the `-faddrsig` tables the build already emits. Virtual methods, constructors and destructors (`unnamed_addr`) and functions whose address is never taken are still folded; objects without an address-significance table (Rust) are not folded. Measured on a local ThinLTO build of master (clang-22, lld-22, -g0): - `zfree_gpr` and `zcfree`: one address before, two after. - `lea F; cmp` sites where F is shared by different functions: 87 before (20 are zlib-ng's `zfree == zcfree` test inlined into rdkafka, rocksdb, arrow, orc, libarchive, minizip, gRPC and zlib-ng itself), 3 after: the source alias `AES_encrypt`/`asm_AES_encrypt`, and twice a destructor passed to `__cxa_throw`, none an identity test. - gRPC loop with gzip/deflate transport compression: before, the server crashed in 3/3 runs within 6 queries (the official 26.8.10.6 image in 7/7 within 22, 26.3.33.24 ran 2000/2000), the request side alone in 4/4, and 1 KB requests also gave a crash at a wild address in `grpc_core::Arena::~Arena()` and a spurious decompression error. After: 34000 queries without a failure. - Size: `.text` +2.21 MiB (+0.46%), stripped binary +2.97 MiB (+0.45%), zstd -3 of the stripped binary +0.55 MiB (+0.28%). Folded code: 52.0 MiB before, 50.6 MiB after. The new test sends compressed gRPC requests and results. It fails on the ThinLTO build without this change and guards the MasterCI release stateless jobs; PR CI has no ThinLTO build. An alternative with no size cost is to drop the identity shortcuts from our zlib-ng fork (upstream 2.2.0 no longer has `alloc_aligned` / `free_aligned`, zlib-ng#1713), but that leaves the other comparison sites. Closes ClickHouse#115121. 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 findings), plus one nit from my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260928-094400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260928-073300 |
|
Workflow [PR], commit [bcc3e17] Summary: ✅
AI ReviewSummaryThis PR switches Linux PR Metadata
Findings💡 Nits
Final Verdict✅ Code change looks sound. Please reclassify the changelog category to LLVM Coverage ReportMeasured on commit bcc3e17.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +223 lines in 85 files (-116 lines lost coverage) · Details |
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 Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
Backport #122668 to 26.9: Link with `--icf=safe`: `--icf=all` merges address-taken functions and crashes gRPC compression
…address-taken functions and crashes gRPC compression
Backport #122668 to 26.8: Link with `--icf=safe`: `--icf=all` merges address-taken functions and crashes gRPC compression
Backport #122668 to 26.7: Link with `--icf=safe`: `--icf=all` merges address-taken functions and crashes gRPC compression
|
Haha, this is PR also fixes attach with |
…l` merges address-taken functions and crashes gRPC compression
…l` merges address-taken functions and crashes gRPC compression
Closes: #115121
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Link with
--icf=safeinstead of--icf=all, so the linker keeps functions whose address is taken distinct. gRPC queries with transport compression (gzip,deflate) no longer crash the server, as they could in official builds since 26.4. Closes #115121.Description
Since 26.4, official builds crash on gRPC queries with transport compression (
SIGSEGV,Address: 0x50, infreefrom zlib-ngdeflateEnd/inflateEnd). Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36373749054/job/108786682420Cause.
-Wl,--icf=all(#99474) folds identical functions even when their address is taken: for code, lld ignores the-faddrsigtables the build emits. With ThinLTO, gRPC's zlib free callbackzfree_gpris byte-identical to zlib-ng's defaultzcfree, so both get one address. zlib-ng 2.1.7 picks the buffer layout by comparing callbacks with its defaults:alloc_alignedsees a customzallocand returns a 64-byte aligned pointer, with the original stored below it;free_alignedseeszfree == zcfreeand frees the aligned pointer. When it is the second page of a large jemalloc extent (1 in 64 per buffer), the free crashes; otherwise an interior pointer is freed. CI saw it only in WeeklyCFI, the only integration build with ThinLTO.Change. With
--icf=safe, lld keeps functions whose address is significant distinct. Virtual methods, constructors, destructors and functions whose address is never taken still fold.Validation.
--icf=all) ran 2000/2000..text+2.21 MiB (+0.46%), stripped +2.97 MiB (+0.45%), zstd +0.55 MiB (+0.28%).05291_grpc_transport_compressionfails on the local LTO build before, passes after. PR CI runs no stateless job on an LTO build; it guards the MasterCIamd_release/arm_releasestateless jobs.Alternative with no size cost: drop the identity shortcuts in the zlib-ng fork (gone upstream since 2.2.0, zlib-ng#1713); it leaves the other comparison sites.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122668]
Version info
26.10.1.942-master(included in26.10and later)26.9.6.3,26.8.15.4,26.7.17.6