Skip to content

Commit a505735

Browse files
committed
Hack to make C++ exceptions test work on i686-pc-windows-gnu
1 parent 998e277 commit a505735

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

src/test/run-make-fulldeps/foreign-exceptions/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ all: foo
44
$(call RUN,foo)
55

66
foo: foo.rs $(call NATIVE_STATICLIB,foo)
7-
$(RUSTC) $< -lfoo $(EXTRACXXFLAGS)
7+
$(RUSTC) $< -lfoo $(EXTRARSCXXFLAGS)
88

99
$(TMPDIR)/libfoo.o: foo.cpp
1010
$(call COMPILE_OBJ_CXX,$@,$<)

src/test/run-make-fulldeps/foreign-exceptions/foo.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// are ignored by catch_unwind. Also tests that Rust panics can unwind through
33
// C++ code.
44

5+
// For linking libstdc++ on MinGW
6+
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]
7+
58
#![feature(unwind_attributes)]
69

710
use std::panic::{catch_unwind, AssertUnwindSafe};

src/test/run-make-fulldeps/issue-36710/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ all: foo
66
$(call RUN,foo)
77

88
foo: foo.rs $(call NATIVE_STATICLIB,foo)
9-
$(RUSTC) $< -lfoo $(EXTRACXXFLAGS)
9+
$(RUSTC) $< -lfoo $(EXTRARSCXXFLAGS)
1010

1111
$(TMPDIR)/libfoo.o: foo.cpp
1212
$(call COMPILE_OBJ_CXX,$@,$<)

src/test/run-make-fulldeps/issue-36710/foo.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Tests that linking to C++ code with global destructors works.
22

3+
// For linking libstdc++ on MinGW
4+
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]
5+
36
extern { fn get() -> u32; }
47

58
fn main() {

src/test/run-make-fulldeps/tools.mk

+17
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ ifdef IS_MSVC
8181
else
8282
EXTRACFLAGS := -lws2_32 -luserenv
8383
EXTRACXXFLAGS := -lstdc++
84+
# So this is a bit hacky: we can't use the DLL version of libstdc++ because
85+
# it pulls in the DLL version of libgcc, which means that we end up with 2
86+
# instances of the DW2 unwinding implementation. This is a problem on
87+
# i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
88+
# unwind information with the unwinding implementation, and libstdc++'s
89+
# __cxa_throw won't see the unwinding info we registered with our statically
90+
# linked libgcc.
91+
#
92+
# Now, simply statically linking libstdc++ would fix this problem, except
93+
# that it is compiled with the expectation that pthreads is dynamically
94+
# linked as a DLL and will fail to link with a statically linked libpthread.
95+
#
96+
# So we end up with the following hack: we link use static-nobundle to only
97+
# link the parts of libstdc++ that we actually use, which doesn't include
98+
# the dependency on the pthreads DLL.
99+
EXTRARSCXXFLAGS := -l static-nobundle=stdc++
84100
endif
85101
else
86102
ifeq ($(UNAME),Darwin)
@@ -98,6 +114,7 @@ ifeq ($(UNAME),OpenBSD)
98114
else
99115
EXTRACFLAGS := -lm -lrt -ldl -lpthread
100116
EXTRACXXFLAGS := -lstdc++
117+
EXTRARSCXXFLAGS := -lstdc++
101118
endif
102119
endif
103120
endif

0 commit comments

Comments
 (0)