Skip to content

Commit 0e9fa9b

Browse files
committed
rewrite foreign-exceptions to rmake
1 parent f8d1cab commit 0e9fa9b

File tree

7 files changed

+38
-60
lines changed

7 files changed

+38
-60
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
use std::path::PathBuf;
22

3-
<<<<<<< HEAD
43
use super::cygpath::get_windows_path;
54
use crate::artifact_names::{dynamic_lib_name, static_lib_name};
6-
use crate::external_deps::cc::cc;
7-
=======
8-
use crate::artifact_names::static_lib_name;
95
use crate::external_deps::cc::{cc, cxx};
10-
>>>>>>> e3cf7e53339 (rewrite foreign-double-unwind to rmake)
116
use crate::external_deps::llvm::llvm_ar;
127
use crate::path_helpers::path;
138
use crate::targets::{is_darwin, is_msvc, is_windows};

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

-38
Original file line numberDiff line numberDiff line change
@@ -215,41 +215,3 @@ pub fn extra_cxx_flags() -> Vec<&'static str> {
215215
}
216216
}
217217
}
218-
219-
/// `EXTRARSCXXFLAGS`
220-
pub fn extra_rs_cxx_flags() -> Vec<&'static str> {
221-
// Adapted from tools.mk (trimmed):
222-
//
223-
// ```makefile
224-
// ifdef IS_WINDOWS
225-
// ifdef IS_MSVC
226-
// else
227-
// EXTRARSCXXFLAGS := -lstatic:-bundle=stdc++
228-
// endif
229-
// else
230-
// ifeq ($(UNAME),Darwin)
231-
// EXTRARSCXXFLAGS := -lc++
232-
// else
233-
// ifeq ($(UNAME),FreeBSD)
234-
// else
235-
// ifeq ($(UNAME),SunOS)
236-
// else
237-
// ifeq ($(UNAME),OpenBSD)
238-
// else
239-
// EXTRARSCXXFLAGS := -lstdc++
240-
// endif
241-
// endif
242-
// endif
243-
// endif
244-
// endif
245-
// ```
246-
if is_windows() {
247-
if is_msvc() { vec![] } else { vec!["-lstatic:-bundle=stdc++"] }
248-
} else {
249-
match &uname()[..] {
250-
"Darwin" => vec!["-lc++"],
251-
"FreeBSD" | "SunOS" | "OpenBSD" => vec![],
252-
_ => vec!["-lstdc++"],
253-
}
254-
}
255-
}

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
@@ -11,7 +11,6 @@ run-make/dep-info/Makefile
1111
run-make/emit-to-stdout/Makefile
1212
run-make/extern-fn-reachable/Makefile
1313
run-make/fmt-write-bloat/Makefile
14-
run-make/foreign-exceptions/Makefile
1514
run-make/incr-add-rust-src-component/Makefile
1615
run-make/issue-35164/Makefile
1716
run-make/issue-47551/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)