Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Allow #[no_mangle] anywhere in a crate #54451

Merged
merged 1 commit into from
Oct 7, 2018

Commits on Oct 6, 2018

  1. rustc: Allow #[no_mangle] anywhere in a crate

    This commit updates the compiler to allow the `#[no_mangle]` (and
    `#[export_name]` attributes) to be located anywhere within a crate.
    These attributes are unconditionally processed, causing the compiler to
    always generate an exported symbol with the appropriate name.
    
    After some discussion on rust-lang#54135 it was found that not a great reason
    this hasn't been allowed already, and it seems to match the behavior
    that many expect! Previously the compiler would only export a
    `#[no_mangle]` symbol if it were *publicly reachable*, meaning that it
    itself is `pub` and it's otherwise publicly reachable from the root of
    the crate. This new definition is that `#[no_mangle]` *is always
    reachable*, no matter where it is in a crate or whether it has `pub` or
    not.
    
    This should make it much easier to declare an exported symbol with a
    known and unique name, even when it's an internal implementation detail
    of the crate itself. Note that these symbols will persist beyond LTO as
    well, always making their way to the linker.
    
    Along the way this commit removes the `private_no_mangle_functions` lint
    (also for statics) as there's no longer any need to lint these
    situations. Furthermore a good number of tests were updated now that
    symbol visibility has been changed.
    
    Closes rust-lang#54135
    alexcrichton committed Oct 6, 2018
    Configuration menu
    Copy the full SHA
    d7d7045 View commit details
    Browse the repository at this point in the history