Skip to content

Commit d351805

Browse files
committed
Auto merge of #49212 - kyrias:strip-debug-no-debuginfo, r=michaelwoerister
Pass --strip-debug to GccLinker when building without debuginfo C.f. #46034 --- This brings a hello-world built by passing rustc no command line options from 2.9M to 592K on Linux. (This might need to special case MacOS or Windows, not sure if the linkers there support `--strip-debug`, and there is an annoying lack of dependable docs for the linkers there.)
2 parents 482a913 + 2f0dd4a commit d351805

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12941294
"format compiler diagnostics in a way that's better suitable for UI testing"),
12951295
embed_bitcode: bool = (false, parse_bool, [TRACKED],
12961296
"embed LLVM bitcode in object files"),
1297+
strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
1298+
"tell the linker to strip debuginfo when building without debuginfo enabled."),
12971299
}
12981300

12991301
pub fn default_lib_output() -> CrateType {

src/librustc_trans/back/linker.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,18 @@ impl<'a> Linker for GccLinker<'a> {
281281
}
282282

283283
fn debuginfo(&mut self) {
284-
// Don't do anything special here for GNU-style linkers.
284+
match self.sess.opts.debuginfo {
285+
DebugInfoLevel::NoDebugInfo => {
286+
// If we are building without debuginfo enabled and we were called with
287+
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
288+
// found when linking to get rid of symbols from libstd.
289+
match self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
290+
Some(true) => { self.linker_arg("-S"); },
291+
_ => {},
292+
}
293+
},
294+
_ => {},
295+
};
285296
}
286297

287298
fn no_default_libraries(&mut self) {

0 commit comments

Comments
 (0)