From 3742f4d9f6eaf7b4b7a8aa246ee3dc2fdb2b80c3 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 3 Aug 2018 17:09:50 +0200 Subject: [PATCH] Add test case for including upstream object files in staticlibs when doing cross-lang LTO. --- .../cross-lang-lto-upstream-rlibs/Makefile | 23 +++++++++++++++++++ .../staticlib.rs | 18 +++++++++++++++ .../cross-lang-lto-upstream-rlibs/upstream.rs | 13 +++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/Makefile create mode 100644 src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/staticlib.rs create mode 100644 src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/upstream.rs diff --git a/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/Makefile b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/Makefile new file mode 100644 index 000000000000..de42c6e0eb54 --- /dev/null +++ b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/Makefile @@ -0,0 +1,23 @@ + +-include ../tools.mk + +# This test makes sure that we don't loose upstream object files when compiling +# staticlibs with -Zcross-lang-lto + +all: staticlib.rs upstream.rs + $(RUSTC) upstream.rs -Z cross-lang-lto -Ccodegen-units=1 + + # Check No LTO + $(RUSTC) staticlib.rs -Z cross-lang-lto -Ccodegen-units=1 -L. -o $(TMPDIR)/staticlib.a + (cd $(TMPDIR); llvm-ar x ./staticlib.a) + # Make sure the upstream object file was included + ls upstream.*.rcgu.o + + # Cleanup + rm $(TMPDIR)/* + + # Check ThinLTO + $(RUSTC) upstream.rs -Z cross-lang-lto -Ccodegen-units=1 -Clto=thin + $(RUSTC) staticlib.rs -Z cross-lang-lto -Ccodegen-units=1 -Clto=thin -L. -o $(TMPDIR)/staticlib.a + (cd $(TMPDIR); llvm-ar x ./staticlib.a) + ls upstream.*.rcgu.o diff --git a/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/staticlib.rs b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/staticlib.rs new file mode 100644 index 000000000000..b370b7b859d8 --- /dev/null +++ b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/staticlib.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type="staticlib"] + +extern crate upstream; + +#[no_mangle] +pub extern fn bar() { + upstream::foo(); +} diff --git a/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/upstream.rs b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/upstream.rs new file mode 100644 index 000000000000..a79b9bf08fc6 --- /dev/null +++ b/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs/upstream.rs @@ -0,0 +1,13 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +pub fn foo() {}