Skip to content

Commit 98bf62a

Browse files
Add tests for -Z cross-lang-lto.
1 parent 443f99f commit 98bf62a

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This test makes sure that the expected .llvmbc sections for use by
2+
# linker-based LTO are available in object files when compiling with
3+
# -Z cross-lang-lto
4+
5+
-include ../../run-make-fulldeps/tools.mk
6+
7+
LLVMBC_SECTION_NAME=\\.llvmbc
8+
9+
ifeq ($(UNAME),Darwin)
10+
LLVMBC_SECTION_NAME=__LLVM,__bitcode
11+
endif
12+
13+
14+
OBJDUMP=$(HOST_RPATH_DIR)/../../llvm/bin/llvm-objdump
15+
SECTION_HEADERS=$(OBJDUMP) -section-headers
16+
17+
BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto -Ccodegen-units=1
18+
19+
BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto -Ccodegen-units=1 --emit=obj
20+
21+
all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib
22+
23+
staticlib: lib.rs
24+
$(BUILD_LIB) --crate-type=staticlib
25+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
26+
27+
staticlib-fat-lto: lib.rs
28+
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat
29+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-fat-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
30+
31+
staticlib-thin-lto: lib.rs
32+
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin
33+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-thin-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
34+
35+
rlib: lib.rs
36+
$(BUILD_LIB) --crate-type=rlib
37+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.rlib | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
38+
39+
cdylib: lib.rs
40+
$(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o
41+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/cdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
42+
43+
rdylib: lib.rs
44+
$(BUILD_LIB) --crate-type=dylib --emit=obj -o $(TMPDIR)/rdylib.o
45+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/rdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
46+
47+
exe: lib.rs
48+
$(BUILD_EXE) -o $(TMPDIR)/exe.o
49+
[ "$$($(SECTION_HEADERS) $(TMPDIR)/exe.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[no_mangle]
12+
pub extern "C" fn foo() {
13+
println!("abc");
14+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
println!("Hello World");
13+
}

0 commit comments

Comments
 (0)