Skip to content

Commit 5d53fd7

Browse files
committed
Stop using C++ exceptions for stack unwinding.
1 parent ba801d8 commit 5d53fd7

File tree

14 files changed

+261
-157
lines changed

14 files changed

+261
-157
lines changed

mk/rt.mk

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ RUNTIME_CXXFLAGS_$(1)_$(2) = -D_RUST_STAGE1
7272
endif
7373
endif
7474

75-
RUNTIME_CXXS_$(1)_$(2) := \
76-
rt/rust_cxx_glue.cpp
77-
7875
RUNTIME_CS_$(1)_$(2) := \
7976
rt/rust_builtin.c \
8077
rt/rust_upcall.c \
8178
rt/miniz.c \
8279
rt/rust_android_dummy.c \
8380
rt/rust_test_helpers.c
8481

82+
RUNTIME_LL_$(1)_$(2) := \
83+
rt/rust_try.ll
84+
8585
# stage0 remove this after the next snapshot
8686
%.cpp:
8787
@touch tmp/foo.o
@@ -94,18 +94,17 @@ RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
9494
RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
9595
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
9696
-I $$(S)src/rt/arch/$$(HOST_$(1))
97-
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
97+
RUNTIME_OBJS_$(1)_$(2) := \
9898
$$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
99-
$$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
99+
$$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
100+
$$(RUNTIME_LL_$(1)_$(2):rt/%.ll=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
101+
100102
ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
101103

102104
MORESTACK_OBJS_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/morestack.o
103105
ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
104106

105-
$$(RT_BUILD_DIR_$(1)_$(2))/rust_cxx_glue.o: rt/rust_cxx_glue.cpp $$(MKFILE_DEPS)
106-
@$$(call E, compile: $$@)
107-
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
108-
$$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
107+
LLVM_LLC = $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin/llc -filetype=obj -o $$1 $$2
109108

110109
$$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.c $$(MKFILE_DEPS)
111110
@$$(call E, compile: $$@)
@@ -117,6 +116,11 @@ $$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.S $$(MKFILE_DEPS) \
117116
@$$(call E, compile: $$@)
118117
$$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
119118

119+
$$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.ll $$(MKFILE_DEPS) \
120+
$$(LLVM_CONFIG_$$(CFG_BUILD))
121+
@$$(call E, compile: $$@)
122+
$$(Q)$$(call LLVM_LLC,$$@,$$<)
123+
120124
$$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJS_$(1)_$(2))
121125
@$$(call E, link: $$@)
122126
$$(Q)$(AR_$(1)) rcs $$@ $$^

src/etc/mklldeps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
for lib in out.strip().split(' '):
6060
lib = lib[2:] # chop of the leading '-l'
6161
f.write("#[link(name = \"" + lib + "\", kind = \"static\")]\n")
62+
63+
# LLVM depends on C++ runtime, so we link it in (statically).
64+
# Because our linker driver is gcc, not g++, it won't understand the -static-libstdc++ option,
65+
# so we need to pass "-Bstatic -lstdc++ -Bdynamic" directly to ld.
66+
f.write("#[link_args = \"-Xlinker -Bstatic -Xlinker -lstdc++ -Xlinker -Bdynamic\"]\n")
67+
6268
if os == 'win32':
6369
f.write("#[link(name = \"imagehlp\")]\n")
70+
6471
f.write("extern {}\n")

src/librustc/back/link.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
702702
// In the future, FreeBSD will use clang as default compiler.
703703
// It would be flexible to use cc (system's default C compiler)
704704
// instead of hard-coded gcc.
705-
// For win32, there is no cc command, so we add a condition to make it use
706-
// g++. We use g++ rather than gcc because it automatically adds linker
707-
// options required for generation of dll modules that correctly register
708-
// stack unwind tables.
705+
// For win32, there is no cc command, so we add a condition to make it use gcc.
709706
match sess.targ_cfg.os {
710707
abi::OsAndroid => match sess.opts.android_cross_path {
711708
Some(ref path) => format!("{}/bin/arm-linux-androideabi-gcc", *path),
@@ -714,7 +711,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
714711
(--android-cross-path)")
715712
}
716713
},
717-
abi::OsWin32 => ~"g++",
714+
abi::OsWin32 => ~"gcc",
718715
_ => ~"cc",
719716
}
720717
}
@@ -1023,6 +1020,12 @@ fn link_args(sess: Session,
10231020
}
10241021
}
10251022

1023+
if sess.targ_cfg.os == abi::OsWin32 {
1024+
// Make sure that we link to the dynamic libgcc, otherwise cross-module
1025+
// DWARF stack unwinding will not work.
1026+
args.push(~"-shared-libgcc");
1027+
}
1028+
10261029
add_local_native_libraries(&mut args, sess);
10271030
add_upstream_rust_crates(&mut args, sess, dylib, tmpdir);
10281031
add_upstream_native_libraries(&mut args, sess);

src/librustc/back/upcall.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/librustc/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#[crate_type = "dylib"];
1717
#[crate_type = "rlib"];
1818

19-
#[feature(macro_rules, globs, struct_variant, managed_boxes)];
19+
#[feature(macro_rules, globs, struct_variant, managed_boxes, link_args)];
2020

2121
extern mod extra;
2222
extern mod syntax;
@@ -92,7 +92,6 @@ pub mod back {
9292
pub mod link;
9393
pub mod manifest;
9494
pub mod abi;
95-
pub mod upcall;
9695
pub mod arm;
9796
pub mod mips;
9897
pub mod x86;

src/librustc/lib/llvm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ pub mod llvm {
319319
// automatically updated whenever LLVM is updated to include an up-to-date
320320
// set of the libraries we need to link to LLVM for.
321321
#[link(name = "rustllvm", kind = "static")]
322-
#[link(name = "stdc++")]
323322
extern {
324323
/* Create and destroy contexts. */
325324
pub fn LLVMContextCreate() -> ContextRef;

src/librustc/middle/lang_items.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn collect_language_items(crate: &ast::Crate,
208208
}
209209

210210
lets_do_this! {
211-
There are 42 lang items.
211+
There are 43 lang items.
212212

213213
// ID, Variant name, Name, Method name;
214214
0, FreezeTraitLangItem, "freeze", freeze_trait;
@@ -261,5 +261,7 @@ lets_do_this! {
261261
40, EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory;
262262

263263
41, TypeIdLangItem, "type_id", type_id;
264+
265+
42, EhPersonalityLangItem, "eh_personality", eh_personality_fn;
264266
}
265267

src/librustc/middle/trans/base.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use metadata::{csearch, cstore, encoder};
3737
use middle::astencode;
3838
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
3939
use middle::lang_items::{MallocFnLangItem, ClosureExchangeMallocFnLangItem};
40+
use middle::lang_items::{EhPersonalityLangItem};
4041
use middle::trans::_match;
4142
use middle::trans::adt;
4243
use middle::trans::base;
@@ -1028,10 +1029,10 @@ pub fn get_landing_pad(bcx: @mut Block) -> BasicBlockRef {
10281029
// this represents but it's determined by the personality function and
10291030
// this is what the EH proposal example uses.
10301031
let llretty = Type::struct_([Type::i8p(), Type::i32()], false);
1031-
// The exception handling personality function. This is the C++
1032-
// personality function __gxx_personality_v0, wrapped in our naming
1033-
// convention.
1034-
let personality = bcx.ccx().upcalls.rust_personality;
1032+
// The exception handling personality function.
1033+
let personality = callee::trans_fn_ref(bcx,
1034+
langcall(bcx, None, "", EhPersonalityLangItem),
1035+
0).llfn;
10351036
// The only landing pad clause will be 'cleanup'
10361037
let llretval = LandingPad(pad_bcx, llretty, personality, 1u);
10371038
// The landing pad block is a cleanup
@@ -3197,6 +3198,7 @@ pub fn trans_crate(sess: session::Session,
31973198
reachable.push(ccx.crate_map_name.to_owned());
31983199
reachable.push(~"main");
31993200
reachable.push(~"rust_stack_exhausted");
3201+
reachable.push(~"eh_rust_personality_catch"); // referenced from rt/rust_try.ll
32003202

32013203
return CrateTranslation {
32023204
context: llcx,

src/librustc/middle/trans/context.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111

12-
use back::{upcall};
1312
use driver::session;
1413
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
1514
use lib::llvm::{llvm, TargetData, TypeNames};
@@ -105,7 +104,6 @@ pub struct CrateContext {
105104
tcx: ty::ctxt,
106105
maps: astencode::Maps,
107106
stats: @mut Stats,
108-
upcalls: @upcall::Upcalls,
109107
tydesc_type: Type,
110108
int_type: Type,
111109
opaque_vec_type: Type,
@@ -233,7 +231,6 @@ impl CrateContext {
233231
llvm_insns: HashMap::new(),
234232
fn_stats: ~[]
235233
},
236-
upcalls: upcall::declare_upcalls(targ_cfg, llmod),
237234
tydesc_type: tydesc_type,
238235
int_type: int_type,
239236
opaque_vec_type: opaque_vec_type,

src/libstd/rt/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ mod local_ptr;
173173
/// Bindings to pthread/windows thread-local storage.
174174
mod thread_local_storage;
175175

176+
/// Stack unwinding
177+
pub mod unwind;
178+
176179
/// Just stuff
177180
mod util;
178181

0 commit comments

Comments
 (0)