Skip to content

Commit f8a3dc4

Browse files
committed
The illumos linker does not support --strip-debug
1 parent 09ae784 commit f8a3dc4

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1034,16 +1034,30 @@ fn link_natively<'a>(
10341034

10351035
if sess.target.is_like_osx {
10361036
match (strip, crate_type) {
1037-
(Strip::Debuginfo, _) => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
1037+
(Strip::Debuginfo, _) => strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-S")),
10381038
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
10391039
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
1040-
strip_symbols_in_osx(sess, &out_filename, Some("-x"))
1040+
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-x"))
10411041
}
1042-
(Strip::Symbols, _) => strip_symbols_in_osx(sess, &out_filename, None),
1042+
(Strip::Symbols, _) => strip_symbols_with_external_utility(sess, "strip", &out_filename, None),
10431043
(Strip::None, _) => {}
10441044
}
10451045
}
10461046

1047+
if sess.target.os == "illumos" {
1048+
// Many illumos systems will have both the native 'strip' utility and
1049+
// the GNU one. Use the native version explicitly and do not rely on
1050+
// what's in the path.
1051+
let stripcmd = "/usr/bin/strip";
1052+
match strip {
1053+
// Always preserve the symbol table (-x).
1054+
Strip::Debuginfo => strip_symbols_with_external_utility(sess, stripcmd, &out_filename, Some("-x")),
1055+
// Strip::Symbols is handled via the --strip-all linker option.
1056+
Strip::Symbols => {},
1057+
Strip::None => {}
1058+
}
1059+
}
1060+
10471061
Ok(())
10481062
}
10491063

@@ -1055,8 +1069,8 @@ fn strip_value(sess: &Session) -> Strip {
10551069
}
10561070
}
10571071

1058-
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
1059-
let mut cmd = Command::new("strip");
1072+
fn strip_symbols_with_external_utility<'a>(sess: &'a Session, util: &str, out_filename: &Path, option: Option<&str>) {
1073+
let mut cmd = Command::new(util);
10601074
if let Some(option) = option {
10611075
cmd.arg(option);
10621076
}
@@ -1067,14 +1081,14 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Opti
10671081
let mut output = prog.stderr.clone();
10681082
output.extend_from_slice(&prog.stdout);
10691083
sess.struct_warn(&format!(
1070-
"stripping debug info with `strip` failed: {}",
1071-
prog.status
1084+
"stripping debug info with `{}` failed: {}",
1085+
util, prog.status
10721086
))
10731087
.note(&escape_string(&output))
10741088
.emit();
10751089
}
10761090
}
1077-
Err(e) => sess.fatal(&format!("unable to run `strip`: {}", e)),
1091+
Err(e) => sess.fatal(&format!("unable to run `{}`: {}", util, e)),
10781092
}
10791093
}
10801094

compiler/rustc_codegen_ssa/src/back/linker.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,13 @@ impl<'a> Linker for GccLinker<'a> {
617617
match strip {
618618
Strip::None => {}
619619
Strip::Debuginfo => {
620-
self.linker_arg("--strip-debug");
620+
// The illumos linker does not support --strip-debug although
621+
// it does support --strip-all as a compatibility alias for -s.
622+
// The --strip-debug case is handled by running an external
623+
// `strip` utility as a separate step after linking.
624+
if self.sess.target.os != "illumos" {
625+
self.linker_arg("--strip-debug");
626+
}
621627
}
622628
Strip::Symbols => {
623629
self.linker_arg("--strip-all");

0 commit comments

Comments
 (0)