Skip to content

Commit

Permalink
Hack to make C++ exceptions test work on i686-pc-windows-gnu
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Nov 3, 2019
1 parent 5f1a0af commit 83d6bf4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/foreign-exceptions/Makefile
Expand Up @@ -4,7 +4,7 @@ all: foo
$(call RUN,foo)

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

$(TMPDIR)/libfoo.o: foo.cpp
$(call COMPILE_OBJ_CXX,$@,$<)
3 changes: 3 additions & 0 deletions src/test/run-make-fulldeps/foreign-exceptions/foo.rs
Expand Up @@ -2,6 +2,9 @@
// are ignored by catch_unwind. Also tests that Rust panics can unwind through
// C++ code.

// For linking libstdc++ on MinGW
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]

#![feature(unwind_attributes)]

use std::panic::{catch_unwind, AssertUnwindSafe};
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/issue-36710/Makefile
Expand Up @@ -6,7 +6,7 @@ all: foo
$(call RUN,foo)

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

$(TMPDIR)/libfoo.o: foo.cpp
$(call COMPILE_OBJ_CXX,$@,$<)
3 changes: 3 additions & 0 deletions src/test/run-make-fulldeps/issue-36710/foo.rs
@@ -1,5 +1,8 @@
// Tests that linking to C++ code with global destructors works.

// For linking libstdc++ on MinGW
#![cfg_attr(all(windows, target_env = "gnu"), feature(static_nobundle))]

extern { fn get() -> u32; }

fn main() {
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-make-fulldeps/tools.mk
Expand Up @@ -81,6 +81,22 @@ ifdef IS_MSVC
else
EXTRACFLAGS := -lws2_32 -luserenv
EXTRACXXFLAGS := -lstdc++
# So this is a bit hacky: we can't use the DLL version of libstdc++ because
# it pulls in the DLL version of libgcc, which means that we end up with 2
# instances of the DW2 unwinding implementation. This is a problem on
# i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
# unwind information with the unwinding implementation, and libstdc++'s
# __cxa_throw won't see the unwinding info we registered with our statically
# linked libgcc.
#
# Now, simply statically linking libstdc++ would fix this problem, except
# that it is compiled with the expectation that pthreads is dynamically
# linked as a DLL and will fail to link with a statically linked libpthread.
#
# So we end up with the following hack: we link use static-nobundle to only
# link the parts of libstdc++ that we actually use, which doesn't include
# the dependency on the pthreads DLL.
EXTRARSCXXFLAGS := -l static-nobundle=stdc++
endif
else
ifeq ($(UNAME),Darwin)
Expand All @@ -98,6 +114,7 @@ ifeq ($(UNAME),OpenBSD)
else
EXTRACFLAGS := -lm -lrt -ldl -lpthread
EXTRACXXFLAGS := -lstdc++
EXTRARSCXXFLAGS := -lstdc++
endif
endif
endif
Expand Down

0 comments on commit 83d6bf4

Please sign in to comment.