trans: Link rlibs to dylibs with --whole-archive
This commit starts passing the `--whole-archive` flag (`-force_load` on OSX) to the linker when linking rlibs into dylibs. The primary purpose of this commit is to ensure that the linker doesn't strip out objects from an archive when creating a dynamic library. Information on how this can go wrong can be found in issues #14344 and #25185. The unfortunate part about passing this flag to the linker is that we have to preprocess the rlib to remove the metadata and compressed bytecode found within. This means that creating a dylib will now take longer to link as we've got to copy around the input rlibs to a temporary location, modify them, and then invoke the linker. This isn't done for executables, however, so the "hello world" compile time is not affected. This fix was instigated because of the previous commit where rlibs may not contain multiple object files instead of one due to codegen units being greater than one. That change prevented the main distribution from being compiled with more than one codegen-unit and this commit fixes that. Closes #14344 Closes #25185
This commit is contained in:
parent
d23239b48e
commit
9bc8e6d147
16 changed files with 230 additions and 130 deletions
15
src/test/auxiliary/issue-14344-1.rs
Normal file
15
src/test/auxiliary/issue-14344-1.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
pub fn foo() {}
|
||||
13
src/test/auxiliary/issue-14344-2.rs
Normal file
13
src/test/auxiliary/issue-14344-2.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2015 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 issue_14344_1;
|
||||
|
||||
pub fn bar() {}
|
||||
18
src/test/auxiliary/issue-25185-1.rs
Normal file
18
src/test/auxiliary/issue-25185-1.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern {
|
||||
pub fn rust_dbg_extern_identity_u32(u: u32) -> u32;
|
||||
}
|
||||
13
src/test/auxiliary/issue-25185-2.rs
Normal file
13
src/test/auxiliary/issue-25185-2.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2015 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 issue_25185_1;
|
||||
|
||||
pub use issue_25185_1::rust_dbg_extern_identity_u32;
|
||||
|
|
@ -4,6 +4,6 @@
|
|||
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
|
||||
|
||||
all:
|
||||
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so
|
||||
$(RUSTC) main.rs
|
||||
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so -C prefer-dynamic
|
||||
$(RUSTC) main.rs -C prefer-dynamic
|
||||
$(call RUN,main)
|
||||
|
|
|
|||
20
src/test/run-pass/issue-14344.rs
Normal file
20
src/test/run-pass/issue-14344.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// aux-build:issue-14344-1.rs
|
||||
// aux-build:issue-14344-2.rs
|
||||
|
||||
extern crate issue_14344_1;
|
||||
extern crate issue_14344_2;
|
||||
|
||||
fn main() {
|
||||
issue_14344_1::foo();
|
||||
issue_14344_2::bar();
|
||||
}
|
||||
21
src/test/run-pass/issue-25185.rs
Normal file
21
src/test/run-pass/issue-25185.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// aux-build:issue-25185-1.rs
|
||||
// aux-build:issue-25185-2.rs
|
||||
|
||||
extern crate issue_25185_2;
|
||||
|
||||
fn main() {
|
||||
let x = unsafe {
|
||||
issue_25185_2::rust_dbg_extern_identity_u32(1)
|
||||
};
|
||||
assert_eq!(x, 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue