Skip to content

Commit cbe6bd0

Browse files
committed
auto merge of #13829 : alexcrichton/rust/dead-strip, r=thestinger
This flag to the linker asks it to strip away all dead code during linking, as well as dead data. This reduces the size of hello world from 1.7MB to 458K on my system (70% reduction). I have not seen this impact link times negatively, and I have seen this pass 'make check' successfully. I am slightly wary of adding this option, but the benefits are so huge tha I think we should work hard to work around any issues rather than avoid using the flag entirely.
2 parents 8fdf1e2 + edd8bb0 commit cbe6bd0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/librustc/back/link.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,18 @@ fn link_args(sess: &Session,
11501150
sess.opts.optimize == session::Aggressive {
11511151
args.push("-Wl,-O1".to_owned());
11521152
}
1153+
} else if sess.targ_cfg.os == abi::OsMacos {
1154+
// The dead_strip option to the linker specifies that functions and data
1155+
// unreachable by the entry point will be removed. This is quite useful
1156+
// with Rust's compilation model of compiling libraries at a time into
1157+
// one object file. For example, this brings hello world from 1.7MB to
1158+
// 458K.
1159+
//
1160+
// Note that this is done for both executables and dynamic libraries. We
1161+
// won't get much benefit from dylibs because LLVM will have already
1162+
// stripped away as much as it could. This has not been seen to impact
1163+
// link times negatively.
1164+
args.push("-Wl,-dead_strip".to_owned());
11531165
}
11541166

11551167
if sess.targ_cfg.os == abi::OsWin32 {

0 commit comments

Comments
 (0)