-Zdefault-hidden-visibility
causes linking errors due to intrinsic-related calls #123427
Open
Description
opened on Apr 3, 2024
-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 #118417; MCP rust-lang/compiler-team#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.
Activity