about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2018-03-20 16:23:31 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2018-03-24 22:54:47 +0100
commit2f0dd4a8f0717bc50430817552cd8c9890fc60aa (patch)
tree92264394f92790c8183da4198b0e23eb3219914c
parentb4aa80dd73df9708022cc383aad8da1dcf38d1df (diff)
Add flag for telling the linker to strip debuginfo when building without it
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
-rw-r--r--src/librustc/session/config.rs2
-rw-r--r--src/librustc_trans/back/linker.rs13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index d24da1ff7c8..4203985136a 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -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 {
diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs
index 9bd7d83a191..53a9dd6a76f 100644
--- a/src/librustc_trans/back/linker.rs
+++ b/src/librustc_trans/back/linker.rs
@@ -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) {