diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 69a70cdf144b3..33734d615a621 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1253,7 +1253,11 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session, if any_objects { archive.build(); - cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&dst)); + if dylib { + cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&dst)); + } else { + cmd.link_rlib(&fix_windows_verbatim_for_gcc(&dst)); + } } }); } diff --git a/src/test/run-make/lto-no-link-whole-rlib/Makefile b/src/test/run-make/lto-no-link-whole-rlib/Makefile new file mode 100644 index 0000000000000..1d45cb413c577 --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/Makefile @@ -0,0 +1,18 @@ +# Copyright 2016 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. + +-include ../tools.mk + +all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar) + $(RUSTC) lib1.rs + $(RUSTC) lib2.rs + $(RUSTC) main.rs -Clto + $(call RUN,main) + diff --git a/src/test/run-make/lto-no-link-whole-rlib/bar.c b/src/test/run-make/lto-no-link-whole-rlib/bar.c new file mode 100644 index 0000000000000..716d1abcf347f --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/bar.c @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +int foo() { + return 2; +} diff --git a/src/test/run-make/lto-no-link-whole-rlib/foo.c b/src/test/run-make/lto-no-link-whole-rlib/foo.c new file mode 100644 index 0000000000000..1b36874581a99 --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/foo.c @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +int foo() { + return 1; +} diff --git a/src/test/run-make/lto-no-link-whole-rlib/lib1.rs b/src/test/run-make/lto-no-link-whole-rlib/lib1.rs new file mode 100644 index 0000000000000..0a87c8e472558 --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/lib1.rs @@ -0,0 +1,20 @@ +// Copyright 2016 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"] + +#[link(name = "foo", kind = "static")] +extern { + fn foo() -> i32; +} + +pub fn foo1() -> i32 { + unsafe { foo() } +} diff --git a/src/test/run-make/lto-no-link-whole-rlib/lib2.rs b/src/test/run-make/lto-no-link-whole-rlib/lib2.rs new file mode 100644 index 0000000000000..6e3f382b3fd92 --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/lib2.rs @@ -0,0 +1,23 @@ +// Copyright 2016 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"] + +extern crate lib1; + +#[link(name = "bar", kind = "static")] +extern { + fn foo() -> i32; +} + +pub fn foo2() -> i32 { + unsafe { foo() } +} + diff --git a/src/test/run-make/lto-no-link-whole-rlib/main.rs b/src/test/run-make/lto-no-link-whole-rlib/main.rs new file mode 100644 index 0000000000000..8417af63be9d9 --- /dev/null +++ b/src/test/run-make/lto-no-link-whole-rlib/main.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +extern crate lib1; +extern crate lib2; + +fn main() { + assert_eq!(lib1::foo1(), 2); + assert_eq!(lib2::foo2(), 2); +}