]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/reachable.rs
Only retain external static symbols across LTO
[rust.git] / src / librustc / middle / reachable.rs
index 6dd447e3b6860c68ec4e567b68406c80c423ab56..5486172b830d2b44a360051e65915a5110215e1b 100644 (file)
@@ -25,7 +25,7 @@
 use util::nodemap::NodeSet;
 
 use std::collections::HashSet;
-use syntax::abi;
+use syntax::abi::Abi;
 use syntax::ast;
 use syntax::attr;
 use rustc_front::hir;
@@ -229,16 +229,16 @@ fn propagate(&mut self) {
     fn propagate_node(&mut self, node: &ast_map::Node,
                       search_item: ast::NodeId) {
         if !self.any_library {
-            // If we are building an executable, then there's no need to flag
-            // anything as external except for `extern fn` types. These
-            // functions may still participate in some form of native interface,
-            // but all other rust-only interfaces can be private (they will not
-            // participate in linkage after this product is produced)
+            // If we are building an executable, only explicitly extern
+            // types need to be exported.
             if let ast_map::NodeItem(item) = *node {
-                if let hir::ItemFn(_, _, _, abi, _, _) = item.node {
-                    if abi != abi::Rust {
-                        self.reachable_symbols.insert(search_item);
-                    }
+                let reachable = if let hir::ItemFn(_, _, _, abi, _, _) = item.node {
+                    abi != Abi::Rust
+                } else {
+                    false
+                };
+                if reachable || attr::contains_extern_indicator(&item.attrs) {
+                    self.reachable_symbols.insert(search_item);
                 }
             }
         } else {