Skip to content

Commit 2f0dd4a

Browse files
committedMar 24, 2018
Add flag for telling the linker to strip debuginfo when building without it
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
1 parent b4aa80d commit 2f0dd4a

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
@@ -1292,6 +1292,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12921292
"format compiler diagnostics in a way that's better suitable for UI testing"),
12931293
embed_bitcode: bool = (false, parse_bool, [TRACKED],
12941294
"embed LLVM bitcode in object files"),
1295+
strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
1296+
"tell the linker to strip debuginfo when building without debuginfo enabled."),
12951297
}
12961298

12971299
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)