From e2dbba8d4d4fe42e38e8db61a5801d719f577c79 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 22 Jul 2024 11:45:38 -0400 Subject: [PATCH 1/3] rewrite c-unwind-abi-catch-lib-panic to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../c-unwind-abi-catch-lib-panic/Makefile | 35 ------------------ .../c-unwind-abi-catch-lib-panic/rmake.rs | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 tests/run-make/c-unwind-abi-catch-lib-panic/Makefile create mode 100644 tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index fa340a02213..469bec31e47 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,5 +1,4 @@ run-make/branch-protection-check-IBT/Makefile -run-make/c-unwind-abi-catch-lib-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile run-make/cross-lang-lto-clang/Makefile diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile b/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile deleted file mode 100644 index 2bb8d42495d..00000000000 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# Exercise unwinding a panic. This catches a panic across an FFI boundary and downcasts it into an integer. The Rust code that panics is in a separate crate. -# See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb - -# ignore-cross-compile -# needs-unwind -include ../tools.mk - -all: archive - # Compile `main.rs`, which will link into our library, and run it. - $(RUSTC) main.rs - $(call RUN,main) - -ifdef IS_MSVC -archive: add.o panic.o - # Now, create an archive using these two objects. - $(AR) crus $(TMPDIR)/add.lib $(TMPDIR)/add.o $(TMPDIR)/panic.o -else -archive: add.o panic.o - # Now, create an archive using these two objects. - $(AR) crus $(TMPDIR)/libadd.a $(TMPDIR)/add.o $(TMPDIR)/panic.o -endif - -# Compile `panic.rs` into an object file. -# -# Note that we invoke `rustc` directly, so we may emit an object rather -# than an archive. We'll do that later. -panic.o: - $(BARE_RUSTC) $(RUSTFLAGS) \ - --out-dir $(TMPDIR) \ - --emit=obj panic.rs - -# Compile `add.c` into an object file. -add.o: - $(call COMPILE_OBJ,$(TMPDIR)/add.o,add.c) - diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs b/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs new file mode 100644 index 00000000000..4bdb8579af5 --- /dev/null +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs @@ -0,0 +1,36 @@ +// Exercise unwinding a panic. This catches a panic across an FFI (foreign function interface) +// boundary and downcasts it into an integer. +// The Rust code that panics is in a separate crate. +// See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ needs-unwind +// Reason: this test exercises unwinding a panic + +use run_make_support::{cc, is_msvc, llvm_ar, run, rustc}; + +fn main() { + // Compile `add.c` into an object file. + if is_msvc() { + cc().arg("-c").out_exe("add").input("add.c").run(); + } else { + cc().arg("-v").arg("-c").out_exe("add.o").input("add.c").run(); + }; + + // Compile `panic.rs` into an object file. + // Note that we invoke `rustc` directly, so we may emit an object rather + // than an archive. We'll do that later. + rustc().emit("obj").input("panic.rs").run(); + + // Now, create an archive using these two objects. + if is_msvc() { + llvm_ar().obj_to_ar().args(&["libadd.a", "add.obj", "panic.o"]).run(); + } else { + llvm_ar().obj_to_ar().args(&["libadd.a", "add.o", "panic.o"]).run(); + }; + + // Compile `main.rs`, which will link into our library, and run it. + rustc().input("main.rs").run(); + run("main"); +} From 2a3e4c547b35c44461bc8c3c2dcf4b99c3bafd63 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 22 Jul 2024 11:55:20 -0400 Subject: [PATCH 2/3] rewrite foreign-rust-exceptions to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../run-make/foreign-rust-exceptions/Makefile | 13 ----------- .../run-make/foreign-rust-exceptions/rmake.rs | 23 +++++++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/foreign-rust-exceptions/Makefile create mode 100644 tests/run-make/foreign-rust-exceptions/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 469bec31e47..e35b69449ac 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -14,7 +14,6 @@ run-make/extern-fn-reachable/Makefile run-make/fmt-write-bloat/Makefile run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile -run-make/foreign-rust-exceptions/Makefile run-make/incr-add-rust-src-component/Makefile run-make/issue-35164/Makefile run-make/issue-36710/Makefile diff --git a/tests/run-make/foreign-rust-exceptions/Makefile b/tests/run-make/foreign-rust-exceptions/Makefile deleted file mode 100644 index 59cee284200..00000000000 --- a/tests/run-make/foreign-rust-exceptions/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# ignore-cross-compile -# ignore-i686-pc-windows-gnu -# needs-unwind - -# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder -# so cross-DLL unwinding does not work. - -include ../tools.mk - -all: - $(RUSTC) bar.rs --crate-type=cdylib - $(RUSTC) foo.rs - $(call RUN,foo) 2>&1 | $(CGREP) "Rust cannot catch foreign exceptions" diff --git a/tests/run-make/foreign-rust-exceptions/rmake.rs b/tests/run-make/foreign-rust-exceptions/rmake.rs new file mode 100644 index 00000000000..06f7a07c62d --- /dev/null +++ b/tests/run-make/foreign-rust-exceptions/rmake.rs @@ -0,0 +1,23 @@ +// Rust exceptions can be foreign (from C code, in this test) or local. Foreign +// exceptions should not be caught, as that can cause undefined behaviour. Instead +// of catching them, #102721 made it so that the binary panics in execution with a helpful message. +// This test checks that the correct message appears and that execution fails when trying to catch +// a foreign exception. +// See https://github.com/rust-lang/rust/issues/102715 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ needs-unwind +// Reason: unwinding panics is exercised in this test + +//FIXME(Oneirical): ignore-i686-pc-windows-gnu +// This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder +// so cross-DLL unwinding does not work. + +use run_make_support::{run_fail, rustc}; + +fn main() { + rustc().input("bar.rs").crate_type("cdylib").run(); + rustc().input("foo.rs").run(); + run_fail("foo").assert_stderr_contains("Rust cannot catch foreign exceptions"); +} From 3cc1056ff77a9a6fb338549b712aebfef1959be0 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 22 Jul 2024 13:04:32 -0400 Subject: [PATCH 3/3] rewrite export-executable-symbols to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../c-unwind-abi-catch-lib-panic/rmake.rs | 6 ++--- .../export-executable-symbols/Makefile | 11 -------- .../export-executable-symbols/rmake.rs | 25 +++++++++++++++++++ .../run-make/foreign-rust-exceptions/rmake.rs | 4 +-- 5 files changed, 30 insertions(+), 17 deletions(-) delete mode 100644 tests/run-make/export-executable-symbols/Makefile create mode 100644 tests/run-make/export-executable-symbols/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index e35b69449ac..c3993e41a50 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-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile run-make/emit-to-stdout/Makefile -run-make/export-executable-symbols/Makefile run-make/extern-fn-reachable/Makefile run-make/fmt-write-bloat/Makefile run-make/foreign-double-unwind/Makefile diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs b/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs index 4bdb8579af5..62e1748b6fb 100644 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/rmake.rs @@ -8,7 +8,7 @@ //@ needs-unwind // Reason: this test exercises unwinding a panic -use run_make_support::{cc, is_msvc, llvm_ar, run, rustc}; +use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name}; fn main() { // Compile `add.c` into an object file. @@ -25,9 +25,9 @@ fn main() { // Now, create an archive using these two objects. if is_msvc() { - llvm_ar().obj_to_ar().args(&["libadd.a", "add.obj", "panic.o"]).run(); + llvm_ar().obj_to_ar().args(&[&static_lib_name("add"), "add.obj", "panic.o"]).run(); } else { - llvm_ar().obj_to_ar().args(&["libadd.a", "add.o", "panic.o"]).run(); + llvm_ar().obj_to_ar().args(&[&static_lib_name("add"), "add.o", "panic.o"]).run(); }; // Compile `main.rs`, which will link into our library, and run it. diff --git a/tests/run-make/export-executable-symbols/Makefile b/tests/run-make/export-executable-symbols/Makefile deleted file mode 100644 index c4d29aa2bf4..00000000000 --- a/tests/run-make/export-executable-symbols/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../tools.mk - -# ignore-wasm32 -# ignore-wasm64 -# ignore-none no-std is not supported -# only-linux - -all: - $(RUSTC) -Zexport-executable-symbols main.rs --target $(TARGET) --crate-type=bin - nm $(TMPDIR)/main | $(CGREP) exported_symbol - diff --git a/tests/run-make/export-executable-symbols/rmake.rs b/tests/run-make/export-executable-symbols/rmake.rs new file mode 100644 index 00000000000..77f968189b6 --- /dev/null +++ b/tests/run-make/export-executable-symbols/rmake.rs @@ -0,0 +1,25 @@ +// The unstable flag `-Z export-executable-symbols` exports symbols from executables, as if +// they were dynamic libraries. This test is a simple smoke test to check that this feature +// works by using it in compilation, then checking that the output binary contains the exported +// symbol. +// See https://github.com/rust-lang/rust/pull/85673 + +//@ only-unix +// Reason: the export-executable-symbols flag only works on Unix +// due to hardcoded platform-specific implementation +// (See #85673) +//@ ignore-wasm32 +//@ ignore-wasm64 +//@ ignore-none +// Reason: no-std is not supported + +use run_make_support::{bin_name, llvm_readobj, rustc}; + +fn main() { + rustc().arg("-Zexport-executable-symbols").input("main.rs").crate_type("bin").run(); + llvm_readobj() + .symbols() + .input(bin_name("main")) + .run() + .assert_stdout_contains("exported_symbol"); +} diff --git a/tests/run-make/foreign-rust-exceptions/rmake.rs b/tests/run-make/foreign-rust-exceptions/rmake.rs index 06f7a07c62d..9c917078aaa 100644 --- a/tests/run-make/foreign-rust-exceptions/rmake.rs +++ b/tests/run-make/foreign-rust-exceptions/rmake.rs @@ -10,8 +10,8 @@ //@ needs-unwind // Reason: unwinding panics is exercised in this test -//FIXME(Oneirical): ignore-i686-pc-windows-gnu -// This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder +//@ ignore-i686-pc-windows-gnu +// Reason: This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder // so cross-DLL unwinding does not work. use run_make_support::{run_fail, rustc};