Fix zig cc/c++ mishandling of -u (undefined symbol) linker flag #242
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.
Closes #243
The
-u SYMBOLflag tells the linker to treat SYMBOL as undefined, forcing it to be resolved from archives or shared libraries. This is a standard linker feature used to:Currently, Zig's cc/c++ driver misinterprets
-u SYMBOL- it attempts to open SYMBOL as a filename rather than passing it to the linker. This breaks any toolchain or build system that relies on this flag.This is a known Zig bug tracked at:
https://codeberg.org/ziglang/zig/issues/30613
The fix (https://codeberg.org/ziglang/zig/pulls/30749) is pending merge. I'll post on the issue and merge request at Zig just to +1 the need for a fix - and I'm not sure whether you want to integrate a work around here in
hermetic_cc_toolchainor not vs waiting for an upstream fix.This patch works around the issue by transforming
-u SYMBOLinto-Wl,-u,SYMBOL, which explicitly passes the flag through to the linker.Discovered while debugging
bazel coveragefailures in a mixed C++/Rust repository (minimal reproduction at https://github.com/electronjoe/bazel-cpp-rust-codecov). This repo useshermetic_cc_compilerandrules_rust-> rustc passes-u __llvm_profile_runtimefor coverage instrumentation. If you would like to reproduce the original issue, you can open a codespace from the repo,bazel coverage //..., observe success - then roll back this patch in the repo and try again to observe the failure mode.