From fa2b6122135ad18640e2e9b47450f50fa873c54a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 11:55:24 -0400 Subject: [PATCH 01/13] Rewrite link-args-order to rmake --- src/doc/book | 2 +- src/tools/cargo | 2 +- src/tools/run-make-support/src/rustc.rs | 24 ++++++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/Makefile | 10 ----- tests/run-make/link-args-order/rmake.rs | 39 +++++++++++++++++++ 6 files changed, 65 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/link-args-order/Makefile create mode 100644 tests/run-make/link-args-order/rmake.rs diff --git a/src/doc/book b/src/doc/book index 45c1a6d69edfd..5228bfac8267a 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e +Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc diff --git a/src/tools/cargo b/src/tools/cargo index a1f47ec3f7cd0..4dcbca118ab7f 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e +Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 331e1a5ab8b32..7e5a637e20e15 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -230,6 +230,24 @@ impl Rustc { self } + /// Add multiple extra arguments to the linker invocation, via `-Clink-args`. + pub fn link_args(&mut self, link_args: &str) -> &mut Self { + self.cmd.arg(format!("-Clink-args={link_args}")); + self + } + + /// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`. + pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self { + self.cmd.arg(format!("-Zpre-link-arg={link_arg}")); + self + } + + /// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`. + pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self { + self.cmd.arg(format!("-Zpre-link-args={link_args}")); + self + } + /// Specify a stdin input pub fn stdin>(&mut self, input: I) -> &mut Self { self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); @@ -248,4 +266,10 @@ impl Rustc { self.cmd.arg(format!("-Clinker={linker}")); self } + + /// Specify the linker flavor + pub fn linker_flavor(&mut self, linker_flavor: &str) -> &mut Self { + self.cmd.arg(format!("-Clinker-flavor={linker_flavor}")); + self + } } diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1596257747fa9..feb31e25e5f85 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -100,7 +100,6 @@ run-make/libtest-json/Makefile run-make/libtest-junit/Makefile run-make/libtest-padding/Makefile run-make/libtest-thread-limit/Makefile -run-make/link-args-order/Makefile run-make/link-cfg/Makefile run-make/link-framework/Makefile run-make/link-path-order/Makefile diff --git a/tests/run-make/link-args-order/Makefile b/tests/run-make/link-args-order/Makefile deleted file mode 100644 index c562cc1b396fa..0000000000000 --- a/tests/run-make/link-args-order/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# ignore-msvc - -include ../tools.mk - -RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args="d e" -C link-arg=f -RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f - -all: - $(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' - $(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs new file mode 100644 index 0000000000000..cd921a031292b --- /dev/null +++ b/tests/run-make/link-args-order/rmake.rs @@ -0,0 +1,39 @@ +// Passing linker arguments to the compiler used to be lost or reordered in a messy way +// as they were passed further to the linker. This was fixed in #70665, and this test +// checks that linker arguments remain intact and in the order they were originally passed in. +// See https://github.com/rust-lang/rust/pull/70665 + +use run_make_support::rustc; + +fn main() { + assert!( + String::from_utf8( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .link_arg("a") + .link_args("\"b c\"") + .link_args("\"d e\"") + .link_arg("f") + .run_fail() + .stderr + ) + .unwrap() + .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + ); + assert!( + String::from_utf8( + rustc() + .input("empty.rs") + .linker_flavor("ld") + .pre_link_arg("a") + .pre_link_args("\"b c\"") + .pre_link_args("\"d e\"") + .pre_link_arg("f") + .run_fail() + .stderr + ) + .unwrap() + .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") + ); +} From 594135ea370085bfd80ce56f7f08b146cb97f3ca Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 14:51:55 -0400 Subject: [PATCH 02/13] Rewrite ls-metadata to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/ls-metadata/Makefile | 8 -------- tests/run-make/ls-metadata/rmake.rs | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/ls-metadata/Makefile create mode 100644 tests/run-make/ls-metadata/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 feb31e25e5f85..57bb326ac954c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -108,7 +108,6 @@ run-make/llvm-ident/Makefile run-make/long-linker-command-lines-cmd-exe/Makefile run-make/long-linker-command-lines/Makefile run-make/longjmp-across-rust/Makefile -run-make/ls-metadata/Makefile run-make/lto-dylib-dep/Makefile run-make/lto-empty/Makefile run-make/lto-linkage-used-attr/Makefile diff --git a/tests/run-make/ls-metadata/Makefile b/tests/run-make/ls-metadata/Makefile deleted file mode 100644 index f03569baef7f2..0000000000000 --- a/tests/run-make/ls-metadata/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs - $(RUSTC) -Z ls=root $(TMPDIR)/foo - touch $(TMPDIR)/bar - $(RUSTC) -Z ls=root $(TMPDIR)/bar diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs new file mode 100644 index 0000000000000..61dcd3774a193 --- /dev/null +++ b/tests/run-make/ls-metadata/rmake.rs @@ -0,0 +1,17 @@ +// Passing invalid files to -Z ls (which lists the symbols +// defined by a library crate) used to cause a segmentation fault. +// As this was fixed in #11262, this test checks that no segfault +// occurs when passing the invalid file `bar` to -Z ls. +// See https://github.com/rust-lang/rust/issues/11259 + +//@ ignore-cross-compile + +use run_make_support::fs_wrapper; +use run_make_support::{rmake_out_path, rustc}; + +fn main() { + rustc().input("foo.rs"); + rustc().arg("-Zls=root").input(rmake_out_path("foo")); + fs_wrapper::create_file(rmake_out_path("bar")); + rustc().arg("-Zls=root").input(rmake_out_path("bar")); +} From 03a4259c8b925330d5425e61e7553351c21e55be Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 6 Jun 2024 15:20:42 -0400 Subject: [PATCH 03/13] Rewrite lto-readonly-lib to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/link-args-order/rmake.rs | 48 +++++++------------ tests/run-make/ls-metadata/rmake.rs | 10 ++-- tests/run-make/lto-readonly-lib/Makefile | 13 ----- tests/run-make/lto-readonly-lib/rmake.rs | 25 ++++++++++ 5 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/lto-readonly-lib/Makefile create mode 100644 tests/run-make/lto-readonly-lib/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 57bb326ac954c..0fdc6de0b644e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -112,7 +112,6 @@ run-make/lto-dylib-dep/Makefile run-make/lto-empty/Makefile run-make/lto-linkage-used-attr/Makefile run-make/lto-no-link-whole-rlib/Makefile -run-make/lto-readonly-lib/Makefile run-make/lto-smoke-c/Makefile run-make/macos-deployment-target/Makefile run-make/macos-fat-archive/Makefile diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index cd921a031292b..4530251c7a585 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -6,34 +6,22 @@ use run_make_support::rustc; fn main() { - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .link_arg("a") - .link_args("\"b c\"") - .link_args("\"d e\"") - .link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") - ); - assert!( - String::from_utf8( - rustc() - .input("empty.rs") - .linker_flavor("ld") - .pre_link_arg("a") - .pre_link_args("\"b c\"") - .pre_link_args("\"d e\"") - .pre_link_arg("f") - .run_fail() - .stderr - ) - .unwrap() - .contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\"") - ); + rustc() + .input("empty.rs") + .linker_flavor("ld") + .link_arg("a") + .link_args("\"b c\"") + .link_args("\"d e\"") + .link_arg("f") + .run_fail() + .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + rustc() + .input("empty.rs") + .linker_flavor("ld") + .pre_link_arg("a") + .pre_link_args("\"b c\"") + .pre_link_args("\"d e\"") + .pre_link_arg("f") + .run_fail() + .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); } diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs index 61dcd3774a193..0e60f2c46787a 100644 --- a/tests/run-make/ls-metadata/rmake.rs +++ b/tests/run-make/ls-metadata/rmake.rs @@ -7,11 +7,11 @@ //@ ignore-cross-compile use run_make_support::fs_wrapper; -use run_make_support::{rmake_out_path, rustc}; +use run_make_support::rustc; fn main() { - rustc().input("foo.rs"); - rustc().arg("-Zls=root").input(rmake_out_path("foo")); - fs_wrapper::create_file(rmake_out_path("bar")); - rustc().arg("-Zls=root").input(rmake_out_path("bar")); + rustc().input("foo.rs").run(); + rustc().arg("-Zls=root").input("foo").run(); + fs_wrapper::create_file("bar"); + rustc().arg("-Zls=root").input("bar").run(); } diff --git a/tests/run-make/lto-readonly-lib/Makefile b/tests/run-make/lto-readonly-lib/Makefile deleted file mode 100644 index 11d944e3e3d4b..0000000000000 --- a/tests/run-make/lto-readonly-lib/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) lib.rs - - # the compiler needs to copy and modify the rlib file when performing - # LTO, so we should ensure that it can cope with the original rlib - # being read-only. - chmod 444 $(TMPDIR)/*.rlib - - $(RUSTC) main.rs -C lto - $(call RUN,main) diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs new file mode 100644 index 0000000000000..bf1dafee697dc --- /dev/null +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -0,0 +1,25 @@ +// When the compiler is performing link time optimization, it will +// need to copy the original rlib file, set the copy's permissions to read/write, +// and modify that copy - even if the original +// file is read-only. This test creates a read-only rlib, and checks that +// compilation with LTO succeeds. +// See https://github.com/rust-lang/rust/pull/17619 + +//@ ignore-cross-compile + +use run_make_support::fs_wrapper; +use run_make_support::{cwd, run, rustc}; + +fn main() { + rustc().input("lib.rs").run(); + let entries = fs_wrapper::read_dir(cwd()); + for entry in entries { + if entry.path().extension().and_then(|s| s.to_str()) == Some("rlib") { + let mut perms = fs_wrapper::metadata(entry.path()).permissions(); + perms.set_readonly(true); + fs_wrapper::set_permissions(entry.path(), perms); + } + } + rustc().input("main.rs").arg("-Clto").run(); + run("main"); +} From 62431b73e00eaae0788b53f4ccf6cecb9f7f03ca Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Jun 2024 15:13:40 +0200 Subject: [PATCH 04/13] Migrate `run-make/compressed-debuginfo` to `rmake.rs` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/compressed-debuginfo/Makefile | 14 -------- tests/run-make/compressed-debuginfo/rmake.rs | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) delete mode 100644 tests/run-make/compressed-debuginfo/Makefile create mode 100644 tests/run-make/compressed-debuginfo/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 24e51b8fee519..61303669ee41d 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -15,7 +15,6 @@ run-make/comment-section/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile -run-make/compressed-debuginfo/Makefile run-make/crate-hash-rustc-version/Makefile run-make/crate-name-priority/Makefile run-make/cross-lang-lto-clang/Makefile diff --git a/tests/run-make/compressed-debuginfo/Makefile b/tests/run-make/compressed-debuginfo/Makefile deleted file mode 100644 index d2f24dde00d7b..0000000000000 --- a/tests/run-make/compressed-debuginfo/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# only-linux -# -# This tests debuginfo-compression. - -all: zlib zstandard - -zlib: - test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zlib foo.rs 2>&1 | sed 's/.*unknown.*zlib.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZLIB - -zstandard: - test "`$(RUSTC) --crate-name=foo --crate-type=lib --emit=obj -C debuginfo=full -Z debuginfo-compression=zstd foo.rs 2>&1 | sed 's/.*unknown.*zstd.*/missing/' | head -n 1`" = missing || readelf -t $(TMPDIR)/foo.o | grep -q ZST diff --git a/tests/run-make/compressed-debuginfo/rmake.rs b/tests/run-make/compressed-debuginfo/rmake.rs new file mode 100644 index 0000000000000..9c6d50ab243cd --- /dev/null +++ b/tests/run-make/compressed-debuginfo/rmake.rs @@ -0,0 +1,36 @@ +// Checks the `debuginfo-compression` option. + +//@ only-linux +//@ ignore-cross-compile + +// FIXME: This test isn't comprehensive and isn't covering all possible combinations. + +use run_make_support::{assert_contains, cmd, run_in_tmpdir, rustc}; + +fn check_compression(compression: &str, to_find: &str) { + run_in_tmpdir(|| { + let out = rustc() + .crate_name("foo") + .crate_type("lib") + .emit("obj") + .arg("-Cdebuginfo=full") + .arg(&format!("-Zdebuginfo-compression={compression}")) + .input("foo.rs") + .run(); + let stderr = out.stderr_utf8(); + if stderr.is_empty() { + // FIXME: `readelf` might need to be replaced with `llvm-readelf`. + cmd("readelf").arg("-t").arg("foo.o").run().assert_stdout_contains(to_find); + } else { + assert_contains( + &stderr, + &format!("unknown debuginfo compression algorithm {compression}"), + ); + } + }); +} + +fn main() { + check_compression("zlib", "ZLIB"); + check_compression("zstd", "ZSTD"); +} From 060a13e9fd56b1d186ea016070e390067b9e893d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 15:59:33 -0400 Subject: [PATCH 05/13] rewrite extern-flag-rename-transitive to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../extern-flag-rename-transitive/Makefile | 7 ------- .../extern-flag-rename-transitive/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/extern-flag-rename-transitive/Makefile create mode 100644 tests/run-make/extern-flag-rename-transitive/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 1596257747fa9..6f57cb717ace8 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -40,7 +40,6 @@ run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile run-make/extern-flag-pathless/Makefile -run-make/extern-flag-rename-transitive/Makefile run-make/extern-fn-explicit-align/Makefile run-make/extern-fn-generic/Makefile run-make/extern-fn-mangle/Makefile diff --git a/tests/run-make/extern-flag-rename-transitive/Makefile b/tests/run-make/extern-flag-rename-transitive/Makefile deleted file mode 100644 index d16a8e20868ef..0000000000000 --- a/tests/run-make/extern-flag-rename-transitive/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) foo.rs - $(RUSTC) bar.rs - $(RUSTC) baz.rs --extern a=$(TMPDIR)/libfoo.rlib - diff --git a/tests/run-make/extern-flag-rename-transitive/rmake.rs b/tests/run-make/extern-flag-rename-transitive/rmake.rs new file mode 100644 index 0000000000000..0090d487f03d6 --- /dev/null +++ b/tests/run-make/extern-flag-rename-transitive/rmake.rs @@ -0,0 +1,14 @@ +// In this test, baz.rs is looking for an extern crate "a" which +// does not exist, and can only run through the --extern rustc flag +// defining that the "a" crate is in fact just "foo". This test +// checks that the --extern flag takes precedence over the extern +// crate statement in the code. +// See https://github.com/rust-lang/rust/pull/52723 + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("foo.rs").run(); + rustc().input("bar.rs").run(); + rustc().input("baz.rs").extern_("a", rust_lib_name("foo")).run(); +} From 9e2ace85f9d2a9fd24af197f2da81eb3a5db51b9 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:05:56 -0400 Subject: [PATCH 06/13] rewrite debugger-visualizer-dep-info to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/debugger-visualizer-dep-info/Makefile | 9 --------- tests/run-make/debugger-visualizer-dep-info/rmake.rs | 11 +++++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 tests/run-make/debugger-visualizer-dep-info/Makefile create mode 100644 tests/run-make/debugger-visualizer-dep-info/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 6f57cb717ace8..4091cbbbcb89c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -23,7 +23,6 @@ run-make/cross-lang-lto-pgo-smoketest/Makefile run-make/cross-lang-lto-upstream-rlibs/Makefile run-make/cross-lang-lto/Makefile run-make/debug-assertions/Makefile -run-make/debugger-visualizer-dep-info/Makefile run-make/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile diff --git a/tests/run-make/debugger-visualizer-dep-info/Makefile b/tests/run-make/debugger-visualizer-dep-info/Makefile deleted file mode 100644 index 0877998a74fe7..0000000000000 --- a/tests/run-make/debugger-visualizer-dep-info/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# This test makes sure that files referenced via #[debugger_visualizer] are -# included in `--emit dep-info` output. - -all: - $(RUSTC) --emit dep-info main.rs - $(CGREP) "foo.py" < $(TMPDIR)/main.d - $(CGREP) "my_visualizers/bar.natvis" < $(TMPDIR)/main.d diff --git a/tests/run-make/debugger-visualizer-dep-info/rmake.rs b/tests/run-make/debugger-visualizer-dep-info/rmake.rs new file mode 100644 index 0000000000000..65ffb2373e7c4 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/rmake.rs @@ -0,0 +1,11 @@ +// This test checks that files referenced via #[debugger_visualizer] are +// included in `--emit dep-info` output. +// See https://github.com/rust-lang/rust/pull/111641 + +use run_make_support::{invalid_utf8_contains, rustc}; + +fn main() { + rustc().emit("dep-info").input("main.rs").run(); + invalid_utf8_contains("main.d", "foo.py"); + invalid_utf8_contains("main.d", "my_visualizers/bar.natvis"); +} From dff354e57fe030f8fa0467f092b75e8979a3cce9 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:20:32 -0400 Subject: [PATCH 07/13] rewrite metadata-flag-frobs-symbols to rmake --- src/tools/run-make-support/src/rustc.rs | 6 ++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../metadata-flag-frobs-symbols/Makefile | 11 ---------- .../metadata-flag-frobs-symbols/rmake.rs | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 tests/run-make/metadata-flag-frobs-symbols/Makefile create mode 100644 tests/run-make/metadata-flag-frobs-symbols/rmake.rs diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 331e1a5ab8b32..125f4b4bd6291 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -73,6 +73,12 @@ impl Rustc { self } + /// Incorporate a hashed string to mangled symbols. + pub fn metadata(&mut self, meta: &str) -> &mut Self { + self.cmd.arg(format!("-Cmetadata={meta}")); + self + } + /// Add a suffix in each output filename. pub fn extra_filename(&mut self, suffix: &str) -> &mut Self { self.cmd.arg(format!("-Cextra-filename={suffix}")); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 4091cbbbcb89c..691248ea260b6 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -119,7 +119,6 @@ run-make/macos-fat-archive/Makefile run-make/manual-link/Makefile run-make/many-crates-but-no-match/Makefile run-make/metadata-dep-info/Makefile -run-make/metadata-flag-frobs-symbols/Makefile run-make/min-global-align/Makefile run-make/mingw-export-call-convention/Makefile run-make/mismatching-target-triples/Makefile diff --git a/tests/run-make/metadata-flag-frobs-symbols/Makefile b/tests/run-make/metadata-flag-frobs-symbols/Makefile deleted file mode 100644 index 53d7d0657695f..0000000000000 --- a/tests/run-make/metadata-flag-frobs-symbols/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) foo.rs -C metadata=a -C extra-filename=-a - $(RUSTC) foo.rs -C metadata=b -C extra-filename=-b - $(RUSTC) bar.rs \ - --extern foo1=$(TMPDIR)/libfoo-a.rlib \ - --extern foo2=$(TMPDIR)/libfoo-b.rlib \ - --print link-args - $(call RUN,bar) diff --git a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs new file mode 100644 index 0000000000000..12c07f9e3aeec --- /dev/null +++ b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs @@ -0,0 +1,21 @@ +// In this test, foo.rs is compiled twice with different hashes tied to its +// symbols thanks to the metadata flag. bar.rs then ensures that the memory locations +// of foo's symbols are different even though they came from the same original source code. +// This checks that the metadata flag is doing its job. +// See https://github.com/rust-lang/rust/issues/14471 + +//@ ignore-cross-compile + +use run_make_support::{run, rust_lib_name, rustc}; + +fn main() { + rustc().input("foo.rs").metadata("a").extra_filename("-a").run(); + rustc().input("foo.rs").metadata("b").extra_filename("-b").run(); + rustc() + .input("bar.rs") + .extern_("foo1", rust_lib_name("foo-a")) + .extern_("foo2", rust_lib_name("foo-b")) + .print("link-args") + .run(); + run("bar"); +} From d1e8c6bc7e93b6649e9dab0604dcc591dde03af0 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:30:26 -0400 Subject: [PATCH 08/13] rewrite extern-overrides-distribution to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../extern-overrides-distribution/Makefile | 6 ------ .../extern-overrides-distribution/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) delete mode 100644 tests/run-make/extern-overrides-distribution/Makefile create mode 100644 tests/run-make/extern-overrides-distribution/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 691248ea260b6..8eee16e87a88e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -49,7 +49,6 @@ run-make/extern-fn-with-packed-struct/Makefile run-make/extern-fn-with-union/Makefile run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile -run-make/extern-overrides-distribution/Makefile run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile run-make/forced-unwind-terminate-pof/Makefile diff --git a/tests/run-make/extern-overrides-distribution/Makefile b/tests/run-make/extern-overrides-distribution/Makefile deleted file mode 100644 index bfd0dd6991ba7..0000000000000 --- a/tests/run-make/extern-overrides-distribution/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) libc.rs -Cmetadata=foo - $(RUSTC) main.rs --extern libc=$(TMPDIR)/liblibc.rlib diff --git a/tests/run-make/extern-overrides-distribution/rmake.rs b/tests/run-make/extern-overrides-distribution/rmake.rs new file mode 100644 index 0000000000000..bd2553d4134a4 --- /dev/null +++ b/tests/run-make/extern-overrides-distribution/rmake.rs @@ -0,0 +1,14 @@ +// The --extern flag should override any "crate_type" declarations in the +// Rust files themselves. In this test, libc is compiled as "lib", but +// main.rs will only run with an rlib, which checks if the --extern flag +// is successfully overriding the default behaviour. +// See https://github.com/rust-lang/rust/pull/21782 + +//@ ignore-cross-compile + +use run_make_support::{rust_lib_name, rustc}; + +fn main() { + rustc().input("libc.rs").metadata("foo").run(); + rustc().input("main.rs").extern_("libc", rust_lib_name("libc")).run(); +} From b3c51323b507192521cfa264a6ab129fcdb85b34 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 9 Jun 2024 16:43:24 -0400 Subject: [PATCH 09/13] make assert_stderr_contains print its contents on panic --- src/doc/book | 2 +- src/tools/cargo | 2 +- src/tools/run-make-support/src/rustc.rs | 12 ------------ tests/run-make/link-args-order/rmake.rs | 19 +++++++++++-------- tests/run-make/lto-readonly-lib/rmake.rs | 16 +++++----------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/doc/book b/src/doc/book index 5228bfac8267a..45c1a6d69edfd 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 5228bfac8267ad24659a81b92ec5417976b5edbc +Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e diff --git a/src/tools/cargo b/src/tools/cargo index 4dcbca118ab7f..a1f47ec3f7cd0 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 4dcbca118ab7f9ffac4728004c983754bc6a04ff +Subproject commit a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726e diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 7e5a637e20e15..289d847a5728c 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -236,18 +236,6 @@ impl Rustc { self } - /// Add an extra argument to prepend the linker invocation, via `-Zpre-link-arg`. - pub fn pre_link_arg(&mut self, link_arg: &str) -> &mut Self { - self.cmd.arg(format!("-Zpre-link-arg={link_arg}")); - self - } - - /// Add multiple extra arguments to the linker invocation, via `-Zpre-link-args`. - pub fn pre_link_args(&mut self, link_args: &str) -> &mut Self { - self.cmd.arg(format!("-Zpre-link-args={link_args}")); - self - } - /// Specify a stdin input pub fn stdin>(&mut self, input: I) -> &mut Self { self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); diff --git a/tests/run-make/link-args-order/rmake.rs b/tests/run-make/link-args-order/rmake.rs index 4530251c7a585..d238ad23f27c7 100644 --- a/tests/run-make/link-args-order/rmake.rs +++ b/tests/run-make/link-args-order/rmake.rs @@ -3,6 +3,9 @@ // checks that linker arguments remain intact and in the order they were originally passed in. // See https://github.com/rust-lang/rust/pull/70665 +//@ ignore-msvc +// Reason: the ld linker does not exist on Windows. + use run_make_support::rustc; fn main() { @@ -10,18 +13,18 @@ fn main() { .input("empty.rs") .linker_flavor("ld") .link_arg("a") - .link_args("\"b c\"") - .link_args("\"d e\"") + .link_args("b c") + .link_args("d e") .link_arg("f") .run_fail() - .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + .assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#); rustc() .input("empty.rs") .linker_flavor("ld") - .pre_link_arg("a") - .pre_link_args("\"b c\"") - .pre_link_args("\"d e\"") - .pre_link_arg("f") + .arg("-Zpre-link-arg=a") + .arg("-Zpre-link-args=b c") + .arg("-Zpre-link-args=d e") + .arg("-Zpre-link-arg=f") .run_fail() - .assert_stderr_contains("\"a\" \"b\" \"c\" \"d\" \"e\" \"f\""); + .assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#); } diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs index bf1dafee697dc..9eb135addd9ec 100644 --- a/tests/run-make/lto-readonly-lib/rmake.rs +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -8,18 +8,12 @@ //@ ignore-cross-compile use run_make_support::fs_wrapper; -use run_make_support::{cwd, run, rustc}; +use run_make_support::{run, rust_lib_name, rustc, test_while_readonly}; fn main() { rustc().input("lib.rs").run(); - let entries = fs_wrapper::read_dir(cwd()); - for entry in entries { - if entry.path().extension().and_then(|s| s.to_str()) == Some("rlib") { - let mut perms = fs_wrapper::metadata(entry.path()).permissions(); - perms.set_readonly(true); - fs_wrapper::set_permissions(entry.path(), perms); - } - } - rustc().input("main.rs").arg("-Clto").run(); - run("main"); + test_while_readonly(rust_lib_name("lib"), || { + rustc().input("main.rs").arg("-Clto").run(); + run("main"); + }); } From e7ea063622d4a150fb22030b78d21b18f4855481 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 18 Jun 2024 16:43:52 -0400 Subject: [PATCH 10/13] rewrite forced-unwind-terminate-pof to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../forced-unwind-terminate-pof/Makefile | 9 --------- .../forced-unwind-terminate-pof/rmake.rs | 16 ++++++++++++++++ .../metadata-flag-frobs-symbols/rmake.rs | 1 - 4 files changed, 16 insertions(+), 11 deletions(-) delete mode 100644 tests/run-make/forced-unwind-terminate-pof/Makefile create mode 100644 tests/run-make/forced-unwind-terminate-pof/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 8eee16e87a88e..a5ccb1b784247 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -51,7 +51,6 @@ run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile -run-make/forced-unwind-terminate-pof/Makefile run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile run-make/foreign-rust-exceptions/Makefile diff --git a/tests/run-make/forced-unwind-terminate-pof/Makefile b/tests/run-make/forced-unwind-terminate-pof/Makefile deleted file mode 100644 index 871621520b910..0000000000000 --- a/tests/run-make/forced-unwind-terminate-pof/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# ignore-cross-compile -# only-linux -include ../tools.mk - -all: foo - $(call RUN,foo) | $(CGREP) -v "cannot unwind" - -foo: foo.rs - $(RUSTC) $< diff --git a/tests/run-make/forced-unwind-terminate-pof/rmake.rs b/tests/run-make/forced-unwind-terminate-pof/rmake.rs new file mode 100644 index 0000000000000..320ddb172b6ec --- /dev/null +++ b/tests/run-make/forced-unwind-terminate-pof/rmake.rs @@ -0,0 +1,16 @@ +// During a forced unwind, crossing the non-Plain Old Frame +// would define the forced unwind as undefined behaviour, and +// immediately abort the unwinding process. This test checks +// that the forced unwinding takes precedence. +// See https://github.com/rust-lang/rust/issues/101469 + +//@ ignore-cross-compile +//@ ignore-windows +//Reason: pthread (POSIX threads) is not available on Windows + +use run_make_support::{run, rustc}; + +fn main() { + rustc().input("foo.rs").run(); + run("foo").assert_stdout_not_contains("cannot unwind"); +} diff --git a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs index 12c07f9e3aeec..938886957fb9a 100644 --- a/tests/run-make/metadata-flag-frobs-symbols/rmake.rs +++ b/tests/run-make/metadata-flag-frobs-symbols/rmake.rs @@ -15,7 +15,6 @@ fn main() { .input("bar.rs") .extern_("foo1", rust_lib_name("foo-a")) .extern_("foo2", rust_lib_name("foo-b")) - .print("link-args") .run(); run("bar"); } From 1e42bb606d9abcfa22ee248e3a8598f813632418 Mon Sep 17 00:00:00 2001 From: bohan Date: Thu, 20 Jun 2024 19:44:36 +0800 Subject: [PATCH 11/13] collect attrs in const block expr --- compiler/rustc_resolve/src/def_collector.rs | 3 +++ tests/ui/resolve/path-attr-in-const-block.rs | 9 +++++++++ tests/ui/resolve/path-attr-in-const-block.stderr | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/ui/resolve/path-attr-in-const-block.rs create mode 100644 tests/ui/resolve/path-attr-in-const-block.stderr diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index fb6e55f2b7bdf..60789c083133f 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -343,6 +343,9 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> { self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span) } ExprKind::ConstBlock(ref constant) => { + for attr in &expr.attrs { + visit::walk_attribute(self, attr); + } let def = self.create_def( constant.id, kw::Empty, diff --git a/tests/ui/resolve/path-attr-in-const-block.rs b/tests/ui/resolve/path-attr-in-const-block.rs new file mode 100644 index 0000000000000..076511d26d6d3 --- /dev/null +++ b/tests/ui/resolve/path-attr-in-const-block.rs @@ -0,0 +1,9 @@ +// issue#126516 +// issue#126647 + +fn main() { + const { + #![path = foo!()] + //~^ ERROR: cannot find macro `foo` in this scope + } +} diff --git a/tests/ui/resolve/path-attr-in-const-block.stderr b/tests/ui/resolve/path-attr-in-const-block.stderr new file mode 100644 index 0000000000000..8f9e58157c809 --- /dev/null +++ b/tests/ui/resolve/path-attr-in-const-block.stderr @@ -0,0 +1,8 @@ +error: cannot find macro `foo` in this scope + --> $DIR/path-attr-in-const-block.rs:6:19 + | +LL | #![path = foo!()] + | ^^^ + +error: aborting due to 1 previous error + From d3091df79b92eff2648e2b1537f22c6f834aecf0 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 20 Jun 2024 15:15:48 +0000 Subject: [PATCH 12/13] Remove `feature(const_closures)` from libcore --- library/core/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index a533a7938f13b..94ad8fbd5df07 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -209,7 +209,6 @@ #![feature(cfg_sanitize)] #![feature(cfg_target_has_atomic)] #![feature(cfg_target_has_atomic_equal_alignment)] -#![feature(const_closures)] #![feature(const_fn_floating_point_arithmetic)] #![feature(const_for)] #![feature(const_mut_refs)] From f42fa4f6e006d0d9eb90c7b10a9698dffb104174 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 20 Jun 2024 17:42:40 +0200 Subject: [PATCH 13/13] add `needs-unwind` to UI test the `tail-expr-lock-poisoning` UI test uses the `panic::catch_unwind` API so it relies on unwinding being implemented. this test ought not to run on targets that do not support unwinding. add the `needs-unwind` attribute to signal this --- tests/ui/lifetimes/tail-expr-lock-poisoning.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/lifetimes/tail-expr-lock-poisoning.rs b/tests/ui/lifetimes/tail-expr-lock-poisoning.rs index 69b8f286d774f..cdfd35304b44e 100644 --- a/tests/ui/lifetimes/tail-expr-lock-poisoning.rs +++ b/tests/ui/lifetimes/tail-expr-lock-poisoning.rs @@ -3,6 +3,7 @@ //@ [edition2024] compile-flags: -Zunstable-options //@ [edition2024] edition: 2024 //@ run-pass +//@ needs-unwind #![cfg_attr(edition2024, feature(shorter_tail_lifetimes))] use std::sync::Mutex;