about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-18 13:12:38 -0400
committerOneirical <manchot@videotron.ca>2024-08-02 10:06:20 -0400
commit46b4083e6fa64445d714fff001ce92907980deb1 (patch)
tree554017590019be63d59b27930960605751ff0e35
parent5b44f800f37e0d3093aa5b89c10eb401bbc600eb (diff)
downloadrust-46b4083e6fa64445d714fff001ce92907980deb1.tar.gz
rust-46b4083e6fa64445d714fff001ce92907980deb1.zip
rewrite foreign-exceptions to rmake
-rw-r--r--src/tools/run-make-support/src/external_deps/c_build.rs5
-rw-r--r--src/tools/run-make-support/src/external_deps/cc.rs38
-rw-r--r--src/tools/run-make-support/src/external_deps/rustc.rs20
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/cpp-global-destructors/rmake.rs19
-rw-r--r--tests/run-make/foreign-double-unwind/rmake.rs4
-rw-r--r--tests/run-make/foreign-exceptions/Makefile12
-rw-r--r--tests/run-make/foreign-exceptions/rmake.rs19
8 files changed, 48 insertions, 70 deletions
diff --git a/src/tools/run-make-support/src/external_deps/c_build.rs b/src/tools/run-make-support/src/external_deps/c_build.rs
index 901aede4901..15e02d04393 100644
--- a/src/tools/run-make-support/src/external_deps/c_build.rs
+++ b/src/tools/run-make-support/src/external_deps/c_build.rs
@@ -1,13 +1,8 @@
 use std::path::PathBuf;
 
-<<<<<<< HEAD
 use super::cygpath::get_windows_path;
 use crate::artifact_names::{dynamic_lib_name, static_lib_name};
-use crate::external_deps::cc::cc;
-=======
-use crate::artifact_names::static_lib_name;
 use crate::external_deps::cc::{cc, cxx};
->>>>>>> e3cf7e53339 (rewrite foreign-double-unwind to rmake)
 use crate::external_deps::llvm::llvm_ar;
 use crate::path_helpers::path;
 use crate::targets::{is_darwin, is_msvc, is_windows};
diff --git a/src/tools/run-make-support/src/external_deps/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs
index 941a43854a0..39ac3efef39 100644
--- a/src/tools/run-make-support/src/external_deps/cc.rs
+++ b/src/tools/run-make-support/src/external_deps/cc.rs
@@ -214,41 +214,3 @@ pub fn extra_cxx_flags() -> Vec<&'static str> {
         }
     }
 }
-
-/// `EXTRARSCXXFLAGS`
-pub fn extra_rs_cxx_flags() -> Vec<&'static str> {
-    // Adapted from tools.mk (trimmed):
-    //
-    // ```makefile
-    // ifdef IS_WINDOWS
-    //     ifdef IS_MSVC
-    //     else
-    //         EXTRARSCXXFLAGS := -lstatic:-bundle=stdc++
-    //     endif
-    // else
-    //     ifeq ($(UNAME),Darwin)
-    //         EXTRARSCXXFLAGS := -lc++
-    //     else
-    //         ifeq ($(UNAME),FreeBSD)
-    //         else
-    //             ifeq ($(UNAME),SunOS)
-    //             else
-    //                 ifeq ($(UNAME),OpenBSD)
-    //                 else
-    //                     EXTRARSCXXFLAGS := -lstdc++
-    //                 endif
-    //             endif
-    //         endif
-    //     endif
-    // endif
-    // ```
-    if is_windows() {
-        if is_msvc() { vec![] } else { vec!["-lstatic:-bundle=stdc++"] }
-    } else {
-        match &uname()[..] {
-            "Darwin" => vec!["-lc++"],
-            "FreeBSD" | "SunOS" | "OpenBSD" => vec![],
-            _ => vec!["-lstdc++"],
-        }
-    }
-}
diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs
index cabfbd59c48..cece58d2956 100644
--- a/src/tools/run-make-support/src/external_deps/rustc.rs
+++ b/src/tools/run-make-support/src/external_deps/rustc.rs
@@ -5,7 +5,7 @@ use crate::command::Command;
 use crate::env::env_var;
 use crate::path_helpers::cwd;
 use crate::util::set_host_rpath;
-use crate::{is_msvc, is_windows, uname};
+use crate::{is_darwin, is_msvc, is_windows, uname};
 
 /// Construct a new `rustc` invocation. This will automatically set the library
 /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
@@ -344,10 +344,26 @@ impl Rustc {
         // endif
         // ```
         let flag = if is_windows() {
+            // 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:-bundle to only
+            // link the parts of libstdc++ that we actually use, which doesn't include
+            // the dependency on the pthreads DLL.
             if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
+        } else if is_darwin() {
+            Some("-lc++")
         } else {
             match &uname()[..] {
-                "Darwin" => Some("-lc++"),
                 "FreeBSD" | "SunOS" | "OpenBSD" => None,
                 _ => Some("-lstdc++"),
             }
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 2d5f7b9ae9e..bd4f54d22da 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -9,7 +9,6 @@ run-make/dep-info-spaces/Makefile
 run-make/dep-info/Makefile
 run-make/emit-to-stdout/Makefile
 run-make/extern-fn-reachable/Makefile
-run-make/foreign-exceptions/Makefile
 run-make/incr-add-rust-src-component/Makefile
 run-make/issue-84395-lto-embed-bitcode/Makefile
 run-make/issue-88756-default-output/Makefile
diff --git a/tests/run-make/cpp-global-destructors/rmake.rs b/tests/run-make/cpp-global-destructors/rmake.rs
index 02928b9de9d..9bc5c84e10d 100644
--- a/tests/run-make/cpp-global-destructors/rmake.rs
+++ b/tests/run-make/cpp-global-destructors/rmake.rs
@@ -6,17 +6,16 @@
 //@ ignore-cross-compile
 // Reason: the compiled binary is executed
 
-// FIXME(Oneirical): are these really necessary? This test is supposed to test a musl
-// bug... and it ignores musl? This wasn't part of the original test at its creation, which
-// had no ignores.
+//@ ignore-none
+// Reason: no-std is not supported.
+//@ ignore-wasm32
+//@ ignore-wasm64
+// Reason: compiling C++ to WASM may cause problems.
 
-//# ignore-none no-std is not supported
-//# ignore-wasm32 FIXME: don't attempt to compile C++ to WASM
-//# ignore-wasm64 FIXME: don't attempt to compile C++ to WASM
-//# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for `std`
-//# ignore-musl FIXME: this makefile needs teaching how to use a musl toolchain
-//#                    (see dist-i586-gnu-i586-i686-musl Dockerfile)
-//# ignore-sgx
+// Neither of these are tested in full CI.
+//@ ignore-nvptx64-nvidia-cuda
+// Reason: can't find crate "std"
+//@ ignore-sgx
 
 use run_make_support::{build_native_static_lib_cxx, run, rustc};
 
diff --git a/tests/run-make/foreign-double-unwind/rmake.rs b/tests/run-make/foreign-double-unwind/rmake.rs
index b2ac8bfbead..9bd3b4c0fea 100644
--- a/tests/run-make/foreign-double-unwind/rmake.rs
+++ b/tests/run-make/foreign-double-unwind/rmake.rs
@@ -12,10 +12,10 @@
 //@ ignore-cross-compile
 // Reason: the compiled binary is executed
 
-use run_make_support::{build_native_static_lib_cxx, run, rustc};
+use run_make_support::{build_native_static_lib_cxx, run_fail, rustc};
 
 fn main() {
     build_native_static_lib_cxx("foo");
     rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
-    run("foo").assert_stdout_not_contains("unreachable");
+    run_fail("foo").assert_stdout_not_contains("unreachable");
 }
diff --git a/tests/run-make/foreign-exceptions/Makefile b/tests/run-make/foreign-exceptions/Makefile
deleted file mode 100644
index 56c41b274fb..00000000000
--- a/tests/run-make/foreign-exceptions/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# ignore-cross-compile
-# needs-unwind
-include ../tools.mk
-
-all: foo
-	$(call RUN,foo)
-
-foo: foo.rs $(call NATIVE_STATICLIB,foo)
-	$(RUSTC) $< -lfoo $(EXTRARSCXXFLAGS)
-
-$(TMPDIR)/libfoo.o: foo.cpp
-	$(call COMPILE_OBJ_CXX,$@,$<)
diff --git a/tests/run-make/foreign-exceptions/rmake.rs b/tests/run-make/foreign-exceptions/rmake.rs
new file mode 100644
index 00000000000..929319f049f
--- /dev/null
+++ b/tests/run-make/foreign-exceptions/rmake.rs
@@ -0,0 +1,19 @@
+// This test was created to check that compilation and execution still works
+// after the addition of a new feature, in #65646: the ability to unwind panics
+// and exceptions back and forth between Rust and C++. This is a basic smoke test,
+// this feature being broken in quiet or subtle ways could still result in this test
+// passing.
+// See https://github.com/rust-lang/rust/pull/65646
+
+//@ needs-unwind
+// Reason: this test exercises panic unwinding
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{build_native_static_lib_cxx, run, rustc};
+
+fn main() {
+    build_native_static_lib_cxx("foo");
+    rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
+    run("foo");
+}