`-Zdefault-hidden-visibility` causes linking errors due to intrinsic-related calls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
-Zdefault-hidden-visibility should affect symbols defined in a crate. References to externally-defined symbols should not have hidden visibility.
Certain intrinsics such as compare_bytes may emit calls to libc.so functions (e.g. memcmp). When -Zdefault-hidden-visibility is used, these symbol references are hidden. This leads to linking errors since an undefined hidden symbol cannot be resolved to a symbol in a dynamic library.
Repro:
#![feature(core_intrinsics)]
fn main() {
let a = 0u8;
let b = 0u8;
println!("{}", unsafe {
std::intrinsics::compare_bytes(&a as *const _, &b as *const _, 1)
});
}
error:
note: /usr/bin/ld: .../rust/build/x86_64-unknown-linux-gnu/test/ui/default-hidden-visibility-intrinsic/default-hidden-visibility-intrinsic.default_hidden_visibility_intrinsic.adfc02789a1ff675-cgu.0.rcgu.o: in function `default_hidden_visibility_intrinsic::main':
default_hidden_visibility_intrinsic.adfc02789a1ff675-cgu.0:(.text._ZN35default_hidden_visibility_intrinsic4main17hf16163bc798359ebE+0x1e): undefined reference to `memcmp'
/usr/bin/ld: .../rust/build/x86_64-unknown-linux-gnu/test/ui/default-hidden-visibility-intrinsic/default-hidden-visibility-intrinsic: hidden symbol `memcmp' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
The flag was added in https://github.com/rust-lang/rust/pull/118417; MCP https://github.com/rust-lang/compiler-team/issues/656
While this flag isn't really intended for use on bin crates, I suspect crates downstream of an rlib or staticlib would have the same errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided compare_bytes reproduction and the regression-test path test/ui/default-hidden-visibility-intrinsic/default-hidden-visibility-intrinsic. Trace how -Zdefault-hidden-visibility is applied to intrinsic-emitted references such as memcmp. Done means externally defined symbols retain resolvable visibility and the reproduction links successfully with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100