From acb6078d9183c41e39495ff075cd01b3d68fe967 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 20 Jun 2024 11:21:56 -0400 Subject: [PATCH 1/4] rewrite remap-path-prefix to rmake --- src/tools/run-make-support/src/rustc.rs | 11 +++++ tests/run-make/remap-path-prefix/Makefile | 30 ------------ tests/run-make/remap-path-prefix/rmake.rs | 58 +++++++++++++++++++++++ 3 files changed, 69 insertions(+), 30 deletions(-) delete mode 100644 tests/run-make/remap-path-prefix/Makefile create mode 100644 tests/run-make/remap-path-prefix/rmake.rs diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 28ece1dff128d..df843d74fc927 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -106,6 +106,17 @@ impl Rustc { self } + /// Remap source path prefixes in all output. + pub fn remap_path_prefix>(&mut self, from: P, to: P) -> &mut Self { + let from = from.as_ref().to_string_lossy(); + let to = to.as_ref().to_string_lossy(); + + self.cmd.arg("--remap-path-prefix"); + self.cmd.arg(format!("{from}={to}")); + + self + } + /// Specify path to the input file. pub fn input>(&mut self, path: P) -> &mut Self { self.cmd.arg(path.as_ref()); diff --git a/tests/run-make/remap-path-prefix/Makefile b/tests/run-make/remap-path-prefix/Makefile deleted file mode 100644 index 02423dea7d26c..0000000000000 --- a/tests/run-make/remap-path-prefix/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -include ../tools.mk - -# ignore-windows - -ifeq ($(UNAME),Darwin) - DEBUGINFOOPTS := -Csplit-debuginfo=off -else - DEBUGINFOOPTS := -endif - -all: remap remap-with-scope - -# Checks if remapping works if the remap-from string contains path to the working directory plus more -remap: - $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs - grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 - ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 - -remap-with-scope: - $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs - grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 - ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 - - $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=macro $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs - grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 - ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 - - $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs - grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 - ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs new file mode 100644 index 0000000000000..4d98dcf6131cd --- /dev/null +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -0,0 +1,58 @@ +// Generating metadata alongside remap-path-prefix would fail to actually remap the path +// in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being +// successfully remapped to "/the/aux" in the rmeta files. +// See https://github.com/rust-lang/rust/pull/85344 + +// FIXME(Oneirical): check if works without ignore-windows + +use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc}; + +fn main() { + let mut out_simple = rustc(); + let mut out_object = rustc(); + let mut out_macro = rustc(); + let mut out_diagobj = rustc(); + out_simple + .remap_path_prefix("auxiliary", "/the/aux") + .crate_type("lib") + .emit("metadata") + .input("auxiliary/lib.rs"); + out_object + .remap_path_prefix("auxiliary", "/the/aux") + .crate_type("lib") + .emit("metadata") + .input("auxiliary/lib.rs"); + out_macro + .remap_path_prefix("auxiliary", "/the/aux") + .crate_type("lib") + .emit("metadata") + .input("auxiliary/lib.rs"); + out_diagobj + .remap_path_prefix("auxiliary", "/the/aux") + .crate_type("lib") + .emit("metadata") + .input("auxiliary/lib.rs"); + + out_simple.run(); + invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); + invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + + out_object.arg("-Zremap-path-scope=object"); + out_macro.arg("-Zremap-path-scope=macro"); + out_diagobj.arg("-Zremap-path-scope=diagnostics,object"); + if is_darwin() { + out_object.arg("-Csplit-debuginfo=off"); + out_macro.arg("-Csplit-debuginfo=off"); + out_diagobj.arg("-Csplit-debuginfo=off"); + } + + out_object.run(); + invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); + invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + out_macro.run(); + invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); + invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + out_diagobj.run(); + invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); + invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); +} From cb1281b76d4d90fd66bd76507e583c69625e037d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 21 Jun 2024 13:35:47 -0400 Subject: [PATCH 2/4] rewrite debug-assertions to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/debug-assertions/Makefile | 27 -------------- tests/run-make/debug-assertions/debug.rs | 9 ++--- tests/run-make/debug-assertions/rmake.rs | 37 +++++++++++++++++++ 4 files changed, 40 insertions(+), 34 deletions(-) delete mode 100644 tests/run-make/debug-assertions/Makefile create mode 100644 tests/run-make/debug-assertions/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 2bc3acc58cb22..6199dce7d9830 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -18,7 +18,6 @@ run-make/cross-lang-lto-clang/Makefile 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/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile diff --git a/tests/run-make/debug-assertions/Makefile b/tests/run-make/debug-assertions/Makefile deleted file mode 100644 index 4501459e9d1d8..0000000000000 --- a/tests/run-make/debug-assertions/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# ignore-cross-compile -# needs-unwind -include ../tools.mk - -all: - $(RUSTC) debug.rs -C debug-assertions=no - $(call RUN,debug) good - $(RUSTC) debug.rs -C opt-level=0 - $(call RUN,debug) bad - $(RUSTC) debug.rs -C opt-level=1 - $(call RUN,debug) good - $(RUSTC) debug.rs -C opt-level=2 - $(call RUN,debug) good - $(RUSTC) debug.rs -C opt-level=3 - $(call RUN,debug) good - $(RUSTC) debug.rs -C opt-level=s - $(call RUN,debug) good - $(RUSTC) debug.rs -C opt-level=z - $(call RUN,debug) good - $(RUSTC) debug.rs -O - $(call RUN,debug) good - $(RUSTC) debug.rs - $(call RUN,debug) bad - $(RUSTC) debug.rs -C debug-assertions=yes -O - $(call RUN,debug) bad - $(RUSTC) debug.rs -C debug-assertions=yes -C opt-level=1 - $(call RUN,debug) bad diff --git a/tests/run-make/debug-assertions/debug.rs b/tests/run-make/debug-assertions/debug.rs index 9eebf60ded09b..c6e4bddc34c75 100644 --- a/tests/run-make/debug-assertions/debug.rs +++ b/tests/run-make/debug-assertions/debug.rs @@ -1,15 +1,12 @@ #![feature(rustc_attrs)] #![deny(warnings)] -use std::env; use std::thread; fn main() { - let should_fail = env::args().nth(1) == Some("bad".to_string()); - - assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail); - assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail); - assert_eq!(thread::spawn(overflow).join().is_err(), should_fail); + assert!(thread::spawn(debug_assert_eq).join().is_ok()); + assert!(thread::spawn(debug_assert).join().is_ok()); + assert!(thread::spawn(overflow).join().is_ok()); } fn debug_assert_eq() { diff --git a/tests/run-make/debug-assertions/rmake.rs b/tests/run-make/debug-assertions/rmake.rs new file mode 100644 index 0000000000000..ba8be9488a8d8 --- /dev/null +++ b/tests/run-make/debug-assertions/rmake.rs @@ -0,0 +1,37 @@ +// debug.rs contains some "debug assertion" statements which +// should only be enabled in either non-optimized builds or when +// `-C debug-assertions` is set to yes. These debug assertions +// are guaranteed to fail, so this test checks that the run command +// fails where debug assertions should be activated, and succeeds where +// debug assertions should be disabled. +// See https://github.com/rust-lang/rust/pull/22980 + +//@ ignore-cross-compile +//@ needs-unwind + +use run_make_support::{run, run_fail, rustc}; + +fn main() { + rustc().input("debug.rs").arg("-Cdebug-assertions=no").run(); + run("debug"); + rustc().input("debug.rs").opt_level("0").run(); + run_fail("debug"); + rustc().input("debug.rs").opt_level("1").run(); + run("debug"); + rustc().input("debug.rs").opt_level("2").run(); + run("debug"); + rustc().input("debug.rs").opt_level("3").run(); + run("debug"); + rustc().input("debug.rs").opt_level("s").run(); + run("debug"); + rustc().input("debug.rs").opt_level("z").run(); + run("debug"); + rustc().input("debug.rs").opt().run(); + run("debug"); + rustc().input("debug.rs").run(); + run_fail("debug"); + rustc().input("debug.rs").opt().arg("-Cdebug-assertions=yes").run(); + run_fail("debug"); + rustc().input("debug.rs").opt_level("1").arg("-Cdebug-assertions=yes").run(); + run_fail("debug"); +} From 133b47ab3837baf7d1a7f9f03a7166c137667797 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 21 Jun 2024 15:05:54 -0400 Subject: [PATCH 3/4] rewrite emit-stack-sizes to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 2 -- tests/run-make/debug-assertions/debug.rs | 1 + tests/run-make/emit-stack-sizes/Makefile | 12 ---------- tests/run-make/emit-stack-sizes/rmake.rs | 23 +++++++++++++++++++ 4 files changed, 24 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/emit-stack-sizes/Makefile create mode 100644 tests/run-make/emit-stack-sizes/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 6199dce7d9830..f6c091ee4129e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -26,7 +26,6 @@ run-make/dump-mono-stats/Makefile run-make/dylib-chain/Makefile run-make/emit-path-unhashed/Makefile run-make/emit-shared-files/Makefile -run-make/emit-stack-sizes/Makefile run-make/emit-to-stdout/Makefile run-make/env-dep-info/Makefile run-make/export-executable-symbols/Makefile @@ -147,7 +146,6 @@ run-make/raw-dylib-link-ordinal/Makefile run-make/raw-dylib-stdcall-ordinal/Makefile run-make/redundant-libs/Makefile run-make/remap-path-prefix-dwarf/Makefile -run-make/remap-path-prefix/Makefile run-make/reproducible-build-2/Makefile run-make/reproducible-build/Makefile run-make/return-non-c-like-enum-from-c/Makefile diff --git a/tests/run-make/debug-assertions/debug.rs b/tests/run-make/debug-assertions/debug.rs index c6e4bddc34c75..1f27c04a16d45 100644 --- a/tests/run-make/debug-assertions/debug.rs +++ b/tests/run-make/debug-assertions/debug.rs @@ -1,3 +1,4 @@ +#![allow(internal_features)] #![feature(rustc_attrs)] #![deny(warnings)] diff --git a/tests/run-make/emit-stack-sizes/Makefile b/tests/run-make/emit-stack-sizes/Makefile deleted file mode 100644 index b546fcba5121e..0000000000000 --- a/tests/run-make/emit-stack-sizes/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# ignore-windows -# ignore-apple -# -# This feature only works when the output object format is ELF so we ignore -# Apple and Windows - -# check that the .stack_sizes section is generated -all: - $(RUSTC) -C opt-level=3 -Z emit-stack-sizes --emit=obj foo.rs - size -A $(TMPDIR)/foo.o | $(CGREP) .stack_sizes diff --git a/tests/run-make/emit-stack-sizes/rmake.rs b/tests/run-make/emit-stack-sizes/rmake.rs new file mode 100644 index 0000000000000..53cc9ee5943f8 --- /dev/null +++ b/tests/run-make/emit-stack-sizes/rmake.rs @@ -0,0 +1,23 @@ +// Running rustc with the -Z emit-stack-sizes +// flag enables diagnostics to seek stack overflows +// at compile time. This test compiles a rust file +// with this flag, then checks that the output object +// file contains the section "stack_sizes", where +// this diagnostics information should be located. +// See https://github.com/rust-lang/rust/pull/51946 + +//@ ignore-windows +//@ ignore-apple +// Reason: this feature only works when the output object format is ELF. +// This won't be the case on Windows/OSX - for example, OSX produces a Mach-O binary. + +use run_make_support::{llvm_readobj, rustc}; + +fn main() { + rustc().opt_level("3").arg("-Zemit-stack-sizes").emit("obj").input("foo.rs").run(); + llvm_readobj() + .arg("--section-headers") + .input("foo.o") + .run() + .assert_stdout_contains(".stack_sizes"); +} From 17950828420fa2068214b906e9fea98a771e64e8 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 27 Jun 2024 14:38:30 -0400 Subject: [PATCH 4/4] rmeta_contains functions for remap-path-prefix --- Cargo.lock | 1 + src/tools/run-make-support/Cargo.toml | 1 + src/tools/run-make-support/src/lib.rs | 1 + tests/run-make/remap-path-prefix/rmake.rs | 51 ++++++++++++++++++----- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0182eca05058d..f6293f9626e13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3401,6 +3401,7 @@ name = "run_make_support" version = "0.2.0" dependencies = [ "ar", + "bstr", "gimli 0.28.1", "object 0.34.0", "regex", diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index e3837a2f8cc4e..ec3b8a96ef3b6 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -4,6 +4,7 @@ version = "0.2.0" edition = "2021" [dependencies] +bstr = "1.6.0" object = "0.34.0" similar = "2.5.0" wasmparser = "0.118.2" diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 771cda630af6a..31b913810b665 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -21,6 +21,7 @@ use std::io; use std::panic; use std::path::{Path, PathBuf}; +pub use bstr; pub use gimli; pub use object; pub use regex; diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs index 4d98dcf6131cd..62c0368e4b3a4 100644 --- a/tests/run-make/remap-path-prefix/rmake.rs +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -3,9 +3,8 @@ // successfully remapped to "/the/aux" in the rmeta files. // See https://github.com/rust-lang/rust/pull/85344 -// FIXME(Oneirical): check if works without ignore-windows - -use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, is_darwin, rustc}; +use run_make_support::bstr::ByteSlice; +use run_make_support::{bstr, fs_wrapper, is_darwin, rustc}; fn main() { let mut out_simple = rustc(); @@ -34,8 +33,8 @@ fn main() { .input("auxiliary/lib.rs"); out_simple.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_object.arg("-Zremap-path-scope=object"); out_macro.arg("-Zremap-path-scope=macro"); @@ -47,12 +46,42 @@ fn main() { } out_object.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_macro.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); out_diagobj.run(); - invalid_utf8_contains("liblib.rmeta", "/the/aux/lib.rs"); - invalid_utf8_not_contains("liblib.rmeta", "auxiliary"); + rmeta_contains("/the/aux/lib.rs"); + rmeta_not_contains("auxiliary"); +} + +//FIXME(Oneirical): These could be generalized into run_make_support +// helper functions. +fn rmeta_contains(expected: &str) { + // Normalize to account for path differences in Windows. + if !bstr::BString::from(fs_wrapper::read("liblib.rmeta")) + .replace(b"\\", b"/") + .contains_str(expected) + { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } +} + +fn rmeta_not_contains(expected: &str) { + // Normalize to account for path differences in Windows. + if bstr::BString::from(fs_wrapper::read("liblib.rmeta")) + .replace(b"\\", b"/") + .contains_str(expected) + { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } }