Skip to content

Commit cbb561f

Browse files
Rollup merge of rust-lang#88137 - joshtriplett:osx-strip-symbols-no-option, r=michaelwoerister
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.
2 parents 6c2d4bf + ff697c6 commit cbb561f

File tree

1 file changed

+10
-12
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+10
-12
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1024,14 +1024,20 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
10241024
}
10251025

10261026
if sess.target.is_like_osx {
1027-
if let Some(option) = osx_strip_opt(sess.opts.debugging_opts.strip) {
1028-
strip_symbols_in_osx(sess, &out_filename, option);
1027+
match sess.opts.debugging_opts.strip {
1028+
Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
1029+
Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
1030+
Strip::None => {}
10291031
}
10301032
}
10311033
}
10321034

1033-
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str) {
1034-
let prog = Command::new("strip").arg(option).arg(out_filename).output();
1035+
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
1036+
let mut cmd = Command::new("strip");
1037+
if let Some(option) = option {
1038+
cmd.arg(option);
1039+
}
1040+
let prog = cmd.arg(out_filename).output();
10351041
match prog {
10361042
Ok(prog) => {
10371043
if !prog.status.success() {
@@ -1049,14 +1055,6 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str
10491055
}
10501056
}
10511057

1052-
fn osx_strip_opt<'a>(strip: Strip) -> Option<&'a str> {
1053-
match strip {
1054-
Strip::Debuginfo => Some("-S"),
1055-
Strip::Symbols => Some("-x"),
1056-
Strip::None => None,
1057-
}
1058-
}
1059-
10601058
fn escape_string(s: &[u8]) -> String {
10611059
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
10621060
let mut x = "Non-UTF-8 output: ".to_string();

0 commit comments

Comments
 (0)