Skip to content

Fix llvm objcopy location for rust symbol mangling - #101081

Closed
arsenmuk wants to merge 1 commit into
masterfrom
arsenmuk/fix-rust-symbol-mangling
Closed

arsenmuk wants to merge 1 commit into
masterfrom
arsenmuk/fix-rust-symbol-mangling

Conversation

@arsenmuk

@arsenmuk arsenmuk commented Mar 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

With introduction of symbol stripping for Rust libraries in #98446, the llvm-objcopy is not always discoverable

Original error:

[build] ld.lld-21: error: relocation refers to a symbol in a discarded section: DW.ref.rust_eh_personality
[build] >>> defined in rust/workspace/lib_ch_rust_prql.a(stripped.o)
[build] >>> referenced by stripped.o:(.eh_frame+0x18bbbbb) in archive rust/workspace/lib_ch_rust_prql.a
[build] 
[build] ld.lld-21: error: relocation refers to a symbol in a discarded section: DW.ref.rust_eh_personality
[build] >>> defined in rust/workspace/lib_ch_rust_polyglot.a(stripped.o)
[build] >>> referenced by stripped.o:(.eh_frame+0x1963e5b) in archive rust/workspace/lib_ch_rust_polyglot.a
[build] clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@clickhouse-gh

clickhouse-gh Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [de4dae0]

Summary: ✅


AI Review

Summary

This PR updates Rust symbol-stripping integration to resolve llvm-objcopy explicitly (via find_program) instead of relying on CMAKE_OBJCOPY, and only enables stripping when both ld.lld and llvm-objcopy are available. The change is small, targeted, and reduces toolchain mismatch risk on mixed compiler setups. I did not find correctness, safety, performance, or compliance issues in the patch.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 29, 2026
@arsenmuk
arsenmuk marked this pull request as ready for review March 29, 2026 15:59
@azat azat self-assigned this Mar 29, 2026

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, objcopy from binutils cannot handle rust mangling? Does it leads to an error?

@arsenmuk

Copy link
Copy Markdown
Member Author

So, objcopy from binutils cannot handle rust mangling? Does it leads to an error?

In my case it exploded at processing DW.ref.rust_eh_personality. I haven't used RelWithDebInfo much before, plus Rust mangling was enabled quite recently, so perhaps this is why we didn't see that failed elsewhere.

There are some differences between gnu and llvm objcopy. Specifically dropping of GRP_COMDAT flag when a symbol becomes local. If I understand it correctly, it is bug/feature-request which was implemented for LLVM, but still pending for GNU.
Here it's covered briefly - https://maskray.me/blog/2021-07-25-comdat-and-section-group
LLVM - https://reviews.llvm.org/D106782
GNU - https://sourceware.org/bugzilla/show_bug.cgi?id=27931

@azat

azat commented Mar 31, 2026

Copy link
Copy Markdown
Member

Thanks for the details!

If I understand it correctly, it is bug/feature-request which was implemented for LLVM, but still pending for GNU.

I see, so the reason is the difference between binutils and llvm - https://pastila.nl/?01433e71/cec99653abb956222c2d37169d3f1cd0#SqT2bGq7XeNHXCZmmaEJ6g==GCM

Comment on lines +47 to 55
find_program(_LLVM_OBJCOPY_FOR_STRIP NAMES "llvm-objcopy-${COMPILER_VERSION_MAJOR}" "llvm-objcopy")
if (_LLD_FOR_STRIP AND _LLVM_OBJCOPY_FOR_STRIP)
set(_prql_lib "${CMAKE_CURRENT_BINARY_DIR}/lib_ch_rust_prql.a")
add_custom_target(strip_prql_symbols
COMMAND bash "${ClickHouse_SOURCE_DIR}/cmake/strip_rust_symbols.sh"
"${_prql_lib}" "${CMAKE_AR}" "${CMAKE_OBJCOPY}" "${_LLD_FOR_STRIP}"
"${_prql_lib}" "${CMAKE_AR}" "${_LLVM_OBJCOPY_FOR_STRIP}" "${_LLD_FOR_STRIP}"
prql_to_sql prql_free_pointer
DEPENDS cargo-build__ch_rust_prql
COMMENT "Stripping internal symbols from PRQL library"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of copy-paste for prql and polyglot, can you unify this? (can be done separately)

@arsenmuk
arsenmuk marked this pull request as draft April 1, 2026 06:09
@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Dear @arsenmuk, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants