Skip to content

Commit b89be60

Browse files
committed
rewrite foreign-exceptions to rmake
1 parent 796d8e9 commit b89be60

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

src/tools/run-make-support/src/external_deps/rustc.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::command::Command;
55
use crate::env::env_var;
66
use crate::path_helpers::cwd;
77
use crate::util::set_host_rpath;
8-
use crate::{is_msvc, is_windows, uname};
8+
use crate::{is_darwin, is_msvc, is_windows, uname};
99

1010
/// Construct a new `rustc` invocation. This will automatically set the library
1111
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
@@ -344,10 +344,26 @@ impl Rustc {
344344
// endif
345345
// ```
346346
let flag = if is_windows() {
347+
// So this is a bit hacky: we can't use the DLL version of libstdc++ because
348+
// it pulls in the DLL version of libgcc, which means that we end up with 2
349+
// instances of the DW2 unwinding implementation. This is a problem on
350+
// i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
351+
// unwind information with the unwinding implementation, and libstdc++'s
352+
// __cxa_throw won't see the unwinding info we registered with our statically
353+
// linked libgcc.
354+
//
355+
// Now, simply statically linking libstdc++ would fix this problem, except
356+
// that it is compiled with the expectation that pthreads is dynamically
357+
// linked as a DLL and will fail to link with a statically linked libpthread.
358+
//
359+
// So we end up with the following hack: we link use static:-bundle to only
360+
// link the parts of libstdc++ that we actually use, which doesn't include
361+
// the dependency on the pthreads DLL.
347362
if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
363+
} else if is_darwin() {
364+
Some("-lc++")
348365
} else {
349366
match &uname()[..] {
350-
"Darwin" => Some("-lc++"),
351367
"FreeBSD" | "SunOS" | "OpenBSD" => None,
352368
_ => Some("-lstdc++"),
353369
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ run-make/extern-fn-with-union/Makefile
2929
run-make/extern-multiple-copies/Makefile
3030
run-make/extern-multiple-copies2/Makefile
3131
run-make/fmt-write-bloat/Makefile
32-
run-make/foreign-exceptions/Makefile
3332
run-make/foreign-rust-exceptions/Makefile
3433
run-make/incr-add-rust-src-component/Makefile
3534
run-make/incr-foreign-head-span/Makefile

tests/run-make/foreign-double-unwind/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//@ ignore-cross-compile
1313
// Reason: the compiled binary is executed
1414

15-
use run_make_support::{build_native_static_lib_cxx, run, rustc};
15+
use run_make_support::{build_native_static_lib_cxx, run_fail, rustc};
1616

1717
fn main() {
1818
build_native_static_lib_cxx("foo");
1919
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
20-
run("foo").assert_stdout_not_contains("unreachable");
20+
run_fail("foo").assert_stdout_not_contains("unreachable");
2121
}

tests/run-make/foreign-exceptions/Makefile

-12
This file was deleted.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test was created to check that compilation and execution still works
2+
// after the addition of a new feature, in #65646: the ability to unwind panics
3+
// and exceptions back and forth between Rust and C++. Should this feature be broken,
4+
// the test should fail.
5+
// See https://github.com/rust-lang/rust/pull/65646
6+
7+
//@ needs-unwind
8+
// Reason: this test exercises panic unwinding
9+
//@ ignore-cross-compile
10+
// Reason: the compiled binary is executed
11+
12+
use run_make_support::{build_native_static_lib_cxx, run, rustc};
13+
14+
fn main() {
15+
build_native_static_lib_cxx("foo");
16+
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
17+
run("foo");
18+
}

0 commit comments

Comments
 (0)