Skip to content

Pass --strip-debug to GccLinker when building without debuginfo #49212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,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 {
Expand Down
13 changes: 12 additions & 1 deletion src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down