From f11ab15e9af77b87a4d201eedb2e16f9947b6e85 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 11:58:49 -0400 Subject: [PATCH 1/3] rewrite pass-linker-flags to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/pass-linker-flags/Makefile | 5 ---- tests/run-make/pass-linker-flags/rmake.rs | 27 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) delete mode 100644 tests/run-make/pass-linker-flags/Makefile create mode 100644 tests/run-make/pass-linker-flags/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 2da4e476e90..bdb20255dd9 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/output-type-permutations/Makefile run-make/panic-abort-eh_frame/Makefile run-make/pass-linker-flags-flavor/Makefile run-make/pass-linker-flags-from-dep/Makefile -run-make/pass-linker-flags/Makefile run-make/pass-non-c-like-enum-to-c/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile diff --git a/tests/run-make/pass-linker-flags/Makefile b/tests/run-make/pass-linker-flags/Makefile deleted file mode 100644 index 226943e93bd..00000000000 --- a/tests/run-make/pass-linker-flags/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../tools.mk - -all: - $(RUSTC) empty.rs -Z unstable-options -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3' - $(RUSTC) attribute.rs --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3' diff --git a/tests/run-make/pass-linker-flags/rmake.rs b/tests/run-make/pass-linker-flags/rmake.rs new file mode 100644 index 00000000000..cc6c5d066de --- /dev/null +++ b/tests/run-make/pass-linker-flags/rmake.rs @@ -0,0 +1,27 @@ +// This test checks the proper function of `-l link-arg=NAME`, which, unlike +// -C link-arg, is supposed to guarantee that the order relative to other -l +// options will be respected. In this test, compilation fails (because none of the +// link arguments like `a1` exist), but it is still checked if the output contains the +// link arguments in the exact order they were passed in. `attribute.rs` is a variant +// of the test where the flags are defined in the rust file itself. +// See https://github.com/rust-lang/rust/issues/99427 + +use run_make_support::{regex, rustc}; + +fn main() { + let out = rustc() + .input("empty.rs") + .arg("-Zunstable-options") + .args(&["-l", "static=l1"]) + .arg("-llink-arg=a1") + .arg("-lstatic=l2") + .arg("-llink-arg=a2") + .arg("-ldylib=d1") + .arg("-llink-arg=a3") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out2 = rustc().input("attribute.rs").print("link-args").run_unchecked().stdout_utf8(); + let re = regex::Regex::new("l1.*a1.*l2.*a2.*d1.*a3").unwrap(); + assert!(re.is_match(&out) && re.is_match(&out2)); +} From bc765929fbc61c381440175ad93b3a44e1c324a1 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 13:16:11 -0400 Subject: [PATCH 2/3] rewrite pass-linker-flags-flavor to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../pass-linker-flags-flavor/Makefile | 11 --- .../pass-linker-flags-flavor/rmake.rs | 83 +++++++++++++++++++ tests/run-make/pass-linker-flags/rmake.rs | 5 +- 4 files changed, 86 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/pass-linker-flags-flavor/Makefile create mode 100644 tests/run-make/pass-linker-flags-flavor/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 bdb20255dd9..15200752879 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -106,7 +106,6 @@ run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile run-make/output-type-permutations/Makefile run-make/panic-abort-eh_frame/Makefile -run-make/pass-linker-flags-flavor/Makefile run-make/pass-linker-flags-from-dep/Makefile run-make/pass-non-c-like-enum-to-c/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile diff --git a/tests/run-make/pass-linker-flags-flavor/Makefile b/tests/run-make/pass-linker-flags-flavor/Makefile deleted file mode 100644 index 1bb05d0f974..00000000000 --- a/tests/run-make/pass-linker-flags-flavor/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# only-linux - -include ../tools.mk - -all: - $(RUSTC) empty.rs -Z unstable-options -C linker-flavor=gnu-cc -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3' - $(RUSTC) empty.rs -Z unstable-options -C linker-flavor=gnu-cc -l static=l1 -l link-arg:+verbatim=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3' - $(RUSTC) empty.rs -Z unstable-options -C linker-flavor=ld -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*"a2".*d1.*"a3"' - $(RUSTC) attribute.rs -Z unstable-options -C linker-flavor=gnu-cc --print link-args | $(CGREP) -e 'l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3' - $(RUSTC) --cfg 'feature="verbatim"' attribute.rs -Z unstable-options -C linker-flavor=gnu-cc --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3' - $(RUSTC) attribute.rs -C linker-flavor=ld --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*"a2".*d1.*"a3"' diff --git a/tests/run-make/pass-linker-flags-flavor/rmake.rs b/tests/run-make/pass-linker-flags-flavor/rmake.rs new file mode 100644 index 00000000000..9efb89cea09 --- /dev/null +++ b/tests/run-make/pass-linker-flags-flavor/rmake.rs @@ -0,0 +1,83 @@ +// Setting the linker flavor as a C compiler should cause the output of the -l flags to be +// prefixed by -Wl, except when a flag is requested to be verbatim. A bare linker (ld) should +// never cause prefixes to appear in the output. This test checks this ruleset twice, once with +// explicit flags and then with those flags passed inside the rust source code. +// See https://github.com/rust-lang/rust/pull/118202 + +//FIXME(Oneirical): only-linux + +use run_make_support::{regex, rustc}; + +fn main() { + let out_gnu = rustc() + .input("empty.rs") + .linker_flavor("gnu-cc") + .arg("-Zunstable-options") + .arg("-lstatic=l1") + .arg("-llink-arg=a1") + .arg("-lstatic=l2") + .arg("-llink-arg=a2") + .arg("-ldylib=d1") + .arg("-llink-arg=a3") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_gnu_verbatim = rustc() + .input("empty.rs") + .linker_flavor("gnu-cc") + .arg("-Zunstable-options") + .arg("-lstatic=l1") + .arg("-llink-arg:+verbatim=a1") + .arg("-lstatic=l2") + .arg("-llink-arg=a2") + .arg("-ldylib=d1") + .arg("-llink-arg=a3") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_ld = rustc() + .input("empty.rs") + .linker_flavor("ld") + .arg("-Zunstable-options") + .arg("-lstatic=l1") + .arg("-llink-arg=a1") + .arg("-lstatic=l2") + .arg("-llink-arg=a2") + .arg("-ldylib=d1") + .arg("-llink-arg=a3") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_att_gnu = rustc() + .arg("-Zunstable-options") + .linker_flavor("gnu-cc") + .input("attribute.rs") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_att_gnu_verbatim = rustc() + .cfg(r#"feature="verbatim""#) + .arg("-Zunstable-options") + .linker_flavor("gnu-cc") + .input("attribute.rs") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_att_ld = rustc() + .linker_flavor("ld") + .input("attribute.rs") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + + let no_verbatim = regex::Regex::new("l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3").unwrap(); + let one_verbatim = regex::Regex::new(r#"l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3"#).unwrap(); + let ld = regex::Regex::new(r#"l1.*"a1".*l2.*"a2".*d1.*"a3""#).unwrap(); + + assert!(no_verbatim.is_match(&out_gnu)); + assert!(no_verbatim.is_match(&out_att_gnu)); + assert!(one_verbatim.is_match(&out_gnu_verbatim)); + assert!(one_verbatim.is_match(&out_att_gnu_verbatim)); + assert!(ld.is_match(&out_ld)); + assert!(ld.is_match(&out_att_ld)); +} diff --git a/tests/run-make/pass-linker-flags/rmake.rs b/tests/run-make/pass-linker-flags/rmake.rs index cc6c5d066de..de69567a6e6 100644 --- a/tests/run-make/pass-linker-flags/rmake.rs +++ b/tests/run-make/pass-linker-flags/rmake.rs @@ -12,7 +12,7 @@ fn main() { let out = rustc() .input("empty.rs") .arg("-Zunstable-options") - .args(&["-l", "static=l1"]) + .arg("-lstatic=l1") .arg("-llink-arg=a1") .arg("-lstatic=l2") .arg("-llink-arg=a2") @@ -23,5 +23,6 @@ fn main() { .stdout_utf8(); let out2 = rustc().input("attribute.rs").print("link-args").run_unchecked().stdout_utf8(); let re = regex::Regex::new("l1.*a1.*l2.*a2.*d1.*a3").unwrap(); - assert!(re.is_match(&out) && re.is_match(&out2)); + assert!(re.is_match(&out)); + assert!(re.is_match(&out2)); } From 9f994b633a4ca0ed4f75066ee27ca052e56453dc Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 13:46:26 -0400 Subject: [PATCH 3/3] rewrite pass-linker-flags-from-dep to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../pass-linker-flags-flavor/rmake.rs | 3 +- .../pass-linker-flags-from-dep/Makefile | 12 ------ .../pass-linker-flags-from-dep/rmake.rs | 43 +++++++++++++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/pass-linker-flags-from-dep/Makefile create mode 100644 tests/run-make/pass-linker-flags-from-dep/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 15200752879..c2a4866352f 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -106,7 +106,6 @@ run-make/optimization-remarks-dir-pgo/Makefile run-make/optimization-remarks-dir/Makefile run-make/output-type-permutations/Makefile run-make/panic-abort-eh_frame/Makefile -run-make/pass-linker-flags-from-dep/Makefile run-make/pass-non-c-like-enum-to-c/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile diff --git a/tests/run-make/pass-linker-flags-flavor/rmake.rs b/tests/run-make/pass-linker-flags-flavor/rmake.rs index 9efb89cea09..e36d68cc884 100644 --- a/tests/run-make/pass-linker-flags-flavor/rmake.rs +++ b/tests/run-make/pass-linker-flags-flavor/rmake.rs @@ -4,7 +4,8 @@ // explicit flags and then with those flags passed inside the rust source code. // See https://github.com/rust-lang/rust/pull/118202 -//FIXME(Oneirical): only-linux +//@ only-linux +// Reason: the `gnu-cc` linker is only available on linux use run_make_support::{regex, rustc}; diff --git a/tests/run-make/pass-linker-flags-from-dep/Makefile b/tests/run-make/pass-linker-flags-from-dep/Makefile deleted file mode 100644 index 48b3b26ce81..00000000000 --- a/tests/run-make/pass-linker-flags-from-dep/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -all: - # Build deps - $(RUSTC) native_dep_1.rs --crate-type=staticlib - $(RUSTC) native_dep_2.rs --crate-type=staticlib - $(RUSTC) rust_dep_flag.rs -l static:-bundle=native_dep_1 -l link-arg=some_flag -l static:-bundle=native_dep_2 --crate-type=lib -Z unstable-options - $(RUSTC) rust_dep_attr.rs --crate-type=lib - - # Check sequence of linker args - $(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_flag.rlib --crate-type=bin --print link-args | $(CGREP) -e 'native_dep_1.*some_flag.*native_dep_2' - $(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_attr.rlib --crate-type=bin --print link-args | $(CGREP) -e 'native_dep_1.*some_flag.*native_dep_2' diff --git a/tests/run-make/pass-linker-flags-from-dep/rmake.rs b/tests/run-make/pass-linker-flags-from-dep/rmake.rs new file mode 100644 index 00000000000..4b8e0486e14 --- /dev/null +++ b/tests/run-make/pass-linker-flags-from-dep/rmake.rs @@ -0,0 +1,43 @@ +// A similar test to pass-linker-flags, testing that the `-l link-arg` flag +// respects the order relative to other `-l` flags, but this time, the flags +// are passed on the compilation of a dependency. This test checks that the +// downstream compiled binary contains the linker arguments of the dependency, +// and in the correct order. +// See https://github.com/rust-lang/rust/issues/99427 + +use run_make_support::{regex, rust_lib_name, rustc}; + +fn main() { + // Build dependencies + rustc().input("native_dep_1.rs").crate_type("staticlib").run(); + rustc().input("native_dep_2.rs").crate_type("staticlib").run(); + rustc() + .input("rust_dep_flag.rs") + .arg("-lstatic:-bundle=native_dep_1") + .arg("-llink-arg=some_flag") + .arg("-lstatic:-bundle=native_dep_2") + .crate_type("lib") + .arg("-Zunstable-options") + .run(); + rustc().input("rust_dep_attr.rs").crate_type("lib").run(); + + // Check sequence of linker arguments + let out_flag = rustc() + .input("main.rs") + .extern_("lib", rust_lib_name("rust_dep_flag")) + .crate_type("bin") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + let out_attr = rustc() + .input("main.rs") + .extern_("lib", rust_lib_name("rust_dep_attr")) + .crate_type("bin") + .print("link-args") + .run_unchecked() + .stdout_utf8(); + + let re = regex::Regex::new("native_dep_1.*some_flag.*native_dep_2").unwrap(); + assert!(re.is_match(&out_flag)); + assert!(re.is_match(&out_attr)); +}