Skip to content

Commit 0487292

Browse files
committed
std: Move pc-windows-gnu to SEH-based unwinding
This commit moves the `*-pc-windows-gnu` targets (e.g. the MinGW targets) to use SEH-based unwinding instead of libunwind-based unwinding. There are a number of ramifications on these targets as a result: * Binary distributions of the standard library are no longer tied to a particular compiler toolchain. The MinGW toolchains typically ship with either SEH, Dwarf, or SjLj based unwinding and are binary-incompatible, but with SEH unwinding we'll be able to link with any of the toolchains. * The GNU implementation is now much closer to the MSVC implementation, reducing the amount of duplicated code we'll have to maintain (yay!). * Due to the loss of the libunwind stack unwinder the libbacktrace library is no longer used on Windows. The same unwinding code for MSVC is now used for GNU as well, and unfortunately this has empirically led to worse stack traces in the past. In theory, though, this should be fixed for both MSVC and GNU at the same time! * Due to the lack of a need for frame unwind info registration, the `rsend.o` and `rsbegin.o` startup object files are no longer built. Additionally the `crt2.o` and `dllcrt2.o` files are no longer distributed. It's assumed that the linker in use will inject these as usual. The `-nostdlib` flag is no longer passed to the linker to indicate this. This change also opened up the possibility to reorganize a few modules, so the following changes were also made: * The `custom_unwind_resume` option and all support code was removed from trans as this is no longer necessary. * The `sys_common::unwind` module was refactored to have the platform-specific portions live in `sys::unwind`. * A similar refactoring was applied to backtrace writing (just shuffling some files around). * Documentation was updated in shuffled modules to reflect the current state of affairs.
1 parent 7fce503 commit 0487292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+238
-987
lines changed

mk/cfg/i686-pc-windows-gnu.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ CFG_LDPATH_i686-pc-windows-gnu :=
2222
CFG_RUN_i686-pc-windows-gnu=$(2)
2323
CFG_RUN_TARG_i686-pc-windows-gnu=$(call CFG_RUN_i686-pc-windows-gnu,,$(2))
2424
CFG_GNU_TRIPLE_i686-pc-windows-gnu := i686-w64-mingw32
25-
CFG_THIRD_PARTY_OBJECTS_i686-pc-windows-gnu := crt2.o dllcrt2.o
26-
CFG_INSTALLED_OBJECTS_i686-pc-windows-gnu := crt2.o dllcrt2.o rsbegin.o rsend.o
27-
CFG_RUSTRT_HAS_STARTUP_OBJS_i686-pc-windows-gnu := 1
25+
CFG_THIRD_PARTY_OBJECTS_i686-pc-windows-gnu :=
26+
CFG_INSTALLED_OBJECTS_i686-pc-windows-gnu :=

mk/cfg/x86_64-pc-windows-gnu.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ CFG_LDPATH_x86_64-pc-windows-gnu :=
2222
CFG_RUN_x86_64-pc-windows-gnu=$(2)
2323
CFG_RUN_TARG_x86_64-pc-windows-gnu=$(call CFG_RUN_x86_64-pc-windows-gnu,,$(2))
2424
CFG_GNU_TRIPLE_x86_64-pc-windows-gnu := x86_64-w64-mingw32
25-
CFG_THIRD_PARTY_OBJECTS_x86_64-pc-windows-gnu := crt2.o dllcrt2.o
26-
CFG_INSTALLED_OBJECTS_x86_64-pc-windows-gnu := crt2.o dllcrt2.o rsbegin.o rsend.o
27-
CFG_RUSTRT_HAS_STARTUP_OBJS_x86_64-pc-windows-gnu := 1
25+
CFG_THIRD_PARTY_OBJECTS_x86_64-pc-windows-gnu :=
26+
CFG_INSTALLED_OBJECTS_x86_64-pc-windows-gnu :=

mk/dist.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ PKG_FILES := \
5858
libcoretest \
5959
libbacktrace \
6060
rt \
61-
rtstartup \
6261
rustllvm \
6362
snapshots.txt \
6463
rust-installer \

mk/rt.mk

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,8 @@ BACKTRACE_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),backtrace)
291291
BACKTRACE_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(BACKTRACE_NAME_$(1))
292292
BACKTRACE_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/libbacktrace
293293

294-
# We don't use this on platforms that aren't linux-based (with the exception of
295-
# msys2/mingw builds on windows, which use it to read the dwarf debug
296-
# information) so just make the file available, the compilation of libstd won't
297-
# actually build it.
294+
# We don't use this on platforms that aren't linux-based so just make the file
295+
# available, the compilation of libstd won't actually build it.
298296
ifeq ($$(findstring darwin,$$(OSTYPE_$(1))),darwin)
299297
# See comment above
300298
$$(BACKTRACE_LIB_$(1)):
@@ -307,7 +305,7 @@ $$(BACKTRACE_LIB_$(1)):
307305
touch $$@
308306
else
309307

310-
ifeq ($$(findstring msvc,$(1)),msvc)
308+
ifeq ($$(findstring windows,$(1)),windows)
311309
# See comment above
312310
$$(BACKTRACE_LIB_$(1)):
313311
touch $$@
@@ -382,10 +380,6 @@ endif # endif for darwin
382380
ifeq ($$(findstring musl,$(1)),musl)
383381
$$(RT_OUTPUT_DIR_$(1))/%: $$(CFG_MUSL_ROOT)/lib/%
384382
cp $$^ $$@
385-
else
386-
# Ask gcc where it is
387-
$$(RT_OUTPUT_DIR_$(1))/%:
388-
cp $$(shell $$(CC_$(1)) -print-file-name=$$(@F)) $$@
389383
endif
390384

391385
endef

mk/target.mk

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,6 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
126126

127127
endef
128128

129-
# Macro for building runtime startup/shutdown object files;
130-
# these are Rust's equivalent of crti.o, crtn.o
131-
#
132-
# $(1) - stage
133-
# $(2) - target triple
134-
# $(3) - host triple
135-
# $(4) - object basename
136-
define TARGET_RUSTRT_STARTUP_OBJ
137-
138-
$$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o: \
139-
$(S)src/rtstartup/$(4).rs \
140-
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.core \
141-
$$(HSREQ$(1)_T_$(2)_H_$(3)) \
142-
| $$(TBIN$(1)_T_$(2)_H_$(3))/
143-
@$$(call E, rustc: $$@)
144-
$$(STAGE$(1)_T_$(2)_H_$(3)) --emit=obj -o $$@ $$<
145-
146-
ifeq ($$(CFG_RUSTRT_HAS_STARTUP_OBJS_$(2)), 1)
147-
# Add dependencies on Rust startup objects to all crates that depend on core.
148-
# This ensures that they are built after core (since they depend on it),
149-
# but before everything else (since they are needed for linking dylib crates).
150-
$$(foreach crate, $$(TARGET_CRATES), \
151-
$$(if $$(findstring core,$$(DEPS_$$(crate))), \
152-
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate))) : $$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o
153-
endif
154-
155-
endef
156-
157129
# Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
158130
# a directory that can be cleaned out during the middle of a run of
159131
# the get-snapshot.py script. Therefore, every recipe needs to have
@@ -166,7 +138,10 @@ SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
166138

167139
define TARGET_HOST_RULES
168140

169-
$$(TLIB$(1)_T_$(2)_H_$(3))/:
141+
$$(TLIB$(1)_T_$(2)_H_$(3))/: | $$(SNAPSHOT_RUSTC_POST_CLEANUP)
142+
mkdir -p $$@
143+
144+
$$(TBIN$(1)_T_$(2)_H_$(3))/: | $$(SNAPSHOT_RUSTC_POST_CLEANUP)
170145
mkdir -p $$@
171146

172147
$$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
@@ -197,8 +172,33 @@ $(foreach host,$(CFG_HOST), \
197172
$(foreach tool,$(TOOLS), \
198173
$(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))
199174

175+
# FIXME(stage0) - remove everything here after a snapshot
176+
#
177+
# The stage0 compiler requires the rsend.o, rsbegin.o, crt2.o, and dllcrt2.o
178+
# startup objects on the pc-windows-gnu targets, but that's no longer the case.
179+
# Hack in support to the makefiles to ensure that these objects all exist.
180+
#
181+
# Note that the rs*.o files can just be blank object files.
182+
define STARTUP_OBJS_COMPAT
183+
ifeq ($$(findstring pc-windows-gnu,$(2)),pc-windows-gnu)
184+
DUMMY_DEPS_$(2)_H_$(3) := \
185+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.core \
186+
$$(HSREQ$(1)_T_$(2)_H_$(3))/stamp.core
187+
$$(TLIB$(1)_T_$(2)_H_$(3))/rsend.o $$(TLIB$(1)_T_$(2)_H_$(3))/rsbegin.o: \
188+
$$(DUMMY_DEPS_$(2)_H_$(3) \
189+
| $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
190+
$$(CC_$(2)) $$(CFG_GCCISH_CFLAGS_$(2)) -c -x c - -o $$@ < /dev/null
191+
$$(TLIB$(1)_T_$(2)_H_$(3))/dllcrt2.o $$(TLIB$(1)_T_$(2)_H_$(3))/crt2.o: \
192+
$$(DUMMY_DEPS_$(2)_H_$(3) \
193+
| $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
194+
cp $$(shell $$(CC_$(2)) -print-file-name=$$(@F)) $$@
195+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.std: \
196+
$$(TLIB$(1)_T_$(2)_H_$(3))/rsend.o \
197+
$$(TLIB$(1)_T_$(2)_H_$(3))/rsbegin.o \
198+
$$(TLIB$(1)_T_$(2)_H_$(3))/dllcrt2.o \
199+
$$(TLIB$(1)_T_$(2)_H_$(3))/crt2.o
200+
endif
201+
endef
200202
$(foreach host,$(CFG_HOST), \
201203
$(foreach target,$(CFG_TARGET), \
202-
$(foreach stage,$(STAGES), \
203-
$(foreach obj,rsbegin rsend, \
204-
$(eval $(call TARGET_RUSTRT_STARTUP_OBJ,$(stage),$(target),$(host),$(obj)))))))
204+
$(eval $(call STARTUP_OBJS_COMPAT,0,$(target),$(host)))))

src/doc/book/custom-allocators.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
138138
# fn main() {}
139139
# #[lang = "panic_fmt"] fn panic_fmt() {}
140140
# #[lang = "eh_personality"] fn eh_personality() {}
141-
# #[lang = "eh_unwind_resume"] extern fn eh_unwind_resume() {}
142-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
143-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
144141
```
145142

146143
After we compile this crate, it can be used as follows:

src/doc/book/lang-items.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ fn main(argc: isize, argv: *const *const u8) -> isize {
5959

6060
#[lang = "eh_personality"] extern fn eh_personality() {}
6161
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
62-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
63-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
64-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
6562
```
6663

6764
Note the use of `abort`: the `exchange_malloc` lang item is assumed to

src/doc/book/no-stdlib.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
3939
// provided by libstd.
4040
#[lang = "eh_personality"] extern fn eh_personality() {}
4141
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
42-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
43-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
44-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
4542
# // fn main() {} tricked you, rustdoc!
4643
```
4744

@@ -66,9 +63,6 @@ pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {
6663

6764
#[lang = "eh_personality"] extern fn eh_personality() {}
6865
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
69-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
70-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
71-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
7266
# // fn main() {} tricked you, rustdoc!
7367
```
7468

src/librustc/middle/lang_items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ lets_do_this! {
340340

341341
EhPersonalityLangItem, "eh_personality", eh_personality;
342342
EhPersonalityCatchLangItem, "eh_personality_catch", eh_personality_catch;
343-
EhUnwindResumeLangItem, "eh_unwind_resume", eh_unwind_resume;
344343
MSVCTryFilterLangItem, "msvc_try_filter", msvc_try_filter;
345344

346345
OwnedBoxLangItem, "owned_box", owned_box;

src/librustc/middle/weak_lang_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ pub fn check_crate(krate: &hir::Crate,
4343
if items.eh_personality().is_none() {
4444
items.missing.push(lang_items::EhPersonalityLangItem);
4545
}
46-
if sess.target.target.options.custom_unwind_resume &
47-
items.eh_unwind_resume().is_none() {
48-
items.missing.push(lang_items::EhUnwindResumeLangItem);
49-
}
5046

5147
{
5248
let mut cx = Context { sess: sess, items: items };
@@ -123,5 +119,4 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
123119
weak_lang_items! {
124120
panic_fmt, PanicFmtLangItem, rust_begin_unwind;
125121
eh_personality, EhPersonalityLangItem, rust_eh_personality;
126-
eh_unwind_resume, EhUnwindResumeLangItem, rust_eh_unwind_resume;
127122
}

0 commit comments

Comments
 (0)