Skip to content

Commit 3f89594

Browse files
alexcrichtonischeinkman
authored andcommitted
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
1 parent 62c86a4 commit 3f89594

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libstd/panicking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! {
536536
rust_panic(&mut RewrapBox(msg))
537537
}
538538

539-
/// A private no-mangle function on which to slap yer breakpoints.
539+
/// An unmangled function (through `rustc_std_internal_symbol`) on which to slap
540+
/// yer breakpoints.
540541
#[inline(never)]
541-
#[no_mangle]
542-
#[allow(private_no_mangle_fns)] // yes we get it, but we like breakpoints
543-
pub fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
542+
#[cfg_attr(not(test), rustc_std_internal_symbol)]
543+
fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
544544
let code = unsafe {
545545
let obj = &mut msg as *mut &mut dyn BoxMeUp;
546546
__rust_start_panic(obj as usize)

0 commit comments

Comments
 (0)