From 6cae0805166002c2a70007b11528d3ccec434633 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 10 Oct 2017 15:54:49 -0700 Subject: [PATCH] rustc: Handle `#[linkage]` anywhere in a crate This commit updates the reachability pass of the compiler to seed the local worklist with `#[linkage]`-like items anywhere in a crate, not just those reachable from public items. Closes #45165 --- src/librustc/middle/reachable.rs | 6 +++ src/test/run-pass/smallest-hello-world.rs | 41 ------------------- .../run-pass/thin-lto-global-allocator.rs | 19 +++++++++ 3 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 src/test/run-pass/smallest-hello-world.rs create mode 100644 src/test/run-pass/thin-lto-global-allocator.rs diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 55d0c6b4c66..bb6213cb5fa 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -336,6 +336,12 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { + // Anything which has custom linkage gets thrown on the worklist no + // matter where it is in the crate. + if attr::contains_name(&item.attrs, "linkage") { + self.worklist.push(item.id); + } + // We need only trait impls here, not inherent impls, and only non-exported ones if let hir::ItemImpl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node { if !self.access_levels.is_reachable(item.id) { diff --git a/src/test/run-pass/smallest-hello-world.rs b/src/test/run-pass/smallest-hello-world.rs deleted file mode 100644 index bcbd3fd3786..00000000000 --- a/src/test/run-pass/smallest-hello-world.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Smallest "hello world" with a libc runtime - -// ignore-windows -// ignore-android - -#![feature(intrinsics, lang_items, start, no_core, alloc_system)] -#![feature(global_allocator, allocator_api)] -#![no_std] - -extern crate alloc_system; - -use alloc_system::System; - -#[global_allocator] -static A: System = System; - -extern { - fn puts(s: *const u8); -} - -#[no_mangle] -#[lang = "eh_personality"] pub extern fn rust_eh_personality() {} -#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } - -#[start] -fn main(_: isize, _: *const *const u8) -> isize { - unsafe { - puts("Hello!\0".as_ptr() as *const u8); - } - return 0 -} diff --git a/src/test/run-pass/thin-lto-global-allocator.rs b/src/test/run-pass/thin-lto-global-allocator.rs new file mode 100644 index 00000000000..1c15da5469e --- /dev/null +++ b/src/test/run-pass/thin-lto-global-allocator.rs @@ -0,0 +1,19 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z thinlto -C codegen-units=2 +// min-llvm-version 4.0 + +#![feature(allocator_api, global_allocator)] + +#[global_allocator] +static A: std::heap::System = std::heap::System; + +fn main() {}