Skip to content

Commit a1d1618

Browse files
authored
Rollup merge of rust-lang#102418 - citrus-it:illumos-strip-debug, r=nagisa
The illumos linker does not support --strip-debug When building and testing rust 1.64.0 on illumos, we saw a large number of failing tests associated with: ``` = note: ld: fatal: unrecognized option '--strip-debug' ld: fatal: use the -z help option for usage information collect2: error: ld returned 1 exit status ``` The illumos linker does not support the `--strip-debug` option (although it does support `--strip-all`).
2 parents c79429d + f8a3dc4 commit a1d1618

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
@@ -1033,16 +1033,30 @@ fn link_natively<'a>(
10331033

10341034
if sess.target.is_like_osx {
10351035
match (strip, crate_type) {
1036-
(Strip::Debuginfo, _) => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
1036+
(Strip::Debuginfo, _) => strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-S")),
10371037
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
10381038
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
1039-
strip_symbols_in_osx(sess, &out_filename, Some("-x"))
1039+
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-x"))
10401040
}
1041-
(Strip::Symbols, _) => strip_symbols_in_osx(sess, &out_filename, None),
1041+
(Strip::Symbols, _) => strip_symbols_with_external_utility(sess, "strip", &out_filename, None),
10421042
(Strip::None, _) => {}
10431043
}
10441044
}
10451045

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

@@ -1054,8 +1068,8 @@ fn strip_value(sess: &Session) -> Strip {
10541068
}
10551069
}
10561070

1057-
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
1058-
let mut cmd = Command::new("strip");
1071+
fn strip_symbols_with_external_utility<'a>(sess: &'a Session, util: &str, out_filename: &Path, option: Option<&str>) {
1072+
let mut cmd = Command::new(util);
10591073
if let Some(option) = option {
10601074
cmd.arg(option);
10611075
}
@@ -1066,14 +1080,14 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Opti
10661080
let mut output = prog.stderr.clone();
10671081
output.extend_from_slice(&prog.stdout);
10681082
sess.struct_warn(&format!(
1069-
"stripping debug info with `strip` failed: {}",
1070-
prog.status
1083+
"stripping debug info with `{}` failed: {}",
1084+
util, prog.status
10711085
))
10721086
.note(&escape_string(&output))
10731087
.emit();
10741088
}
10751089
}
1076-
Err(e) => sess.fatal(&format!("unable to run `strip`: {}", e)),
1090+
Err(e) => sess.fatal(&format!("unable to run `{}`: {}", util, e)),
10771091
}
10781092
}
10791093

compiler/rustc_codegen_ssa/src/back/linker.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,13 @@ impl<'a> Linker for GccLinker<'a> {
609609
match strip {
610610
Strip::None => {}
611611
Strip::Debuginfo => {
612-
self.linker_arg("--strip-debug");
612+
// The illumos linker does not support --strip-debug although
613+
// it does support --strip-all as a compatibility alias for -s.
614+
// The --strip-debug case is handled by running an external
615+
// `strip` utility as a separate step after linking.
616+
if self.sess.target.os != "illumos" {
617+
self.linker_arg("--strip-debug");
618+
}
613619
}
614620
Strip::Symbols => {
615621
self.linker_arg("--strip-all");

0 commit comments

Comments
 (0)