rewrite pass-linker-flags-flavor to rmake

This commit is contained in:
Oneirical 2024-07-04 13:16:11 -04:00
parent f11ab15e9a
commit bc765929fb
4 changed files with 86 additions and 14 deletions

View File

@ -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

View File

@ -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"'

View File

@ -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));
}

View File

@ -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));
}