Skip to content

-Zdefault-hidden-visibility causes linking errors due to intrinsic-related calls  #123427

Open
@chbaker0

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 #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

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

Metadata

Assignees

No one assigned

    Labels

    A-intrinsicsArea: IntrinsicsA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions