From b3ee91128e7527b16b24bfeca81186490ace0cfa Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 27 May 2024 11:37:31 +0000 Subject: [PATCH 1/4] Use `rmake` for `windows-` run-make tests --- .../run-make-support/src/llvm_readobj.rs | 6 ++++++ tests/run-make/issue-85441/Makefile | 9 --------- .../windows-binary-no-external-deps/Makefile | 9 --------- .../windows-binary-no-external-deps/rmake.rs | 15 +++++++++++++++ tests/run-make/windows-safeseh/Makefile | 19 ------------------- tests/run-make/windows-safeseh/rmake.rs | 15 +++++++++++++++ tests/run-make/windows-spawn/Makefile | 8 -------- tests/run-make/windows-spawn/rmake.rs | 17 +++++++++++++++++ tests/run-make/windows-spawn/spawn.rs | 10 ++++------ tests/run-make/windows-subsystem/Makefile | 6 ------ tests/run-make/windows-subsystem/rmake.rs | 8 ++++++++ .../{issue-85441 => windows-ws2_32}/empty.rs | 0 tests/run-make/windows-ws2_32/rmake.rs | 13 +++++++++++++ 13 files changed, 78 insertions(+), 57 deletions(-) delete mode 100644 tests/run-make/issue-85441/Makefile delete mode 100644 tests/run-make/windows-binary-no-external-deps/Makefile create mode 100644 tests/run-make/windows-binary-no-external-deps/rmake.rs delete mode 100644 tests/run-make/windows-safeseh/Makefile create mode 100644 tests/run-make/windows-safeseh/rmake.rs delete mode 100644 tests/run-make/windows-spawn/Makefile create mode 100644 tests/run-make/windows-spawn/rmake.rs delete mode 100644 tests/run-make/windows-subsystem/Makefile create mode 100644 tests/run-make/windows-subsystem/rmake.rs rename tests/run-make/{issue-85441 => windows-ws2_32}/empty.rs (100%) create mode 100644 tests/run-make/windows-ws2_32/rmake.rs diff --git a/src/tools/run-make-support/src/llvm_readobj.rs b/src/tools/run-make-support/src/llvm_readobj.rs index f114aacfa3fc7..c91ed31bd41a8 100644 --- a/src/tools/run-make-support/src/llvm_readobj.rs +++ b/src/tools/run-make-support/src/llvm_readobj.rs @@ -42,6 +42,12 @@ impl LlvmReadobj { self } + /// Pass `--coff-imports` to display the Windows DLL imports + pub fn coff_imports(&mut self) -> &mut Self { + self.cmd.arg("--coff-imports"); + self + } + /// Get the [`Output`][::std::process::Output] of the finished process. #[track_caller] pub fn command_output(&mut self) -> ::std::process::Output { diff --git a/tests/run-make/issue-85441/Makefile b/tests/run-make/issue-85441/Makefile deleted file mode 100644 index 987d7f7d4a76f..0000000000000 --- a/tests/run-make/issue-85441/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# only-windows-msvc - -include ../tools.mk - -# Tests that WS2_32.dll is not unnecessarily linked, see issue #85441 - -all: - $(RUSTC) empty.rs - objdump -p $(TMPDIR)/empty.exe | $(CGREP) -v -i "WS2_32.dll" diff --git a/tests/run-make/windows-binary-no-external-deps/Makefile b/tests/run-make/windows-binary-no-external-deps/Makefile deleted file mode 100644 index 8960020fed558..0000000000000 --- a/tests/run-make/windows-binary-no-external-deps/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# only-windows - -PATH=$(SYSTEMROOT)/system32 - -all: - $(RUSTC) hello.rs - $(TMPDIR)/hello.exe diff --git a/tests/run-make/windows-binary-no-external-deps/rmake.rs b/tests/run-make/windows-binary-no-external-deps/rmake.rs new file mode 100644 index 0000000000000..a9ef4996acabe --- /dev/null +++ b/tests/run-make/windows-binary-no-external-deps/rmake.rs @@ -0,0 +1,15 @@ +//@ only-windows + +// Ensure that we aren't relying on any non-system DLLs when compiling and running +// a "hello world" application by setting `PATH` to `C:\Windows\System32`. + +use run_make_support::{run, rustc}; +use std::env; +use std::path::PathBuf; + +fn main() { + let windows_dir = env::var("SystemRoot").unwrap(); + let system32: PathBuf = [&windows_dir, "System32"].iter().collect(); + rustc().input("hello.rs").env("PATH", system32).run(); + run("hello"); +} diff --git a/tests/run-make/windows-safeseh/Makefile b/tests/run-make/windows-safeseh/Makefile deleted file mode 100644 index d6a403961d791..0000000000000 --- a/tests/run-make/windows-safeseh/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# only-windows -# needs-rust-lld - -include ../tools.mk - -all: foo bar - -# Ensure that LLD can link when an .rlib contains a synthetic object -# file referencing exported or used symbols. -foo: - $(RUSTC) -C linker=rust-lld foo.rs - -# Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib. -# Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware. -bar: baz - $(RUSTC) -C linker=rust-lld -C link-arg=/WHOLEARCHIVE:libbaz.rlib bar.rs - -baz: - $(RUSTC) baz.rs diff --git a/tests/run-make/windows-safeseh/rmake.rs b/tests/run-make/windows-safeseh/rmake.rs new file mode 100644 index 0000000000000..56d3ff4ea0d81 --- /dev/null +++ b/tests/run-make/windows-safeseh/rmake.rs @@ -0,0 +1,15 @@ +//@ only-windows +//@ needs-rust-lld + +use run_make_support::rustc; + +fn main() { + // Ensure that LLD can link when an .rlib contains a synthetic object + // file referencing exported or used symbols. + rustc().input("foo.rs").arg("-Clinker=rust-lld").run(); + + // Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib. + // Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware. + rustc().input("baz.rs").run(); + rustc().input("bar.rs").arg("-Clinker=rust-lld").link_arg("/WHOLEARCHIVE:libbaz.rlib").run(); +} diff --git a/tests/run-make/windows-spawn/Makefile b/tests/run-make/windows-spawn/Makefile deleted file mode 100644 index b6cdb169bab48..0000000000000 --- a/tests/run-make/windows-spawn/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include ../tools.mk - -# only-windows - -all: - $(RUSTC) -o "$(TMPDIR)/hopefullydoesntexist bar.exe" hello.rs - $(RUSTC) spawn.rs - $(TMPDIR)/spawn.exe diff --git a/tests/run-make/windows-spawn/rmake.rs b/tests/run-make/windows-spawn/rmake.rs new file mode 100644 index 0000000000000..fb9cf1e214909 --- /dev/null +++ b/tests/run-make/windows-spawn/rmake.rs @@ -0,0 +1,17 @@ +//@ only-windows + +use run_make_support::{run, rustc, tmp_dir}; + +// On Windows `Command` uses `CreateProcessW` to run a new process. +// However, in the past std used to not pass in the application name, leaving +// `CreateProcessW` to use heuristics to guess the intended name from the +// command line string. Sometimes this could go very wrong. +// E.g. in Rust 1.0 `Command::new("foo").arg("bar").spawn()` will try to launch +// `foo bar.exe` if foo.exe does not exist. Which is clearly not desired. + +fn main() { + let out_dir = tmp_dir(); + rustc().input("hello.rs").output(out_dir.join("hopefullydoesntexist bar.exe")).run(); + rustc().input("spawn.rs").run(); + run("spawn"); +} diff --git a/tests/run-make/windows-spawn/spawn.rs b/tests/run-make/windows-spawn/spawn.rs index c34da3d5fde4c..a9e86d1577e55 100644 --- a/tests/run-make/windows-spawn/spawn.rs +++ b/tests/run-make/windows-spawn/spawn.rs @@ -3,10 +3,8 @@ use std::process::Command; fn main() { // Make sure it doesn't try to run "hopefullydoesntexist bar.exe". - assert_eq!(Command::new("hopefullydoesntexist") - .arg("bar") - .spawn() - .unwrap_err() - .kind(), - ErrorKind::NotFound); + assert_eq!( + Command::new("hopefullydoesntexist").arg("bar").spawn().unwrap_err().kind(), + ErrorKind::NotFound + ) } diff --git a/tests/run-make/windows-subsystem/Makefile b/tests/run-make/windows-subsystem/Makefile deleted file mode 100644 index e3cf9181de418..0000000000000 --- a/tests/run-make/windows-subsystem/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) windows.rs - $(RUSTC) console.rs diff --git a/tests/run-make/windows-subsystem/rmake.rs b/tests/run-make/windows-subsystem/rmake.rs new file mode 100644 index 0000000000000..8a6460f89339c --- /dev/null +++ b/tests/run-make/windows-subsystem/rmake.rs @@ -0,0 +1,8 @@ +//@ ignore-cross-compile + +use run_make_support::rustc; + +fn main() { + rustc().input("windows.rs").run(); + rustc().input("console.rs").run(); +} diff --git a/tests/run-make/issue-85441/empty.rs b/tests/run-make/windows-ws2_32/empty.rs similarity index 100% rename from tests/run-make/issue-85441/empty.rs rename to tests/run-make/windows-ws2_32/empty.rs diff --git a/tests/run-make/windows-ws2_32/rmake.rs b/tests/run-make/windows-ws2_32/rmake.rs new file mode 100644 index 0000000000000..4157e604330e4 --- /dev/null +++ b/tests/run-make/windows-ws2_32/rmake.rs @@ -0,0 +1,13 @@ +//@ only-msvc + +// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441 + +use run_make_support::{llvm_readobj, rustc, tmp_dir}; + +fn main() { + rustc().input("empty.rs").run(); + let empty = tmp_dir().join("empty.exe"); + let output = llvm_readobj().input(empty).coff_imports().run(); + let output = String::from_utf8(output.stdout).unwrap(); + assert!(!output.to_ascii_uppercase().contains("WS2_32.DLL")); +} From 57e68b689372256e564d1e64f0dc99f55d277096 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 27 May 2024 12:08:41 +0000 Subject: [PATCH 2/4] Remove Makefiles from allowed_run_make_makefiles --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 9a6ae18abeade..07537370bb60b 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -118,7 +118,6 @@ run-make/issue-83112-incr-test-moved-file/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile run-make/issue-85019-moved-src-dir/Makefile run-make/issue-85401-static-mir/Makefile -run-make/issue-85441/Makefile run-make/issue-88756-default-output/Makefile run-make/issue-97463-abi-param-passing/Makefile run-make/jobserver-error/Makefile @@ -278,8 +277,4 @@ run-make/volatile-intrinsics/Makefile run-make/wasm-exceptions-nostd/Makefile run-make/wasm-override-linker/Makefile run-make/weird-output-filenames/Makefile -run-make/windows-binary-no-external-deps/Makefile -run-make/windows-safeseh/Makefile -run-make/windows-spawn/Makefile -run-make/windows-subsystem/Makefile run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile From e081170b947a68abd2754990577dfd687d96e534 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 27 May 2024 13:43:46 +0000 Subject: [PATCH 3/4] Add linker option to run-make-support --- src/tools/run-make-support/src/rustc.rs | 6 ++++++ tests/run-make/windows-safeseh/rmake.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 1c83b630861cd..a617c189fb423 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -203,6 +203,12 @@ impl Rustc { self } + /// Specify the linker + pub fn linker(&mut self, linker: &str) -> &mut Self { + self.cmd.arg(format!("-Clinker={linker}")); + self + } + /// Get the [`Output`][::std::process::Output] of the finished process. #[track_caller] pub fn command_output(&mut self) -> ::std::process::Output { diff --git a/tests/run-make/windows-safeseh/rmake.rs b/tests/run-make/windows-safeseh/rmake.rs index 56d3ff4ea0d81..10e6b38aa8df1 100644 --- a/tests/run-make/windows-safeseh/rmake.rs +++ b/tests/run-make/windows-safeseh/rmake.rs @@ -6,10 +6,10 @@ use run_make_support::rustc; fn main() { // Ensure that LLD can link when an .rlib contains a synthetic object // file referencing exported or used symbols. - rustc().input("foo.rs").arg("-Clinker=rust-lld").run(); + rustc().input("foo.rs").linker("rust-lld").run(); // Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib. // Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware. rustc().input("baz.rs").run(); - rustc().input("bar.rs").arg("-Clinker=rust-lld").link_arg("/WHOLEARCHIVE:libbaz.rlib").run(); + rustc().input("bar.rs").linker("rust-lld").link_arg("/WHOLEARCHIVE:libbaz.rlib").run(); } From ad5dce55e620db3f992421debafe66194e5210c9 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 27 May 2024 13:46:41 +0000 Subject: [PATCH 4/4] Move run-make windows_subsystem tests to ui tests --- tests/run-make/windows-subsystem/rmake.rs | 8 -------- tests/{run-make => ui}/windows-subsystem/console.rs | 1 + .../{ => windows-subsystem}/windows-subsystem-invalid.rs | 0 .../windows-subsystem-invalid.stderr | 0 tests/{run-make => ui}/windows-subsystem/windows.rs | 1 + 5 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/windows-subsystem/rmake.rs rename tests/{run-make => ui}/windows-subsystem/console.rs (78%) rename tests/ui/{ => windows-subsystem}/windows-subsystem-invalid.rs (100%) rename tests/ui/{ => windows-subsystem}/windows-subsystem-invalid.stderr (100%) rename tests/{run-make => ui}/windows-subsystem/windows.rs (78%) diff --git a/tests/run-make/windows-subsystem/rmake.rs b/tests/run-make/windows-subsystem/rmake.rs deleted file mode 100644 index 8a6460f89339c..0000000000000 --- a/tests/run-make/windows-subsystem/rmake.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ ignore-cross-compile - -use run_make_support::rustc; - -fn main() { - rustc().input("windows.rs").run(); - rustc().input("console.rs").run(); -} diff --git a/tests/run-make/windows-subsystem/console.rs b/tests/ui/windows-subsystem/console.rs similarity index 78% rename from tests/run-make/windows-subsystem/console.rs rename to tests/ui/windows-subsystem/console.rs index 61a92eb6a9db7..8f0ca2de370de 100644 --- a/tests/run-make/windows-subsystem/console.rs +++ b/tests/ui/windows-subsystem/console.rs @@ -1,3 +1,4 @@ +//@ run-pass #![windows_subsystem = "console"] fn main() {} diff --git a/tests/ui/windows-subsystem-invalid.rs b/tests/ui/windows-subsystem/windows-subsystem-invalid.rs similarity index 100% rename from tests/ui/windows-subsystem-invalid.rs rename to tests/ui/windows-subsystem/windows-subsystem-invalid.rs diff --git a/tests/ui/windows-subsystem-invalid.stderr b/tests/ui/windows-subsystem/windows-subsystem-invalid.stderr similarity index 100% rename from tests/ui/windows-subsystem-invalid.stderr rename to tests/ui/windows-subsystem/windows-subsystem-invalid.stderr diff --git a/tests/run-make/windows-subsystem/windows.rs b/tests/ui/windows-subsystem/windows.rs similarity index 78% rename from tests/run-make/windows-subsystem/windows.rs rename to tests/ui/windows-subsystem/windows.rs index 1138248f07da0..65db0fec7a8b6 100644 --- a/tests/run-make/windows-subsystem/windows.rs +++ b/tests/ui/windows-subsystem/windows.rs @@ -1,3 +1,4 @@ +//@ run-pass #![windows_subsystem = "windows"] fn main() {}