Skip to content

Commit e3bf634

Browse files
committed
Auto merge of #51687 - japaric:gh51671, r=alexcrichton
translate / export weak lang items see #51671 for details fixes #51671 fixes #51342 r? @michaelwoerister or @alexcrichton
2 parents 5d95db3 + cce7007 commit e3bf634

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-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,28 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "bin"]
12+
#![feature(lang_items)]
13+
#![feature(panic_implementation)]
14+
#![no_main]
15+
#![no_std]
16+
17+
use core::panic::PanicInfo;
18+
19+
#[panic_implementation]
20+
fn panic(_: &PanicInfo) -> ! {
21+
loop {}
22+
}
23+
24+
#[lang = "eh_personality"]
25+
fn eh() {}
26+
27+
#[lang = "oom"]
28+
fn oom() {}

0 commit comments

Comments
 (0)