about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-28 13:20:08 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-28 13:20:08 -0700
commitedd8bb0aa191abcb5f8a3d6a6b03740907c6c54e (patch)
tree2e871ab25b5c06f3d100fd0508c82220c8d80348 /src
parentff25d62165cbd74e98c569aa74feedbb3ca181e3 (diff)
downloadrust-edd8bb0aa191abcb5f8a3d6a6b03740907c6c54e.tar.gz
rust-edd8bb0aa191abcb5f8a3d6a6b03740907c6c54e.zip
rustc: Pass -dead_strip on OSX
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/back/link.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 44fb8dbb4ce..9ad4a8795e2 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -1150,6 +1150,18 @@ fn link_args(sess: &Session,
            sess.opts.optimize == session::Aggressive {
             args.push("-Wl,-O1".to_owned());
         }
+    } else if sess.targ_cfg.os == abi::OsMacos {
+        // The dead_strip option to the linker specifies that functions and data
+        // unreachable by the entry point will be removed. This is quite useful
+        // with Rust's compilation model of compiling libraries at a time into
+        // one object file. For example, this brings hello world from 1.7MB to
+        // 458K.
+        //
+        // Note that this is done for both executables and dynamic libraries. We
+        // won't get much benefit from dylibs because LLVM will have already
+        // stripped away as much as it could. This has not been seen to impact
+        // link times negatively.
+        args.push("-Wl,-dead_strip".to_owned());
     }
 
     if sess.targ_cfg.os == abi::OsWin32 {