]> git.lizzy.rs Git - rust.git/commitdiff
Force all lang items to be reachable
authorAlex Crichton <alex@alexcrichton.com>
Thu, 16 Jan 2014 18:12:31 +0000 (10:12 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 22 Feb 2014 18:29:06 +0000 (10:29 -0800)
This prevents linker errors as found in #11591

Closes #11591

src/librustc/middle/reachable.rs
src/test/auxiliary/lang-item-public.rs [new file with mode: 0644]
src/test/run-pass/lang-item-public.rs [new file with mode: 0644]

index ee948f5453babad20abefd24804bbd2f50ae7f28..547d78219a52137aa07d4e294200d37a134dc784 100644 (file)
@@ -404,11 +404,23 @@ pub fn find_reachable(tcx: ty::ctxt,
     let reachable_context = ReachableContext::new(tcx, method_map);
 
     // Step 1: Seed the worklist with all nodes which were found to be public as
-    //         a result of the privacy pass
+    //         a result of the privacy pass along with all local lang items. If
+    //         other crates link to us, they're going to expect to be able to
+    //         use the lang items, so we need to be sure to mark them as
+    //         exported.
+    let mut worklist = reachable_context.worklist.borrow_mut();
     for &id in exported_items.iter() {
-        let mut worklist = reachable_context.worklist.borrow_mut();
         worklist.get().push(id);
     }
+    for (_, item) in tcx.lang_items.items() {
+        match *item {
+            Some(did) if is_local(did) => {
+                worklist.get().push(did.node);
+            }
+            _ => {}
+        }
+    }
+    drop(worklist);
 
     // Step 2: Mark all symbols that the symbols on the worklist touch.
     reachable_context.propagate();
diff --git a/src/test/auxiliary/lang-item-public.rs b/src/test/auxiliary/lang-item-public.rs
new file mode 100644 (file)
index 0000000..123160f
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 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.
+
+#[no_std];
+
+#[lang="fail_"]
+fn fail(_: *i8, _: *i8, _: uint) -> ! { loop {} }
+
+#[no_mangle]
+pub extern "C" fn rust_stack_exhausted() {}
diff --git a/src/test/run-pass/lang-item-public.rs b/src/test/run-pass/lang-item-public.rs
new file mode 100644 (file)
index 0000000..6256449
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 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.
+
+// aux-build:lang-item-public.rs
+// ignore-fast
+// ignore-android
+
+#[no_std];
+
+extern crate lang_lib = "lang-item-public";
+
+#[cfg(target_os = "linux")]
+#[link(name = "c")]
+extern {}
+
+#[cfg(target_os = "android")]
+#[link(name = "c")]
+extern {}
+
+#[cfg(target_os = "freebsd")]
+#[link(name = "execinfo")]
+extern {}
+
+#[cfg(target_os = "macos")]
+#[link(name = "System")]
+extern {}
+
+#[start]
+fn main(_: int, _: **u8) -> int {
+    1 % 1
+}