Skip to content

Commit 89cd82d

Browse files
committed
codegen_ssa: use llvm-objcopy for macOS strip
1 parent 3985715 commit 89cd82d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not imp
22
33
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
44
5+
codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to AIX which is not guaranteed to work
6+
57
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
68
79
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}

compiler/rustc_codegen_ssa/src/back/link.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,7 @@ fn link_natively(
10871087
let strip = sess.opts.cg.strip;
10881088

10891089
if sess.target.is_like_osx {
1090-
// Use system `strip` when running on host macOS.
1091-
// <https://github.com/rust-lang/rust/pull/130781>
1092-
let stripcmd = if cfg!(target_os = "macos") { "/usr/bin/strip" } else { "strip" };
1090+
let stripcmd = "rust-objcopy";
10931091
match (strip, crate_type) {
10941092
(Strip::Debuginfo, _) => {
10951093
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-S"))
@@ -1105,11 +1103,14 @@ fn link_natively(
11051103
}
11061104
}
11071105

1108-
if sess.target.os == "illumos" {
1106+
if sess.target.is_like_solaris {
11091107
// Many illumos systems will have both the native 'strip' utility and
11101108
// the GNU one. Use the native version explicitly and do not rely on
11111109
// what's in the path.
1112-
let stripcmd = "/usr/bin/strip";
1110+
//
1111+
// If cross-compiling and there is not a native version, then use
1112+
// `llvm-strip` and hope.
1113+
let stripcmd = if !sess.host.is_like_solaris { "rust-objcopy" } else { "/usr/bin/strip" };
11131114
match strip {
11141115
// Always preserve the symbol table (-x).
11151116
Strip::Debuginfo => {
@@ -1122,6 +1123,10 @@ fn link_natively(
11221123
}
11231124

11241125
if sess.target.is_like_aix {
1126+
// `llvm-strip` doesn't work for AIX - their strip must be used.
1127+
if !sess.host.is_like_aix {
1128+
sess.dcx().emit_warn(errors::AixStripNotUsed);
1129+
}
11251130
let stripcmd = "/usr/bin/strip";
11261131
match strip {
11271132
Strip::Debuginfo => {
@@ -1149,6 +1154,13 @@ fn strip_symbols_with_external_utility(
11491154
if let Some(option) = option {
11501155
cmd.arg(option);
11511156
}
1157+
1158+
let mut new_path = sess.get_tools_search_paths(false);
1159+
if let Some(path) = env::var_os("PATH") {
1160+
new_path.extend(env::split_paths(&path));
1161+
}
1162+
cmd.env("PATH", env::join_paths(new_path).unwrap());
1163+
11521164
let prog = cmd.arg(out_filename).output();
11531165
match prog {
11541166
Ok(prog) => {

compiler/rustc_codegen_ssa/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1092,3 +1092,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
10921092
diag
10931093
}
10941094
}
1095+
1096+
#[derive(Diagnostic)]
1097+
#[diag(codegen_ssa_aix_strip_not_used)]
1098+
pub(crate) struct AixStripNotUsed;

0 commit comments

Comments
 (0)