Skip to content

Commit f745467

Browse files
committed
codegen_ssa: use llvm-objcopy for macOS strip
1 parent d8ab230 commit f745467

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_deployment_target_invalid =
68
failed to parse deployment target specified in {$env_var}: {$error}
79

compiler/rustc_codegen_ssa/src/back/link.rs

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

10871087
if sess.target.is_like_osx {
1088-
// Use system `strip` when running on host macOS.
1089-
// <https://github.com/rust-lang/rust/pull/130781>
1090-
let stripcmd = if cfg!(target_os = "macos") { "/usr/bin/strip" } else { "strip" };
1088+
let stripcmd = "rust-objcopy";
10911089
match (strip, crate_type) {
10921090
(Strip::Debuginfo, _) => {
10931091
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-S"))
@@ -1103,11 +1101,14 @@ fn link_natively(
11031101
}
11041102
}
11051103

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

11221123
if sess.target.is_like_aix {
1124+
// `llvm-strip` doesn't work for AIX - their strip must be used.
1125+
if !sess.host.is_like_aix {
1126+
sess.dcx().emit_warn(errors::AixStripNotUsed);
1127+
}
11231128
let stripcmd = "/usr/bin/strip";
11241129
match strip {
11251130
Strip::Debuginfo => {
@@ -1147,6 +1152,13 @@ fn strip_symbols_with_external_utility(
11471152
if let Some(option) = option {
11481153
cmd.arg(option);
11491154
}
1155+
1156+
let mut new_path = sess.get_tools_search_paths(false);
1157+
if let Some(path) = env::var_os("PATH") {
1158+
new_path.extend(env::split_paths(&path));
1159+
}
1160+
cmd.env("PATH", env::join_paths(new_path).unwrap());
1161+
11501162
let prog = cmd.arg(out_filename).output();
11511163
match prog {
11521164
Ok(prog) => {

compiler/rustc_codegen_ssa/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1101,3 +1101,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
11011101
diag
11021102
}
11031103
}
1104+
1105+
#[derive(Diagnostic)]
1106+
#[diag(codegen_ssa_aix_strip_not_used)]
1107+
pub(crate) struct AixStripNotUsed;

0 commit comments

Comments
 (0)