From 16df91b97ad1df021ccd2203c974f416aae7e76b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 14:56:11 -0400 Subject: [PATCH 1/5] rewrite extern-flag-pathless to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-pathless/Makefile | 34 ---------------- tests/run-make/extern-flag-pathless/rmake.rs | 40 +++++++++++++++++++ 3 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 tests/run-make/extern-flag-pathless/Makefile create mode 100644 tests/run-make/extern-flag-pathless/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 a29d57d160312..463edb461e824 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -33,7 +33,6 @@ run-make/env-dep-info/Makefile 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-fn-explicit-align/Makefile run-make/extern-fn-generic/Makefile run-make/extern-fn-mangle/Makefile diff --git a/tests/run-make/extern-flag-pathless/Makefile b/tests/run-make/extern-flag-pathless/Makefile deleted file mode 100644 index 36b374e0d2e1d..0000000000000 --- a/tests/run-make/extern-flag-pathless/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Test mixing pathless --extern with paths. - -# Test for static linking by checking that the binary runs if the dylib -# is removed and test for dynamic linking by checking that the binary -# fails to run if the dylib is removed. - -all: - $(RUSTC) bar.rs --crate-type=rlib --crate-type=dylib -Cprefer-dynamic - - # rlib preferred over dylib - $(RUSTC) foo.rs --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call RUN,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call RUN,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - # explicit --extern overrides pathless - $(RUSTC) foo.rs --extern bar=$(call DYLIB,bar) --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call FAIL,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - # prefer-dynamic does what it says - $(RUSTC) foo.rs --extern bar -C prefer-dynamic - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call FAIL,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs new file mode 100644 index 0000000000000..2f151136c33c1 --- /dev/null +++ b/tests/run-make/extern-flag-pathless/rmake.rs @@ -0,0 +1,40 @@ +// It is possible, since #64882, to use the --extern flag without an explicit +// path. In the event of two --extern flags, the explicit one with a path will take +// priority, but otherwise, it is a more concise way of fetching specific libraries. +// This test checks that the default priority of explicit extern flags and rlibs is +// respected. +// See https://github.com/rust-lang/rust/pull/64882 + +use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc}; + +fn main() { + rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run(); + + // By default, the rlib has priority over the dylib. + rustc().input("foo.rs").arg("--extern").arg("bar").run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + // The first explicit usage of extern overrides the second pathless --extern bar. + rustc() + .input("foo.rs") + .extern_("bar", dynamic_lib_name("bar")) + .arg("--extern") + .arg("bar") + .run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run_fail("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + // With prefer-dynamic, execution fails as it refuses to use the rlib. + rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run_fail("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); +} From 11ac258a5f5af5fe00cc68a598414a48661a28ce Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 15:14:13 -0400 Subject: [PATCH 2/5] rewrite silly-file-names to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/silly-file-names/Makefile | 12 ---------- tests/run-make/silly-file-names/rmake.rs | 24 +++++++++++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/silly-file-names/Makefile create mode 100644 tests/run-make/silly-file-names/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 463edb461e824..b23a6cb85c02c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -162,7 +162,6 @@ run-make/sepcomp-cci-copies/Makefile run-make/sepcomp-inlining/Makefile run-make/sepcomp-separate/Makefile run-make/share-generics-dylib/Makefile -run-make/silly-file-names/Makefile run-make/simd-ffi/Makefile run-make/split-debuginfo/Makefile run-make/stable-symbol-names/Makefile diff --git a/tests/run-make/silly-file-names/Makefile b/tests/run-make/silly-file-names/Makefile deleted file mode 100644 index e51266c0880b0..0000000000000 --- a/tests/run-make/silly-file-names/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# ignore-cross-compile we need to execute the binary -# ignore-windows we create files with < and > in their names - -include ../tools.mk - -all: - echo '"comes from a file with a name that begins with <"' > "$(TMPDIR)/"' > "$(TMPDIR)/trailing-gt>" - cp silly-file-names.rs "$(TMPDIR)/silly-file-names.rs" - $(RUSTC) "$(TMPDIR)/silly-file-names.rs" -o "$(TMPDIR)/silly-file-names" - "$(TMPDIR)/silly-file-names" > "$(TMPDIR)/silly-file-names.run.stdout" - $(RUSTC_TEST_OP) "$(TMPDIR)/silly-file-names.run.stdout" silly-file-names.run.stdout diff --git a/tests/run-make/silly-file-names/rmake.rs b/tests/run-make/silly-file-names/rmake.rs new file mode 100644 index 0000000000000..9df116146fec3 --- /dev/null +++ b/tests/run-make/silly-file-names/rmake.rs @@ -0,0 +1,24 @@ +// There used to be assert! checks in the compiler to error on encountering +// files starting or ending with < or > respectively, as a preventive measure +// against "fake" files like . However, this was not truly required, +// as rustc has other checks to verify the veracity of a file. This test includes +// some files with < and > in their names and prints out their output to stdout, +// expecting no errors. +// See https://github.com/rust-lang/rust/issues/73419 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed +//@ ignore-windows +// Reason: Windows refuses files with < and > in their names + +use run_make_support::{diff, fs_wrapper, run, rustc}; + +fn main() { + fs_wrapper::create_file(""); + fs_wrapper::write("trailing-gt>", r#""comes from a file with a name that ends with >""#); + rustc().input("silly-file-names.rs").output("silly-file-names").run(); + let out = run("silly-file-names").stdout_utf8(); + diff().expected_file("silly-file-names.run.stdout").actual_text("actual-stdout", out).run(); +} From db21af1a72926571427dd62b51bb1757e88ae64b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 15:33:27 -0400 Subject: [PATCH 3/5] rewrite metadata-dep-info to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/metadata-dep-info/Makefile | 7 ------- ...dash-separated_something-extra.expected.d} | 0 tests/run-make/metadata-dep-info/rmake.rs | 20 +++++++++++++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/metadata-dep-info/Makefile rename tests/run-make/metadata-dep-info/{dash-separated_something-extra.normalized.d => dash-separated_something-extra.expected.d} (100%) create mode 100644 tests/run-make/metadata-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 b23a6cb85c02c..e2ebdbca28188 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -98,7 +98,6 @@ run-make/lto-smoke-c/Makefile run-make/macos-deployment-target/Makefile run-make/macos-fat-archive/Makefile run-make/manual-link/Makefile -run-make/metadata-dep-info/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-dep-info/Makefile b/tests/run-make/metadata-dep-info/Makefile deleted file mode 100644 index d48cbe0f29505..0000000000000 --- a/tests/run-make/metadata-dep-info/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) --emit=metadata,dep-info --crate-type lib dash-separated.rs -C extra-filename=_something-extra - # Strip TMPDIR since it is a machine specific absolute path - sed "s%.*[/\\]%%" "$(TMPDIR)"/dash-separated_something-extra.d > "$(TMPDIR)"/dash-separated_something-extra.normalized.d - $(RUSTC_TEST_OP) "$(TMPDIR)"/dash-separated_something-extra.normalized.d dash-separated_something-extra.normalized.d diff --git a/tests/run-make/metadata-dep-info/dash-separated_something-extra.normalized.d b/tests/run-make/metadata-dep-info/dash-separated_something-extra.expected.d similarity index 100% rename from tests/run-make/metadata-dep-info/dash-separated_something-extra.normalized.d rename to tests/run-make/metadata-dep-info/dash-separated_something-extra.expected.d diff --git a/tests/run-make/metadata-dep-info/rmake.rs b/tests/run-make/metadata-dep-info/rmake.rs new file mode 100644 index 0000000000000..f4bb3ea63fb16 --- /dev/null +++ b/tests/run-make/metadata-dep-info/rmake.rs @@ -0,0 +1,20 @@ +// Emitting dep-info alongside metadata would present subtle discrepancies +// in the output file, such as the filename transforming underscores_ into hyphens-. +// After the fix in #114750, this test checks that the emitted files are identical +// to the expected output. +// See https://github.com/rust-lang/rust/issues/68839 + +use run_make_support::{diff, rustc}; + +fn main() { + rustc() + .emit("metadata,dep-info") + .crate_type("lib") + .input("dash-separated.rs") + .extra_filename("_something-extra") + .run(); + diff() + .expected_file("dash-separated_something-extra.expected.d") + .actual_file("dash-separated_something-extra.d") + .run(); +} From 7c29298ea941247c13ef9de3f129802eb22f12b7 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 16:09:45 -0400 Subject: [PATCH 4/5] rewrite cdylib-fewer-symbols to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/cdylib-fewer-symbols/Makefile | 15 ------------ tests/run-make/cdylib-fewer-symbols/rmake.rs | 23 +++++++++++++++++++ 3 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 tests/run-make/cdylib-fewer-symbols/Makefile create mode 100644 tests/run-make/cdylib-fewer-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 e2ebdbca28188..e9034c631af6f 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/c-unwind-abi-catch-lib-panic/Makefile run-make/c-unwind-abi-catch-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile -run-make/cdylib-fewer-symbols/Makefile run-make/compiler-lookup-paths-2/Makefile run-make/compiler-lookup-paths/Makefile run-make/compiler-rt-works-on-mingw/Makefile diff --git a/tests/run-make/cdylib-fewer-symbols/Makefile b/tests/run-make/cdylib-fewer-symbols/Makefile deleted file mode 100644 index d587cece5bec0..0000000000000 --- a/tests/run-make/cdylib-fewer-symbols/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# ignore-cross-compile - -# Test that allocator-related symbols don't show up as exported from a cdylib as -# they're internal to Rust and not part of the public ABI. -# See https://github.com/rust-lang/rust/commit/fbf98697021173a30b84d9145df0966a23a2f9d2 - -include ../tools.mk - -# ignore-windows -# FIXME: The __rdl_ and __rust_ symbol still remains, no matter using MSVC or GNU -# See https://github.com/rust-lang/rust/pull/46207#issuecomment-347561753 - -all: - $(RUSTC) foo.rs - nm -g "$(call DYLIB,foo)" | $(CGREP) -v __rdl_ __rde_ __rg_ __rust_ diff --git a/tests/run-make/cdylib-fewer-symbols/rmake.rs b/tests/run-make/cdylib-fewer-symbols/rmake.rs new file mode 100644 index 0000000000000..8a8d31e6e49e4 --- /dev/null +++ b/tests/run-make/cdylib-fewer-symbols/rmake.rs @@ -0,0 +1,23 @@ +// Symbols related to the allocator should be hidden and not exported from a cdylib, +// for they are internal to Rust +// and not part of the public ABI (application binary interface). This test checks that +// four such symbols are successfully hidden. +// See https://github.com/rust-lang/rust/pull/45710 + +//FIXME(Oneirical): try it on windows, restore ignore +// See https://github.com/rust-lang/rust/pull/46207#issuecomment-347561753 +//FIXME(Oneirical): I also removed cross-compile ignore since there is no binary execution + +use run_make_support::{dynamic_lib_name, llvm_readobj, rustc}; + +fn main() { + // Compile a cdylib + rustc().input("foo.rs").run(); + let out = llvm_readobj().arg("--symbols").input(dynamic_lib_name("foo")).run().stdout_utf8(); + let out = // All hidden symbols must be removed. + out.lines().filter(|&line| !line.trim().contains("HIDDEN")).collect::>().join("\n"); + assert!(!&out.contains("__rdl_")); + assert!(!&out.contains("__rde_")); + assert!(!&out.contains("__rg_")); + assert!(!&out.contains("__ruse_")); +} From d44732120cfd6f49d49bc333ad60c0539aedee19 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 16:21:58 -0400 Subject: [PATCH 5/5] rewrite symbols-include-type-name to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/cdylib-fewer-symbols/rmake.rs | 18 ++++++++---------- tests/run-make/extern-flag-pathless/rmake.rs | 3 +++ .../symbols-include-type-name/Makefile | 9 --------- .../symbols-include-type-name/rmake.rs | 12 ++++++++++++ 5 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 tests/run-make/symbols-include-type-name/Makefile create mode 100644 tests/run-make/symbols-include-type-name/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 e9034c631af6f..17f4c5883a7f7 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -170,7 +170,6 @@ run-make/staticlib-dylib-linkage/Makefile run-make/std-core-cycle/Makefile run-make/symbol-mangling-hashed/Makefile run-make/symbol-visibility/Makefile -run-make/symbols-include-type-name/Makefile run-make/sysroot-crates-are-unstable/Makefile run-make/target-cpu-native/Makefile run-make/target-specs/Makefile diff --git a/tests/run-make/cdylib-fewer-symbols/rmake.rs b/tests/run-make/cdylib-fewer-symbols/rmake.rs index 8a8d31e6e49e4..da11f036f7ca4 100644 --- a/tests/run-make/cdylib-fewer-symbols/rmake.rs +++ b/tests/run-make/cdylib-fewer-symbols/rmake.rs @@ -4,20 +4,18 @@ // four such symbols are successfully hidden. // See https://github.com/rust-lang/rust/pull/45710 -//FIXME(Oneirical): try it on windows, restore ignore -// See https://github.com/rust-lang/rust/pull/46207#issuecomment-347561753 -//FIXME(Oneirical): I also removed cross-compile ignore since there is no binary execution +//@ ignore-cross-compile +// Reason: The __rust_ symbol appears during cross-compilation. use run_make_support::{dynamic_lib_name, llvm_readobj, rustc}; fn main() { // Compile a cdylib rustc().input("foo.rs").run(); - let out = llvm_readobj().arg("--symbols").input(dynamic_lib_name("foo")).run().stdout_utf8(); - let out = // All hidden symbols must be removed. - out.lines().filter(|&line| !line.trim().contains("HIDDEN")).collect::>().join("\n"); - assert!(!&out.contains("__rdl_")); - assert!(!&out.contains("__rde_")); - assert!(!&out.contains("__rg_")); - assert!(!&out.contains("__ruse_")); + let out = + llvm_readobj().arg("--dyn-symbols").input(dynamic_lib_name("foo")).run().stdout_utf8(); + assert!(!&out.contains("__rdl_"), "{out}"); + assert!(!&out.contains("__rde_"), "{out}"); + assert!(!&out.contains("__rg_"), "{out}"); + assert!(!&out.contains("__rust_"), "{out}"); } diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs index 2f151136c33c1..9cf828abcb8b4 100644 --- a/tests/run-make/extern-flag-pathless/rmake.rs +++ b/tests/run-make/extern-flag-pathless/rmake.rs @@ -5,6 +5,9 @@ // respected. // See https://github.com/rust-lang/rust/pull/64882 +//@ ignore-cross-compile +// Reason: the compiled binary is executed + use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc}; fn main() { diff --git a/tests/run-make/symbols-include-type-name/Makefile b/tests/run-make/symbols-include-type-name/Makefile deleted file mode 100644 index ac26a852e36c1..0000000000000 --- a/tests/run-make/symbols-include-type-name/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# Check that symbol names for methods include type names, instead of . - -OUT=$(TMPDIR)/lib.s - -all: - $(RUSTC) --crate-type staticlib --emit asm lib.rs - $(CGREP) Def < $(OUT) diff --git a/tests/run-make/symbols-include-type-name/rmake.rs b/tests/run-make/symbols-include-type-name/rmake.rs new file mode 100644 index 0000000000000..746c7486bf0c0 --- /dev/null +++ b/tests/run-make/symbols-include-type-name/rmake.rs @@ -0,0 +1,12 @@ +// Method names used to be obfuscated when exported into symbols, +// leaving only an obscure ``. After the fix in #30328, +// this test checks that method names are successfully saved in the symbol list. +// See https://github.com/rust-lang/rust/issues/30260 + +use run_make_support::{invalid_utf8_contains, rustc}; + +fn main() { + rustc().crate_type("staticlib").emit("asm").input("lib.rs").run(); + // Check that symbol names for methods include type names, instead of . + invalid_utf8_contains("lib.s", "Def"); +}