Skip to content

Commit 3742f4d

Browse files
Add test case for including upstream object files in staticlibs when doing cross-lang LTO.
1 parent 386e000 commit 3742f4d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
-include ../tools.mk
3+
4+
# This test makes sure that we don't loose upstream object files when compiling
5+
# staticlibs with -Zcross-lang-lto
6+
7+
all: staticlib.rs upstream.rs
8+
$(RUSTC) upstream.rs -Z cross-lang-lto -Ccodegen-units=1
9+
10+
# Check No LTO
11+
$(RUSTC) staticlib.rs -Z cross-lang-lto -Ccodegen-units=1 -L. -o $(TMPDIR)/staticlib.a
12+
(cd $(TMPDIR); llvm-ar x ./staticlib.a)
13+
# Make sure the upstream object file was included
14+
ls upstream.*.rcgu.o
15+
16+
# Cleanup
17+
rm $(TMPDIR)/*
18+
19+
# Check ThinLTO
20+
$(RUSTC) upstream.rs -Z cross-lang-lto -Ccodegen-units=1 -Clto=thin
21+
$(RUSTC) staticlib.rs -Z cross-lang-lto -Ccodegen-units=1 -Clto=thin -L. -o $(TMPDIR)/staticlib.a
22+
(cd $(TMPDIR); llvm-ar x ./staticlib.a)
23+
ls upstream.*.rcgu.o
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
#![crate_type="staticlib"]
12+
13+
extern crate upstream;
14+
15+
#[no_mangle]
16+
pub extern fn bar() {
17+
upstream::foo();
18+
}
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+
#![crate_type = "rlib"]
12+
13+
pub fn foo() {}

0 commit comments

Comments
 (0)