Repository navigation
Use v0 symbol mangling for Rust libraries - #98446
Merged
Merged
Conversation
The `chumsky` parser combinator library (used by `prqlc`) creates deeply nested generic types. With Rust's legacy symbol mangling, these produce extremely long symbol names — the longest was 165 KB for a single symbol. 25 symbols exceeded 10 KB, and total symbol name bytes in the PRQL static library were 6 MB across 67K symbols. Rust v0 mangling uses backreference compression for repeated type paths. Since the giant symbols consist almost entirely of repeated `chumsky::*` type paths (e.g. `chumsky::input::MappedSpan` appeared 412 times in the worst case), v0 mangling reduces the longest symbol from 165 KB to 2.3 KB — a 72x reduction. All symbols over 10 KB are eliminated. This is motivated by https://clickhouse.com/blog/rust Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
After cargo builds the PRQL library, run a post-build step that: 1. Extracts .o files from the .a archive 2. Partial-links them into a single .o (resolving all internal references) 3. Localizes all symbols except `prql_to_sql` and `prql_free_pointer` 4. Strips symbols not needed for relocations 5. Repackages as .a This reduces the library from 69 MB to 51 MB and leaves only 2 visible global symbols. The ~67K internal symbols (including deeply nested chumsky parser combinator types) are eliminated from the symbol table. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The tidy build uses a dummy `CMAKE_AR` script that doesn't actually extract archive members. Skip the strip step when `CMAKE_AR` matches `dummy_compiler_linker`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sanitizer instrumentation (ASan, TSan, MSan) adds special symbols like `___asan_globals_registered` that are referenced by relocations in the instrumented code. The partial link + strip process breaks these symbols, causing linker errors like: ld.lld: error: relocation R_X86_64_PC32 cannot refer to absolute symbol: ___asan_globals_registered Skip the stripping step entirely when SANITIZE is set, since sanitizer builds are for development/testing and don't need this optimization. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The Darwin builds failed because the strip script used `CMAKE_LINKER` (`/usr/bin/ld` — GNU ld) which cannot handle Mach-O object files. The same issue could affect other cross-compilation targets (ppc64le, riscv64, s390x, loongarch64) where the host `ld` doesn't support the target ELF architecture. Two fixes: - Skip stripping on Darwin where objects are Mach-O (`ld.lld -r` only handles ELF) - Use `ld.lld` explicitly instead of `CMAKE_LINKER` — it's a cross-linker that handles all ELF architectures regardless of host Co-Authored-By: Claude Opus 4.6 <[email protected]>
`ld.lld -r` partial linking produces broken `.eh_frame` relocations on ppc64le, causing linker errors like "relocation is not in any piece" during the final link. https://s3.amazonaws.com/clickhouse-test-reports/PRs/98446/f5e77a7baf79573b248cb58abf6d1e6363ebb21e/build_ppc64le/build_clickhouse/build_clickhouse.log Co-Authored-By: Claude Opus 4.6 <[email protected]>
Algunenano
approved these changes
Mar 3, 2026
| # The legacy mangling produces extremely long symbols (up to 165 KB) from deeply nested | ||
| # generic types in parser combinator libraries like chumsky (used by prqlc). | ||
| # v0 mangling uses backreference compression for repeated type paths. | ||
| list(APPEND RUSTFLAGS "-C" "symbol-mangling-version=v0") |
Member
There was a problem hiding this comment.
Related: https://blog.rust-lang.org/2025/11/20/switching-to-v0-mangling-on-nightly/ which would be covered by #98602. But let's do it anyway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes to reduce Rust symbol bloat in the ClickHouse binary, particularly from the PRQL library:
v0 symbol mangling (
-C symbol-mangling-version=v0in RUSTFLAGS): Uses Rust's newer mangling scheme with backreference compression for repeated type paths. Reduces the longest symbol from 165 KB to 2.3 KB (72x reduction) and eliminates all symbols over 10 KB.Post-build symbol stripping for PRQL: After cargo builds the PRQL static library, a post-build step partial-links all
.ofiles into one, localizes all symbols exceptprql_to_sqlandprql_free_pointer, and strips unneeded symbols. This reduces the library from 69 MB to 51 MB and leaves only 2 visible global symbols (down from ~25K).Motivated by https://clickhouse.com/blog/rust
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Use Rust v0 symbol mangling and strip internal symbols from PRQL library to reduce symbol name bloat from parser combinator libraries.
🤖 Generated with Claude Code
Version info
26.3.1.332