about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-10-13 23:37:58 +0800
committerGitHub <noreply@github.com>2017-10-13 23:37:58 +0800
commita481d7ced35ff6cb6ab5972a8dbaafe00e321aea (patch)
treeac798ed3467faca9c247f0dc2959451861c0e265 /src
parente6a6d980e086d88d7b87163a16834ceb72a1f9de (diff)
parent6cae0805166002c2a70007b11528d3ccec434633 (diff)
downloadrust-a481d7ced35ff6cb6ab5972a8dbaafe00e321aea.tar.gz
rust-a481d7ced35ff6cb6ab5972a8dbaafe00e321aea.zip
Rollup merge of #45189 - alexcrichton:thinlto-allocators, r=michaelwoerister
rustc: Handle `#[no_mangle]` anywhere in a crate

This commit updates the reachability pass of the compiler to seed the local
worklist with `#[no_mangle]`-like items anywhere in a crate, not just those
reachable from public items.

Closes #45165
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/reachable.rs6
-rw-r--r--src/test/run-pass/smallest-hello-world.rs41
-rw-r--r--src/test/run-pass/thin-lto-global-allocator.rs19
3 files changed, 25 insertions, 41 deletions
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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}