trans: Don't link whole rlibs to executables
Back in 9bc8e6d14 the linking of rlibs changed to using the `link_whole_rlib`
function. This change, however was only intended to affect dylibs, not
executables. For executables we don't actually want to link entire rlibs because
we want the linker to strip out as much as possible.
This commit adds a conditional to this logic to only link entire rlibs if we're
creating a dylib, and otherwise an executable just links an rlib as usual. A
test is included which will fail to link if this behavior is reverted.
This commit is contained in:
parent
12a68e6af3
commit
cc719d2d7d
7 changed files with 109 additions and 1 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
18
src/test/run-make/lto-no-link-whole-rlib/Makefile
Normal file
18
src/test/run-make/lto-no-link-whole-rlib/Makefile
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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)
|
||||
|
||||
13
src/test/run-make/lto-no-link-whole-rlib/bar.c
Normal file
13
src/test/run-make/lto-no-link-whole-rlib/bar.c
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
int foo() {
|
||||
return 2;
|
||||
}
|
||||
13
src/test/run-make/lto-no-link-whole-rlib/foo.c
Normal file
13
src/test/run-make/lto-no-link-whole-rlib/foo.c
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
int foo() {
|
||||
return 1;
|
||||
}
|
||||
20
src/test/run-make/lto-no-link-whole-rlib/lib1.rs
Normal file
20
src/test/run-make/lto-no-link-whole-rlib/lib1.rs
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() }
|
||||
}
|
||||
23
src/test/run-make/lto-no-link-whole-rlib/lib2.rs
Normal file
23
src/test/run-make/lto-no-link-whole-rlib/lib2.rs
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() }
|
||||
}
|
||||
|
||||
17
src/test/run-make/lto-no-link-whole-rlib/main.rs
Normal file
17
src/test/run-make/lto-no-link-whole-rlib/main.rs
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue