Skip to content

Commit 9ef134d

Browse files
committed
translate / export weak lang items
see rust-lang#51671 for details fixes rust-lang#51671 fixes rust-lang#51342
1 parent 01172a7 commit 9ef134d

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

src/librustc/middle/weak_lang_items.rs

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_target::spec::PanicStrategy;
1717
use syntax::ast;
1818
use syntax::symbol::Symbol;
1919
use syntax_pos::Span;
20+
use hir::def_id::DefId;
2021
use hir::intravisit::{Visitor, NestedVisitorMap};
2122
use hir::intravisit;
2223
use hir;
@@ -145,6 +146,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
145146
}
146147
}
147148

149+
impl<'a, 'tcx, 'gcx> TyCtxt<'a, 'tcx, 'gcx> {
150+
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
151+
let lang_items = self.lang_items();
152+
let did = Some(item_def_id);
153+
154+
$(lang_items.$name() == did)||+
155+
}
156+
}
157+
148158
) }
149159

150160
weak_lang_items! {

src/librustc_mir/monomorphize/collector.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
10311031
MonoItemCollectionMode::Lazy => {
10321032
self.entry_fn == Some(def_id) ||
10331033
self.tcx.is_reachable_non_generic(def_id) ||
1034+
self.tcx.is_weak_lang_item(def_id) ||
10341035
self.tcx.codegen_fn_attrs(def_id).flags.contains(
10351036
CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
10361037
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-include ../tools.mk
2+
3+
ifdef IS_WINDOWS
4+
# Do nothing on MSVC.
5+
all:
6+
exit 0
7+
else
8+
all:
9+
$(RUSTC) --emit=obj app.rs
10+
nm $(TMPDIR)/app.o | $(CGREP) rust_begin_unwind
11+
nm $(TMPDIR)/app.o | $(CGREP) rust_eh_personality
12+
nm $(TMPDIR)/app.o | $(CGREP) rust_oom
13+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_type = "bin"]
2+
#![feature(lang_items)]
3+
#![feature(panic_implementation)]
4+
#![no_main]
5+
#![no_std]
6+
7+
use core::panic::PanicInfo;
8+
9+
#[panic_implementation]
10+
fn panic(_: &PanicInfo) -> ! {
11+
loop {}
12+
}
13+
14+
#[lang = "eh_personality"]
15+
fn eh() {}
16+
17+
#[lang = "oom"]
18+
fn oom() {}

0 commit comments

Comments
 (0)