Skip to content

Commit

Permalink
Rollup merge of #97991 - davidkna:fix-macos-strip, r=joshtriplett
Browse files Browse the repository at this point in the history
Use safer `strip=symbols`-flag for dylibs on macOS

Closes #93988

To safely strip dylibs on macOS, the `-x` flag is needed per the manpage (see the discussion here: #93988 (comment)).

Thus, when the current `crate_type` is producing a dylib (I assume this is the case for proc macros) use the `-x` flag instead of bare `strip` for `strip=symbols`.
  • Loading branch information
Dylan-DPC authored Jun 12, 2022
2 parents cf3c41a + 8558b35 commit 265e0f0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
let strip = strip_value(sess);

if sess.target.is_like_osx {
match strip {
Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
Strip::None => {}
match (strip, crate_type) {
(Strip::Debuginfo, _) => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
strip_symbols_in_osx(sess, &out_filename, Some("-x"))
}
(Strip::Symbols, _) => strip_symbols_in_osx(sess, &out_filename, None),
(Strip::None, _) => {}
}
}
}
Expand Down

0 comments on commit 265e0f0

Please sign in to comment.