Skip to content

Commit

Permalink
Use linker optimizations on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian committed Nov 23, 2013
1 parent 747213a commit 6725493
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,13 @@ pub fn link_args(sess: Session,
args.push("-L" + path.as_str().unwrap().to_owned());
}

if sess.targ_cfg.os == abi::OsLinux {
// GNU-style linkers will use this to omit linking to libraries which don't actually fulfill
// any relocations, but only for libraries which follow this flag. Thus, use it before
// specifing libraries to link to.
args.push(~"-Wl,--as-needed");
}

// The names of the extern libraries
let used_libs = cstore::get_used_libraries(cstore);
for l in used_libs.iter() { args.push(~"-l" + *l); }
Expand All @@ -1091,6 +1098,12 @@ pub fn link_args(sess: Session,
// On linux librt and libdl are an indirect dependencies via rustrt,
// and binutils 2.22+ won't add them automatically
if sess.targ_cfg.os == abi::OsLinux {
// GNU-style linkers supports optimization with -O. --gc-sections removes metadata and
// potentially other useful things, so don't include it.
if sess.opts.optimize == session::Default || sess.opts.optimize == session::Aggressive {
args.push(~"-Wl,-O");
}

args.push_all([~"-lrt", ~"-ldl"]);

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

5 comments on commit 6725493

@bors
Copy link
Contributor

@bors bors commented on 6725493 Nov 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6725493 Nov 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging cmr/rust/linker_opts = 6725493 into auto

@bors
Copy link
Contributor

@bors bors commented on 6725493 Nov 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmr/rust/linker_opts = 6725493 merged ok, testing candidate = 738eb9b

@bors
Copy link
Contributor

@bors bors commented on 6725493 Nov 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 6725493 Nov 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 738eb9b

Please sign in to comment.