]> git.lizzy.rs Git - rust.git/commitdiff
Hack to make C++ exceptions test work on i686-pc-windows-gnu
authorAmanieu d'Antras <amanieu@gmail.com>
Sat, 26 Oct 2019 16:41:55 +0000 (17:41 +0100)
committerAmanieu d'Antras <amanieu@gmail.com>
Sun, 3 Nov 2019 14:03:21 +0000 (14:03 +0000)
src/test/run-make-fulldeps/foreign-exceptions/Makefile
src/test/run-make-fulldeps/foreign-exceptions/foo.rs
src/test/run-make-fulldeps/issue-36710/Makefile
src/test/run-make-fulldeps/issue-36710/foo.rs
src/test/run-make-fulldeps/tools.mk

index fd15db9f15176e25e21eb79337f438cbdff5401a..7eba52f3c24e87914d446f97d63542d74bc30668 100644 (file)
@@ -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,$@,$<)
index 83adf000d9efe2776b55adbf680b911e406d4c09..399c78f8d2d021cb7cdb80bc82400361666f7b6d 100644 (file)
@@ -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};
index dc1fbb4cefb8450d97ae4d91f41a4747d2931dae..4f93d97636e6004df6f86731d5937e2e7ed0dbfb 100644 (file)
@@ -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,$@,$<)
index a9d3effbd18060cb959807fbb9cacf1cc211c2d8..061f07c32434016b3686361998f8331171904e19 100644 (file)
@@ -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() {
index 98bae25220e9dc5c3bf46b03a8c9e29edb5710a8..3194826371762a10b75058c05aafe0ab958b9e3a 100644 (file)
@@ -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)
@@ -98,6 +114,7 @@ ifeq ($(UNAME),OpenBSD)
 else
        EXTRACFLAGS := -lm -lrt -ldl -lpthread
        EXTRACXXFLAGS := -lstdc++
+       EXTRARSCXXFLAGS := -lstdc++
 endif
 endif
 endif