From 0a2282e1286823c06ee9c4fa5e49544fc4f47771 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 23 Aug 2018 00:33:32 -0700 Subject: rustc: Continue to tweak "std internal symbols" In investigating [an issue][1] with `panic_implementation` defined in an executable that's optimized I once again got to rethinking a bit about the `rustc_std_internal_symbol` attribute as well as weak lang items. We've sort of been non-stop tweaking these items ever since their inception, and this continues to the trend. The crux of the bug was that in the reachability we have a [different branch][2] for non-library builds which meant that weak lang items (and std internal symbols) weren't considered reachable, causing them to get eliminiated by ThinLTO passes. The fix was to basically tweak that branch to consider these symbols to ensure that they're propagated all the way to the linker. Along the way I've attempted to erode the distinction between std internal symbols and weak lang items by having weak lang items automatically configure fields of `CodegenFnAttrs`. That way most code no longer even considers weak lang items and they're simply considered normal functions with attributes about the ABI. In the end this fixes the final comment of #51342 [1]: https://github.com/rust-lang/rust/issues/51342#issuecomment-414368019 [2]: https://github.com/rust-lang/rust/blob/35bf1ae25799a4e62131159f052e0a3cbd27c960/src/librustc/middle/reachable.rs#L225-L238 --- src/libstd/alloc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libstd/alloc.rs') diff --git a/src/libstd/alloc.rs b/src/libstd/alloc.rs index b9aba1e9cab..6753ed4a3df 100644 --- a/src/libstd/alloc.rs +++ b/src/libstd/alloc.rs @@ -150,23 +150,23 @@ pub mod __default_lib_allocator { // linkage directives are provided as part of the current compiler allocator // ABI - #[no_mangle] #[rustc_std_internal_symbol] + #[cfg_attr(stage0, no_mangle)] pub unsafe extern fn __rdl_alloc(size: usize, align: usize) -> *mut u8 { let layout = Layout::from_size_align_unchecked(size, align); System.alloc(layout) } - #[no_mangle] #[rustc_std_internal_symbol] + #[cfg_attr(stage0, no_mangle)] pub unsafe extern fn __rdl_dealloc(ptr: *mut u8, size: usize, align: usize) { System.dealloc(ptr, Layout::from_size_align_unchecked(size, align)) } - #[no_mangle] #[rustc_std_internal_symbol] + #[cfg_attr(stage0, no_mangle)] pub unsafe extern fn __rdl_realloc(ptr: *mut u8, old_size: usize, align: usize, @@ -175,8 +175,8 @@ pub mod __default_lib_allocator { System.realloc(ptr, old_layout, new_size) } - #[no_mangle] #[rustc_std_internal_symbol] + #[cfg_attr(stage0, no_mangle)] pub unsafe extern fn __rdl_alloc_zeroed(size: usize, align: usize) -> *mut u8 { let layout = Layout::from_size_align_unchecked(size, align); System.alloc_zeroed(layout) -- cgit 1.4.1-3-g733a5