diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2021-08-18 05:11:26 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2021-08-18 05:11:26 -0700 |
| commit | ff697c613c2fa52819a045fb82b7cb3daa45c1f6 (patch) | |
| tree | 829d9b3079564bc48386a2162f6b850af23a529c /compiler/rustc_codegen_ssa | |
| parent | 896f058f13d6c8021f7637817953a44d3a78be32 (diff) | |
| download | rust-ff697c613c2fa52819a045fb82b7cb3daa45c1f6.tar.gz rust-ff697c613c2fa52819a045fb82b7cb3daa45c1f6.zip | |
On macOS, make strip="symbols" not pass any options to strip
This makes the output with `strip="symbols"` match the result of just calling `strip` on the output binary, minimizing the size of the binary.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f3eb1e04d07..aed057ffcf6 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -977,14 +977,20 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( } if sess.target.is_like_osx { - if let Some(option) = osx_strip_opt(sess.opts.debugging_opts.strip) { - strip_symbols_in_osx(sess, &out_filename, option); + match sess.opts.debugging_opts.strip { + Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")), + Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None), + Strip::None => {} } } } -fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str) { - let prog = Command::new("strip").arg(option).arg(out_filename).output(); +fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) { + let mut cmd = Command::new("strip"); + if let Some(option) = option { + cmd.arg(option); + } + let prog = cmd.arg(out_filename).output(); match prog { Ok(prog) => { if !prog.status.success() { @@ -1002,14 +1008,6 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str } } -fn osx_strip_opt<'a>(strip: Strip) -> Option<&'a str> { - match strip { - Strip::Debuginfo => Some("-S"), - Strip::Symbols => Some("-x"), - Strip::None => None, - } -} - fn escape_string(s: &[u8]) -> String { str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| { let mut x = "Non-UTF-8 output: ".to_string(); |
