Skip to content

Commit a24a020

Browse files
committed
Auto merge of #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 e94827e + f3deac2 commit a24a020

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,36 @@ fn link_natively<'a>(
10111011

10121012
if sess.target.is_like_osx {
10131013
match (strip, crate_type) {
1014-
(Strip::Debuginfo, _) => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
1014+
(Strip::Debuginfo, _) => {
1015+
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-S"))
1016+
}
10151017
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
10161018
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
1017-
strip_symbols_in_osx(sess, &out_filename, Some("-x"))
1019+
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-x"))
1020+
}
1021+
(Strip::Symbols, _) => {
1022+
strip_symbols_with_external_utility(sess, "strip", &out_filename, None)
10181023
}
1019-
(Strip::Symbols, _) => strip_symbols_in_osx(sess, &out_filename, None),
10201024
(Strip::None, _) => {}
10211025
}
10221026
}
10231027

1028+
if sess.target.os == "illumos" {
1029+
// Many illumos systems will have both the native 'strip' utility and
1030+
// the GNU one. Use the native version explicitly and do not rely on
1031+
// what's in the path.
1032+
let stripcmd = "/usr/bin/strip";
1033+
match strip {
1034+
// Always preserve the symbol table (-x).
1035+
Strip::Debuginfo => {
1036+
strip_symbols_with_external_utility(sess, stripcmd, &out_filename, Some("-x"))
1037+
}
1038+
// Strip::Symbols is handled via the --strip-all linker option.
1039+
Strip::Symbols => {}
1040+
Strip::None => {}
1041+
}
1042+
}
1043+
10241044
Ok(())
10251045
}
10261046

@@ -1032,8 +1052,13 @@ fn strip_value(sess: &Session) -> Strip {
10321052
}
10331053
}
10341054

1035-
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
1036-
let mut cmd = Command::new("strip");
1055+
fn strip_symbols_with_external_utility<'a>(
1056+
sess: &'a Session,
1057+
util: &str,
1058+
out_filename: &Path,
1059+
option: Option<&str>,
1060+
) {
1061+
let mut cmd = Command::new(util);
10371062
if let Some(option) = option {
10381063
cmd.arg(option);
10391064
}
@@ -1044,14 +1069,14 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Opti
10441069
let mut output = prog.stderr.clone();
10451070
output.extend_from_slice(&prog.stdout);
10461071
sess.struct_warn(&format!(
1047-
"stripping debug info with `strip` failed: {}",
1048-
prog.status
1072+
"stripping debug info with `{}` failed: {}",
1073+
util, prog.status
10491074
))
10501075
.note(&escape_string(&output))
10511076
.emit();
10521077
}
10531078
}
1054-
Err(e) => sess.fatal(&format!("unable to run `strip`: {}", e)),
1079+
Err(e) => sess.fatal(&format!("unable to run `{}`: {}", util, e)),
10551080
}
10561081
}
10571082

compiler/rustc_codegen_ssa/src/back/linker.rs

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

0 commit comments

Comments
 (0)