about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-09-21 15:58:11 -0700
committerAlex Crichton <alex@alexcrichton.com>2018-10-06 13:57:30 -0700
commitd7d704537457c613e667e9f0cd9fda32600bfb36 (patch)
tree3878e217065631ab341092e69afa89d7642a768f /src/libstd
parentde3d640f59c4fa4a09faf2a8d6b0a812aaa6d6cb (diff)
downloadrust-d7d704537457c613e667e9f0cd9fda32600bfb36.tar.gz
rust-d7d704537457c613e667e9f0cd9fda32600bfb36.zip
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 #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 #54135
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/panicking.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index df085a7f450..a0590a800d3 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -515,11 +515,11 @@ pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! {
     rust_panic(&mut RewrapBox(msg))
 }
 
-/// A private no-mangle function on which to slap yer breakpoints.
+/// An unmangled function (through `rustc_std_internal_symbol`) on which to slap
+/// yer breakpoints.
 #[inline(never)]
-#[no_mangle]
-#[allow(private_no_mangle_fns)] // yes we get it, but we like breakpoints
-pub fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
+#[cfg_attr(not(test), rustc_std_internal_symbol)]
+fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
     let code = unsafe {
         let obj = &mut msg as *mut &mut dyn BoxMeUp;
         __rust_start_panic(obj as usize)