From cf9e7a975d4a64ad60669a9764e64400710c7e67 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 11:10:29 -0400 Subject: [PATCH 1/5] rewrite std-core-cycle to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/std-core-cycle/Makefile | 17 ----------- tests/run-make/std-core-cycle/rmake.rs | 28 +++++++++++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) delete mode 100644 tests/run-make/std-core-cycle/Makefile create mode 100644 tests/run-make/std-core-cycle/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 31cb32d349ace..c527161aa9a0d 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -142,7 +142,6 @@ run-make/static-dylib-by-default/Makefile run-make/static-extern-type/Makefile run-make/staticlib-blank-lib/Makefile 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 diff --git a/tests/run-make/std-core-cycle/Makefile b/tests/run-make/std-core-cycle/Makefile deleted file mode 100644 index 5ed6be905dffa..0000000000000 --- a/tests/run-make/std-core-cycle/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -ifeq ($(UNAME),Darwin) -FLAGS := -else -ifdef IS_WINDOWS -FLAGS := -else -FLAGS := -C link-args=-Wl,--no-undefined -endif -endif - -all: - $(RUSTC) bar.rs - $(RUSTC) foo.rs $(FLAGS) - $(RUSTC) foo.rs $(FLAGS) -C panic=abort diff --git a/tests/run-make/std-core-cycle/rmake.rs b/tests/run-make/std-core-cycle/rmake.rs new file mode 100644 index 0000000000000..0f63c3f7ce471 --- /dev/null +++ b/tests/run-make/std-core-cycle/rmake.rs @@ -0,0 +1,28 @@ +// In some cases, linking libraries with GNU used to fail due to how +// `std` and `core` possess a circular dependency with one another, and +// how the linker could not go back through its symbol processing to resolve +// the circular link. #49316 fixed this, and this test reproduces a minimal +// version of one such linking attempt which used to fail. +// See https://github.com/rust-lang/rust/issues/18807 + +//@ ignore-cross-compile + +use run_make_support::{is_darwin, is_windows, rustc}; + +fn main() { + rustc().input("bar.rs").run(); + + let mut rustc_foo = rustc(); + rustc_foo.input("foo.rs"); + let mut rustc_foo_panic = rustc(); + rustc_foo_panic.input("foo.rs").panic("abort"); + + if !is_darwin() && !is_windows() { + rustc_foo.arg("-Clink-args=-Wl,--no-undefined"); + rustc_foo_panic.arg("-Clink-args=-Wl,--no-undefined"); + } + + rustc_foo.run(); + rustc_foo_panic.run(); +} + From 2c7afc114d7ccc9bbc1dce29f1be1dca343e722f Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 11:41:54 -0400 Subject: [PATCH 2/5] rewrite obey-crate-type-flag to rmake --- src/tools/run-make-support/src/lib.rs | 37 +++++++++++++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/obey-crate-type-flag/Makefile | 14 ------- tests/run-make/obey-crate-type-flag/rmake.rs | 16 ++++++++ 4 files changed, 53 insertions(+), 15 deletions(-) delete mode 100644 tests/run-make/obey-crate-type-flag/Makefile create mode 100644 tests/run-make/obey-crate-type-flag/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index f464a109e7711..721200f77f3aa 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -23,6 +23,7 @@ use std::path::{Path, PathBuf}; pub use bstr; pub use gimli; +pub use glob; pub use object; pub use regex; pub use wasmparser; @@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String { if is_windows() { format!("{name}.exe") } else { name.to_string() } } +/// Remove all dynamic libraries possessing a name starting with `paths`. +#[track_caller] +pub fn remove_dylibs(paths: &str) { + let paths = format!(r"{paths}*"); + remove_glob(dynamic_lib_name(&paths).as_str()); +} + +/// Remove all rust libraries possessing a name starting with `paths`. +#[track_caller] +pub fn remove_rlibs(paths: &str) { + let paths = format!(r"{paths}*"); + remove_glob(rust_lib_name(&paths).as_str()); +} + +#[track_caller] +fn remove_glob(paths: &str) { + let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str()); + paths + .filter_map(|entry| entry.ok()) + .filter(|entry| entry.as_path().is_file()) + .for_each(|file| fs_wrapper::remove_file(&file)); +} + +#[track_caller] +fn count_glob(paths: &str) -> usize { + let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str()); + paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count() +} + +/// Count the number of rust libraries possessing a name starting with `paths`. +#[track_caller] +pub fn count_rlibs(paths: &str) -> usize { + let paths = format!(r"{paths}*"); + count_glob(rust_lib_name(&paths).as_str()) +} + /// Return the current working directory. #[must_use] pub fn cwd() -> PathBuf { diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index c527161aa9a0d..8dc48d42f67f2 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -97,7 +97,6 @@ run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile run-make/no-duplicate-libs/Makefile -run-make/obey-crate-type-flag/Makefile run-make/panic-abort-eh_frame/Makefile run-make/pass-linker-flags-flavor/Makefile run-make/pass-linker-flags-from-dep/Makefile diff --git a/tests/run-make/obey-crate-type-flag/Makefile b/tests/run-make/obey-crate-type-flag/Makefile deleted file mode 100644 index ecbb2e620ed38..0000000000000 --- a/tests/run-make/obey-crate-type-flag/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# check that rustc builds all crate_type attributes -# delete rlib -# delete whatever dylib is made for this system -# check that rustc only builds --crate-type flags, ignoring attributes -# fail if an rlib was built -all: - $(RUSTC) test.rs - $(call REMOVE_RLIBS,test) - $(call REMOVE_DYLIBS,test) - $(RUSTC) --crate-type dylib test.rs - $(call REMOVE_RLIBS,test) && exit 1 || exit 0 diff --git a/tests/run-make/obey-crate-type-flag/rmake.rs b/tests/run-make/obey-crate-type-flag/rmake.rs new file mode 100644 index 0000000000000..4ae4b6e4eec0a --- /dev/null +++ b/tests/run-make/obey-crate-type-flag/rmake.rs @@ -0,0 +1,16 @@ +// test.rs should produce both an rlib and a dylib +// by default. When the crate_type flag is passed and +// forced to dylib, no rlibs should be produced. +// See https://github.com/rust-lang/rust/issues/11573 + +//@ ignore-cross-compile + +use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc}; + +fn main() { + rustc().input("test.rs").run(); + remove_rlibs("test"); + remove_dylibs("test"); + rustc().crate_type("dylib").input("test.rs").run(); + assert_eq!(count_rlibs("test"), 0); +} From d9162fd97f1655a145b7975b8e7af7e37f4de84d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 12:08:43 -0400 Subject: [PATCH 3/5] rewrite and rename issue-18943 to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/issue-18943/Makefile | 7 ------- .../foo.rs | 0 tests/run-make/lib-trait-for-trait-no-ice/rmake.rs | 13 +++++++++++++ tests/run-make/std-core-cycle/rmake.rs | 1 - 5 files changed, 13 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/issue-18943/Makefile rename tests/run-make/{issue-18943 => lib-trait-for-trait-no-ice}/foo.rs (100%) create mode 100644 tests/run-make/lib-trait-for-trait-no-ice/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 8dc48d42f67f2..23b3b91604dc6 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -52,7 +52,6 @@ run-make/issue-107094/Makefile run-make/issue-109934-lto-debuginfo/Makefile run-make/issue-14698/Makefile run-make/issue-15460/Makefile -run-make/issue-18943/Makefile run-make/issue-22131/Makefile run-make/issue-25581/Makefile run-make/issue-26006/Makefile diff --git a/tests/run-make/issue-18943/Makefile b/tests/run-make/issue-18943/Makefile deleted file mode 100644 index fc40d756d6f21..0000000000000 --- a/tests/run-make/issue-18943/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../tools.mk - -# Regression test for ICE #18943 when compiling as lib - -all: - $(RUSTC) foo.rs --crate-type lib - $(call REMOVE_RLIBS,foo) && exit 0 || exit 1 diff --git a/tests/run-make/issue-18943/foo.rs b/tests/run-make/lib-trait-for-trait-no-ice/foo.rs similarity index 100% rename from tests/run-make/issue-18943/foo.rs rename to tests/run-make/lib-trait-for-trait-no-ice/foo.rs diff --git a/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs new file mode 100644 index 0000000000000..5f8c998874b65 --- /dev/null +++ b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs @@ -0,0 +1,13 @@ +// Inside a library, implementing a trait for another trait +// with a lifetime used to cause an internal compiler error (ICE). +// This test checks that this bug does not make a resurgence - +// first by ensuring successful compilation, then verifying that +// the lib crate-type flag was actually followed. +// See https://github.com/rust-lang/rust/issues/18943 + +use run_make_support::{count_rlibs, rustc}; + +fn main() { + rustc().input("foo.rs").crate_type("lib").run(); + assert_eq!(count_rlibs("foo"), 1); +} diff --git a/tests/run-make/std-core-cycle/rmake.rs b/tests/run-make/std-core-cycle/rmake.rs index 0f63c3f7ce471..162b783aeb985 100644 --- a/tests/run-make/std-core-cycle/rmake.rs +++ b/tests/run-make/std-core-cycle/rmake.rs @@ -25,4 +25,3 @@ fn main() { rustc_foo.run(); rustc_foo_panic.run(); } - From ece7d98c0ea5b639c59331ef6b2c890c637ef862 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 14 Jun 2024 13:22:51 -0400 Subject: [PATCH 4/5] rewrite mixing-libs to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/mixing-libs/Makefile | 8 ------- tests/run-make/mixing-libs/rmake.rs | 21 +++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/mixing-libs/Makefile create mode 100644 tests/run-make/mixing-libs/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 23b3b91604dc6..6c67155b55cff 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -90,7 +90,6 @@ run-make/manual-link/Makefile run-make/metadata-dep-info/Makefile run-make/min-global-align/Makefile run-make/missing-crate-dependency/Makefile -run-make/mixing-libs/Makefile run-make/native-link-modifier-bundle/Makefile run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile diff --git a/tests/run-make/mixing-libs/Makefile b/tests/run-make/mixing-libs/Makefile deleted file mode 100644 index 459db0dfdb2f7..0000000000000 --- a/tests/run-make/mixing-libs/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) rlib.rs --crate-type=rlib --crate-type=dylib - $(RUSTC) dylib.rs # no -Cprefer-dynamic so statically linking librlib.rlib - $(call REMOVE_DYLIBS,rlib) # remove librlib.so to test that prog.rs doesn't get confused about the removed dylib version of librlib - $(RUSTC) prog.rs && exit 1 || exit 0 diff --git a/tests/run-make/mixing-libs/rmake.rs b/tests/run-make/mixing-libs/rmake.rs new file mode 100644 index 0000000000000..d46a2403c25b3 --- /dev/null +++ b/tests/run-make/mixing-libs/rmake.rs @@ -0,0 +1,21 @@ +// Having multiple upstream crates available in different formats +// should result in failed compilation. This test causes multiple +// libraries to exist simultaneously as rust libs and dynamic libs, +// causing prog.rs to fail compilation. +// See https://github.com/rust-lang/rust/issues/10434 + +//@ ignore-cross-compile + +use run_make_support::{remove_dylibs, rustc}; + +fn main() { + rustc().input("rlib.rs").crate_type("rlib").crate_type("dylib").run(); + + // Not putting `-C prefer-dynamic` here allows for static linking of librlib.rlib. + rustc().input("dylib.rs").run(); + + // librlib's dynamic version needs to be removed here to prevent prog.rs from fetching + // the wrong one. + remove_dylibs("rlib"); + rustc().input("prog.rs").run_fail(); +} From cbc62cb38fb0982ba1db9f91149a241792002024 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 17 Jun 2024 13:23:53 -0400 Subject: [PATCH 5/5] shallow_find_files function for run_make_support --- src/tools/run-make-support/src/lib.rs | 37 ------------------- .../lib-trait-for-trait-no-ice/rmake.rs | 5 ++- tests/run-make/mixing-libs/rmake.rs | 4 +- tests/run-make/obey-crate-type-flag/rmake.rs | 13 +++++-- 4 files changed, 14 insertions(+), 45 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 721200f77f3aa..f464a109e7711 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -23,7 +23,6 @@ use std::path::{Path, PathBuf}; pub use bstr; pub use gimli; -pub use glob; pub use object; pub use regex; pub use wasmparser; @@ -224,42 +223,6 @@ pub fn bin_name(name: &str) -> String { if is_windows() { format!("{name}.exe") } else { name.to_string() } } -/// Remove all dynamic libraries possessing a name starting with `paths`. -#[track_caller] -pub fn remove_dylibs(paths: &str) { - let paths = format!(r"{paths}*"); - remove_glob(dynamic_lib_name(&paths).as_str()); -} - -/// Remove all rust libraries possessing a name starting with `paths`. -#[track_caller] -pub fn remove_rlibs(paths: &str) { - let paths = format!(r"{paths}*"); - remove_glob(rust_lib_name(&paths).as_str()); -} - -#[track_caller] -fn remove_glob(paths: &str) { - let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str()); - paths - .filter_map(|entry| entry.ok()) - .filter(|entry| entry.as_path().is_file()) - .for_each(|file| fs_wrapper::remove_file(&file)); -} - -#[track_caller] -fn count_glob(paths: &str) -> usize { - let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str()); - paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count() -} - -/// Count the number of rust libraries possessing a name starting with `paths`. -#[track_caller] -pub fn count_rlibs(paths: &str) -> usize { - let paths = format!(r"{paths}*"); - count_glob(rust_lib_name(&paths).as_str()) -} - /// Return the current working directory. #[must_use] pub fn cwd() -> PathBuf { diff --git a/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs index 5f8c998874b65..766acfc00da53 100644 --- a/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs +++ b/tests/run-make/lib-trait-for-trait-no-ice/rmake.rs @@ -5,9 +5,10 @@ // the lib crate-type flag was actually followed. // See https://github.com/rust-lang/rust/issues/18943 -use run_make_support::{count_rlibs, rustc}; +use run_make_support::{rust_lib_name, rustc}; +use std::path::Path; fn main() { rustc().input("foo.rs").crate_type("lib").run(); - assert_eq!(count_rlibs("foo"), 1); + assert!(Path::new(&rust_lib_name("foo")).exists()); } diff --git a/tests/run-make/mixing-libs/rmake.rs b/tests/run-make/mixing-libs/rmake.rs index d46a2403c25b3..06ef6ab00f5f8 100644 --- a/tests/run-make/mixing-libs/rmake.rs +++ b/tests/run-make/mixing-libs/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile -use run_make_support::{remove_dylibs, rustc}; +use run_make_support::{dynamic_lib_name, fs_wrapper, rustc}; fn main() { rustc().input("rlib.rs").crate_type("rlib").crate_type("dylib").run(); @@ -16,6 +16,6 @@ fn main() { // librlib's dynamic version needs to be removed here to prevent prog.rs from fetching // the wrong one. - remove_dylibs("rlib"); + fs_wrapper::remove_file(dynamic_lib_name("rlib")); rustc().input("prog.rs").run_fail(); } diff --git a/tests/run-make/obey-crate-type-flag/rmake.rs b/tests/run-make/obey-crate-type-flag/rmake.rs index 4ae4b6e4eec0a..8aa78cccbb23b 100644 --- a/tests/run-make/obey-crate-type-flag/rmake.rs +++ b/tests/run-make/obey-crate-type-flag/rmake.rs @@ -5,12 +5,17 @@ //@ ignore-cross-compile -use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc}; +use run_make_support::{ + cwd, dynamic_lib_name, fs_wrapper, has_extension, rust_lib_name, rustc, shallow_find_files, +}; +use std::path::Path; fn main() { rustc().input("test.rs").run(); - remove_rlibs("test"); - remove_dylibs("test"); + assert!(Path::new(&dynamic_lib_name("test")).exists()); + assert!(Path::new(&rust_lib_name("test")).exists()); + + fs_wrapper::remove_file(rust_lib_name("test")); rustc().crate_type("dylib").input("test.rs").run(); - assert_eq!(count_rlibs("test"), 0); + assert!(shallow_find_files(cwd(), |path| { has_extension(path, "rlib") }).is_empty()); }