Skip to content

Commit 2bbfe57

Browse files
committed
---
yaml --- r: 121721 b: refs/heads/try c: b18c4cf h: refs/heads/master i: 121719: 914e768 v: v3
1 parent 6092ec2 commit 2bbfe57

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 8fe47bc3bb34d7a1ce7bbd2c6fc5ea7a6dbf57a4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: bab614f5fa725d248afc5f0530c835f37998ce8f
5-
refs/heads/try: e16a87513a9a94d86de6125a72977af50e05af65
5+
refs/heads/try: b18c4cfef0250eb7cc9b7e8273325878be72c242
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/back/link.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,26 +1170,39 @@ fn link_args(cmd: &mut Command,
11701170
// The default library location, we need this to find the runtime.
11711171
// The location of crates will be determined as needed.
11721172
let lib_path = sess.target_filesearch().get_lib_path();
1173-
cmd.arg("-L").arg(lib_path);
1173+
cmd.arg("-L").arg(&lib_path);
11741174

11751175
cmd.arg("-o").arg(out_filename).arg(obj_filename);
11761176

11771177
// Stack growth requires statically linking a __morestack function. Note
1178-
// that this is listed *before* all other libraries, even though it may be
1179-
// used to resolve symbols in other libraries. The only case that this
1180-
// wouldn't be pulled in by the object file is if the object file had no
1181-
// functions.
1178+
// that this is listed *before* all other libraries. Due to the usage of the
1179+
// --as-needed flag below, the standard library may only be useful for its
1180+
// rust_stack_exhausted function. In this case, we must ensure that the
1181+
// libmorestack.a file appears *before* the standard library (so we put it
1182+
// at the very front).
11821183
//
1183-
// If we're building an executable, there must be at least one function (the
1184-
// main function), and if we're building a dylib then we don't need it for
1185-
// later libraries because they're all dylibs (not rlibs).
1184+
// Most of the time this is sufficient, except for when LLVM gets super
1185+
// clever. If, for example, we have a main function `fn main() {}`, LLVM
1186+
// will optimize out calls to `__morestack` entirely because the function
1187+
// doesn't need any stack at all!
11861188
//
1187-
// I'm honestly not entirely sure why this needs to come first. Apparently
1188-
// the --as-needed flag above sometimes strips out libstd from the command
1189-
// line, but inserting this farther to the left makes the
1190-
// "rust_stack_exhausted" symbol an outstanding undefined symbol, which
1191-
// flags libstd as a required library (or whatever provides the symbol).
1192-
cmd.arg("-lmorestack");
1189+
// To get around this snag, we specially tell the linker to always include
1190+
// all contents of this library. This way we're guaranteed that the linker
1191+
// will include the __morestack symbol 100% of the time, always resolving
1192+
// references to it even if the object above didn't use it.
1193+
match sess.targ_cfg.os {
1194+
abi::OsMacos | abi::OsiOS => {
1195+
let morestack = lib_path.join("libmorestack.a");
1196+
1197+
let mut v = "-Wl,-force_load,".as_bytes().to_owned();
1198+
v.push_all(morestack.as_vec());
1199+
cmd.arg(v.as_slice());
1200+
}
1201+
_ => {
1202+
cmd.args(["-Wl,--whole-archive", "-lmorestack",
1203+
"-Wl,--no-whole-archive"]);
1204+
}
1205+
}
11931206

11941207
// When linking a dynamic library, we put the metadata into a section of the
11951208
// executable. This metadata is in a separate object file from the main
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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+
// compile-flags:-O
12+
13+
fn main() {}

0 commit comments

Comments
 (0)