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.)
This commit is contained in:
bors 2018-03-25 21:46:15 +00:00
commit d3518058e2
2 changed files with 14 additions and 1 deletions

View File

@ -1294,6 +1294,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"format compiler diagnostics in a way that's better suitable for UI testing"),
embed_bitcode: bool = (false, parse_bool, [TRACKED],
"embed LLVM bitcode in object files"),
strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
"tell the linker to strip debuginfo when building without debuginfo enabled."),
}
pub fn default_lib_output() -> CrateType {

View File

@ -281,7 +281,18 @@ impl<'a> Linker for GccLinker<'a> {
}
fn debuginfo(&mut self) {
// Don't do anything special here for GNU-style linkers.
match self.sess.opts.debuginfo {
DebugInfoLevel::NoDebugInfo => {
// If we are building without debuginfo enabled and we were called with
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
// found when linking to get rid of symbols from libstd.
match self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
Some(true) => { self.linker_arg("-S"); },
_ => {},
}
},
_ => {},
};
}
fn no_default_libraries(&mut self) {