From f2de5fb2ae0f69d403a06ff4f963e63d95406591 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 12 May 2024 14:00:09 -0400 Subject: [PATCH 1/4] rewrite issue-14500 to rmake --- src/tools/run-make-support/src/rustc.rs | 14 +++++++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/issue-14500/Makefile | 15 --------- tests/run-make/issue-14500/rmake.rs | 31 +++++++++++++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) delete mode 100644 tests/run-make/issue-14500/Makefile create mode 100644 tests/run-make/issue-14500/rmake.rs diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index de773d688ef00..c92e9f9b11f4c 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -150,6 +150,20 @@ impl Rustc { self } + /// Pass a codegen option. + pub fn codegen_option(&mut self, option: &str) -> &mut Self { + self.cmd.arg("-C"); + self.cmd.arg(option); + self + } + + /// Add a directory to the library search path. + pub fn library_search_path>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-L"); + self.cmd.arg(path.as_ref()); + self + } + /// Specify the edition year. pub fn edition(&mut self, edition: &str) -> &mut Self { self.cmd.arg("--edition"); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index e87950b36d9df..a358bc89e1385 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -99,7 +99,6 @@ run-make/issue-107094/Makefile run-make/issue-10971-temps-dir/Makefile run-make/issue-109934-lto-debuginfo/Makefile run-make/issue-11908/Makefile -run-make/issue-14500/Makefile run-make/issue-14698/Makefile run-make/issue-15460/Makefile run-make/issue-18943/Makefile diff --git a/tests/run-make/issue-14500/Makefile b/tests/run-make/issue-14500/Makefile deleted file mode 100644 index eeab48de3b950..0000000000000 --- a/tests/run-make/issue-14500/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -include ../tools.mk - -# ignore-cross-compile - -# Test to make sure that reachable extern fns are always available in final -# productcs, including when LTO is used. In this test, the `foo` crate has a -# reahable symbol, and is a dependency of the `bar` crate. When the `bar` crate -# is compiled with LTO, it shouldn't strip the symbol from `foo`, and that's the -# only way that `foo.c` will successfully compile. - -all: - $(RUSTC) foo.rs --crate-type=rlib - $(RUSTC) bar.rs --crate-type=staticlib -C lto -L. -o $(TMPDIR)/libbar.a - $(CC) foo.c $(TMPDIR)/libbar.a $(EXTRACFLAGS) $(call OUT_EXE,foo) - $(call RUN,foo) diff --git a/tests/run-make/issue-14500/rmake.rs b/tests/run-make/issue-14500/rmake.rs new file mode 100644 index 0000000000000..58c6bc9ebb3a4 --- /dev/null +++ b/tests/run-make/issue-14500/rmake.rs @@ -0,0 +1,31 @@ +// Test to make sure that reachable extern fns are always available in final +// productcs, including when LTO is used. + +// In this test, the `foo` crate has a reahable symbol, +// and is a dependency of the `bar` crate. When the `bar` crate +// is compiled with LTO, it shouldn't strip the symbol from `foo`, and that's the +// only way that `foo.c` will successfully compile. +// See https://github.com/rust-lang/rust/issues/14500 + +//@ ignore-cross-compile + +use run_make_support::{cc, extra_c_flags, run, rustc}; + +fn main() { + let libbar_path = tmp_dir().join("libbar.a"); + rustc().input("foo.rs") + .crate_type("rlib") + .run(); + rustc().input("bar.rs") + .static_lib("staticlib") + .codegen_option("lto") + .library_search_path(".") + .output(&libbar_path) + .run(); + cc().input("foo.c") + .input(libbar_path) + .args(&extra_c_flags()) + .out_exe("foo") + .run(); + run("foo"); +} From a1b5ea0cc220d11b831f49a92c2e37b31ae928d3 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 12 May 2024 14:13:02 -0400 Subject: [PATCH 2/4] make tidy happy --- tests/run-make/issue-14500/rmake.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/run-make/issue-14500/rmake.rs b/tests/run-make/issue-14500/rmake.rs index 58c6bc9ebb3a4..956d66ba88f22 100644 --- a/tests/run-make/issue-14500/rmake.rs +++ b/tests/run-make/issue-14500/rmake.rs @@ -13,19 +13,14 @@ use run_make_support::{cc, extra_c_flags, run, rustc}; fn main() { let libbar_path = tmp_dir().join("libbar.a"); - rustc().input("foo.rs") - .crate_type("rlib") - .run(); - rustc().input("bar.rs") + rustc().input("foo.rs").crate_type("rlib").run(); + rustc() + .input("bar.rs") .static_lib("staticlib") .codegen_option("lto") .library_search_path(".") .output(&libbar_path) .run(); - cc().input("foo.c") - .input(libbar_path) - .args(&extra_c_flags()) - .out_exe("foo") - .run(); + cc().input("foo.c").input(libbar_path).args(&extra_c_flags()).out_exe("foo").run(); run("foo"); } From 71fd2cf5b44441c91673e90414d1e445d8de1922 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 12 May 2024 15:02:22 -0400 Subject: [PATCH 3/4] fix function call and import --- tests/run-make/issue-14500/rmake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/issue-14500/rmake.rs b/tests/run-make/issue-14500/rmake.rs index 956d66ba88f22..58f632e590938 100644 --- a/tests/run-make/issue-14500/rmake.rs +++ b/tests/run-make/issue-14500/rmake.rs @@ -9,14 +9,14 @@ //@ ignore-cross-compile -use run_make_support::{cc, extra_c_flags, run, rustc}; +use run_make_support::{cc, extra_c_flags, run, rustc, tmp_dir}; fn main() { let libbar_path = tmp_dir().join("libbar.a"); rustc().input("foo.rs").crate_type("rlib").run(); rustc() .input("bar.rs") - .static_lib("staticlib") + .crate_type("staticlib") .codegen_option("lto") .library_search_path(".") .output(&libbar_path) From 45b50d303c52a11785469364c82e083cbe14140b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Mon, 13 May 2024 22:56:21 -0400 Subject: [PATCH 4/4] lto function, static_library call, rename --- src/tools/run-make-support/src/rustc.rs | 7 +++---- .../bar.rs | 0 .../foo.c | 0 .../foo.rs | 0 .../rmake.rs | 8 ++++---- 5 files changed, 7 insertions(+), 8 deletions(-) rename tests/run-make/{issue-14500 => reachable-extern-fn-available-lto}/bar.rs (100%) rename tests/run-make/{issue-14500 => reachable-extern-fn-available-lto}/foo.c (100%) rename tests/run-make/{issue-14500 => reachable-extern-fn-available-lto}/foo.rs (100%) rename tests/run-make/{issue-14500 => reachable-extern-fn-available-lto}/rmake.rs (78%) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index c92e9f9b11f4c..0de5a38c0c486 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -150,10 +150,9 @@ impl Rustc { self } - /// Pass a codegen option. - pub fn codegen_option(&mut self, option: &str) -> &mut Self { - self.cmd.arg("-C"); - self.cmd.arg(option); + /// Enables link time optimizations in rustc. Equivalent to `-Clto``. + pub fn lto(&mut self) -> &mut Self { + self.cmd.arg("-Clto"); self } diff --git a/tests/run-make/issue-14500/bar.rs b/tests/run-make/reachable-extern-fn-available-lto/bar.rs similarity index 100% rename from tests/run-make/issue-14500/bar.rs rename to tests/run-make/reachable-extern-fn-available-lto/bar.rs diff --git a/tests/run-make/issue-14500/foo.c b/tests/run-make/reachable-extern-fn-available-lto/foo.c similarity index 100% rename from tests/run-make/issue-14500/foo.c rename to tests/run-make/reachable-extern-fn-available-lto/foo.c diff --git a/tests/run-make/issue-14500/foo.rs b/tests/run-make/reachable-extern-fn-available-lto/foo.rs similarity index 100% rename from tests/run-make/issue-14500/foo.rs rename to tests/run-make/reachable-extern-fn-available-lto/foo.rs diff --git a/tests/run-make/issue-14500/rmake.rs b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs similarity index 78% rename from tests/run-make/issue-14500/rmake.rs rename to tests/run-make/reachable-extern-fn-available-lto/rmake.rs index 58f632e590938..3e38b92b2b87d 100644 --- a/tests/run-make/issue-14500/rmake.rs +++ b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs @@ -1,5 +1,5 @@ // Test to make sure that reachable extern fns are always available in final -// productcs, including when LTO is used. +// productcs, including when link time optimizations (LTO) are used. // In this test, the `foo` crate has a reahable symbol, // and is a dependency of the `bar` crate. When the `bar` crate @@ -9,15 +9,15 @@ //@ ignore-cross-compile -use run_make_support::{cc, extra_c_flags, run, rustc, tmp_dir}; +use run_make_support::{cc, extra_c_flags, run, rustc, static_lib, tmp_dir}; fn main() { - let libbar_path = tmp_dir().join("libbar.a"); + let libbar_path = static_lib("bar"); rustc().input("foo.rs").crate_type("rlib").run(); rustc() .input("bar.rs") .crate_type("staticlib") - .codegen_option("lto") + .lto() .library_search_path(".") .output(&libbar_path) .run();