diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 1671a01860ae4..7d239ff2e0a3a 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -150,6 +150,19 @@ impl Rustc { self } + /// Enables link time optimizations in rustc. Equivalent to `-Clto``. + pub fn lto(&mut self) -> &mut Self { + self.cmd.arg("-Clto"); + 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 83a3ea84b24d7..5f68f779c4eb0 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -95,7 +95,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/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/reachable-extern-fn-available-lto/rmake.rs b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs new file mode 100644 index 0000000000000..3e38b92b2b87d --- /dev/null +++ b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs @@ -0,0 +1,26 @@ +// Test to make sure that reachable extern fns are always available in final +// 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 +// 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, static_lib, tmp_dir}; + +fn main() { + let libbar_path = static_lib("bar"); + rustc().input("foo.rs").crate_type("rlib").run(); + rustc() + .input("bar.rs") + .crate_type("staticlib") + .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"); +}