Skip to content

Commit 738eb9b

Browse files
committed
auto merge of #10620 : cmr/rust/linker_opts, r=thestinger
2 parents 9ba473f + 6725493 commit 738eb9b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc/back/link.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,13 @@ pub fn link_args(sess: Session,
10721072
args.push("-L" + path.as_str().unwrap().to_owned());
10731073
}
10741074

1075+
if sess.targ_cfg.os == abi::OsLinux {
1076+
// GNU-style linkers will use this to omit linking to libraries which don't actually fulfill
1077+
// any relocations, but only for libraries which follow this flag. Thus, use it before
1078+
// specifing libraries to link to.
1079+
args.push(~"-Wl,--as-needed");
1080+
}
1081+
10751082
// The names of the extern libraries
10761083
let used_libs = cstore::get_used_libraries(cstore);
10771084
for l in used_libs.iter() { args.push(~"-l" + *l); }
@@ -1091,6 +1098,12 @@ pub fn link_args(sess: Session,
10911098
// On linux librt and libdl are an indirect dependencies via rustrt,
10921099
// and binutils 2.22+ won't add them automatically
10931100
if sess.targ_cfg.os == abi::OsLinux {
1101+
// GNU-style linkers supports optimization with -O. --gc-sections removes metadata and
1102+
// potentially other useful things, so don't include it.
1103+
if sess.opts.optimize == session::Default || sess.opts.optimize == session::Aggressive {
1104+
args.push(~"-Wl,-O");
1105+
}
1106+
10941107
args.push_all([~"-lrt", ~"-ldl"]);
10951108

10961109
// LLVM implements the `frem` instruction as a call to `fmod`,

0 commit comments

Comments
 (0)