From 98bf62a109bd7d7071e5d3b8f35186cf33124722 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 16 Apr 2018 16:26:40 +0200 Subject: [PATCH] Add tests for -Z cross-lang-lto. --- src/test/run-make/cross-lang-lto/Makefile | 49 +++++++++++++++++++++++ src/test/run-make/cross-lang-lto/lib.rs | 14 +++++++ src/test/run-make/cross-lang-lto/main.rs | 13 ++++++ 3 files changed, 76 insertions(+) create mode 100644 src/test/run-make/cross-lang-lto/Makefile create mode 100644 src/test/run-make/cross-lang-lto/lib.rs create mode 100644 src/test/run-make/cross-lang-lto/main.rs diff --git a/src/test/run-make/cross-lang-lto/Makefile b/src/test/run-make/cross-lang-lto/Makefile new file mode 100644 index 000000000000..e664394d1eac --- /dev/null +++ b/src/test/run-make/cross-lang-lto/Makefile @@ -0,0 +1,49 @@ +# This test makes sure that the expected .llvmbc sections for use by +# linker-based LTO are available in object files when compiling with +# -Z cross-lang-lto + +-include ../../run-make-fulldeps/tools.mk + +LLVMBC_SECTION_NAME=\\.llvmbc + +ifeq ($(UNAME),Darwin) + LLVMBC_SECTION_NAME=__LLVM,__bitcode +endif + + +OBJDUMP=$(HOST_RPATH_DIR)/../../llvm/bin/llvm-objdump +SECTION_HEADERS=$(OBJDUMP) -section-headers + +BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto -Ccodegen-units=1 + +BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto -Ccodegen-units=1 --emit=obj + +all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib + +staticlib: lib.rs + $(BUILD_LIB) --crate-type=staticlib + [ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +staticlib-fat-lto: lib.rs + $(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat + [ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-fat-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +staticlib-thin-lto: lib.rs + $(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin + [ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-thin-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +rlib: lib.rs + $(BUILD_LIB) --crate-type=rlib + [ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.rlib | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +cdylib: lib.rs + $(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o + [ "$$($(SECTION_HEADERS) $(TMPDIR)/cdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +rdylib: lib.rs + $(BUILD_LIB) --crate-type=dylib --emit=obj -o $(TMPDIR)/rdylib.o + [ "$$($(SECTION_HEADERS) $(TMPDIR)/rdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] + +exe: lib.rs + $(BUILD_EXE) -o $(TMPDIR)/exe.o + [ "$$($(SECTION_HEADERS) $(TMPDIR)/exe.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ] diff --git a/src/test/run-make/cross-lang-lto/lib.rs b/src/test/run-make/cross-lang-lto/lib.rs new file mode 100644 index 000000000000..b2a5b946160f --- /dev/null +++ b/src/test/run-make/cross-lang-lto/lib.rs @@ -0,0 +1,14 @@ +// 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. + +#[no_mangle] +pub extern "C" fn foo() { + println!("abc"); +} diff --git a/src/test/run-make/cross-lang-lto/main.rs b/src/test/run-make/cross-lang-lto/main.rs new file mode 100644 index 000000000000..ccd34c9e4dbe --- /dev/null +++ b/src/test/run-make/cross-lang-lto/main.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. + +fn main() { + println!("Hello World"); +}