about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2021-10-21 13:19:46 +0200
committerJosh Triplett <josh@joshtriplett.org>2021-11-15 10:21:02 +0100
commite35b7bbdf8bf9939be5bcbaef781b95e8c93b6e1 (patch)
tree7c8df211c6c273d8ca05ccff2904cc2e1e02241b
parentc4884bbec7ae6ba06211a2769271b8db38c8284b (diff)
downloadrust-e35b7bbdf8bf9939be5bcbaef781b95e8c93b6e1.tar.gz
rust-e35b7bbdf8bf9939be5bcbaef781b95e8c93b6e1.zip
Stabilize -Z strip as -C strip
Leave -Z strip available temporarily as an alias, to avoid breaking
cargo until cargo transitions to using -C strip. (If the user passes
both, the -C version wins.)
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs14
-rw-r--r--compiler/rustc_interface/src/tests.rs2
-rw-r--r--compiler/rustc_session/src/config.rs2
-rw-r--r--compiler/rustc_session/src/options.rs2
-rw-r--r--src/doc/rustc/src/codegen-options/index.md16
-rw-r--r--src/doc/unstable-book/src/compiler-flags/strip.md17
6 files changed, 32 insertions, 21 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 1ba0c4fa05b..638b2a7b5a9 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1034,8 +1034,10 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
         SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
     }
 
+    let strip = strip_value(sess);
+
     if sess.target.is_like_osx {
-        match sess.opts.debugging_opts.strip {
+        match strip {
             Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
             Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
             Strip::None => {}
@@ -1043,6 +1045,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
     }
 }
 
+// Temporarily support both -Z strip and -C strip
+fn strip_value(sess: &Session) -> Strip {
+    match (sess.opts.debugging_opts.strip, sess.opts.cg.strip) {
+        (s, Strip::None) => s,
+        (_, s) => s,
+    }
+}
+
 fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
     let mut cmd = Command::new("strip");
     if let Some(option) = option {
@@ -2014,7 +2024,7 @@ fn add_order_independent_options(
     cmd.optimize();
 
     // Pass debuginfo and strip flags down to the linker.
-    cmd.debuginfo(sess.opts.debugging_opts.strip);
+    cmd.debuginfo(strip_value(sess));
 
     // We want to prevent the compiler from accidentally leaking in any system libraries,
     // so by default we tell linkers not to link to any default libraries.
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index eed2e07e890..6b666d7c292 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -551,6 +551,7 @@ fn test_codegen_options_tracking_hash() {
     untracked!(remark, Passes::Some(vec![String::from("pass1"), String::from("pass2")]));
     untracked!(rpath, true);
     untracked!(save_temps, true);
+    untracked!(strip, Strip::Debuginfo);
 
     macro_rules! tracked {
         ($name: ident, $non_default_value: expr) => {
@@ -684,7 +685,6 @@ fn test_debugging_options_tracking_hash() {
     untracked!(self_profile_events, Some(vec![String::new()]));
     untracked!(span_debug, true);
     untracked!(span_free_formats, true);
-    untracked!(strip, Strip::Debuginfo);
     untracked!(temps_dir, Some(String::from("abc")));
     untracked!(terminal_width, Some(80));
     untracked!(threads, 99);
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index 3afe0947339..5e6bbe03918 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -37,7 +37,7 @@ use std::iter::{self, FromIterator};
 use std::path::{Path, PathBuf};
 use std::str::{self, FromStr};
 
-/// The different settings that the `-Z strip` flag can have.
+/// The different settings that the `-C strip` flag can have.
 #[derive(Clone, Copy, PartialEq, Hash, Debug)]
 pub enum Strip {
     /// Do not strip at all.
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 8b9ec5028d1..3f279a045f1 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -1015,6 +1015,8 @@ options! {
         "use soft float ABI (*eabihf targets only) (default: no)"),
     split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
         "how to handle split-debuginfo, a platform-specific option"),
+    strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
+        "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
     target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
         "select target processor (`rustc --print target-cpus` for details)"),
     target_feature: String = (String::new(), parse_target_feature, [TRACKED],
diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md
index 4f8c4c66f88..0201b88417a 100644
--- a/src/doc/rustc/src/codegen-options/index.md
+++ b/src/doc/rustc/src/codegen-options/index.md
@@ -525,6 +525,22 @@ platforms. Possible values are:
 Note that `packed` and `unpacked` are gated behind `-Z unstable-options` on
 non-macOS platforms at this time.
 
+## strip
+
+The option `-C strip=val` controls stripping of debuginfo and similar auxiliary
+data from binaries during linking.
+
+Supported values for this option are:
+
+- `none` - debuginfo and symbols (if they exist) are copied to the produced
+  binary or separate files depending on the target (e.g. `.pdb` files in case
+  of MSVC).
+- `debuginfo` - debuginfo sections and debuginfo symbols from the symbol table
+  section are stripped at link time and are not copied to the produced binary
+  or separate files.
+- `symbols` - same as `debuginfo`, but the rest of the symbol table section is
+  stripped as well if the linker supports it.
+
 ## target-cpu
 
 This instructs `rustc` to generate code specifically for a particular processor.
diff --git a/src/doc/unstable-book/src/compiler-flags/strip.md b/src/doc/unstable-book/src/compiler-flags/strip.md
deleted file mode 100644
index 52cb98113c0..00000000000
--- a/src/doc/unstable-book/src/compiler-flags/strip.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# `strip`
-
-The tracking issue for this feature is: [#72110](https://github.com/rust-lang/rust/issues/72110).
-
-------------------------
-
-Option `-Z strip=val` controls stripping of debuginfo and similar auxiliary data from binaries
-during linking.
-
-Supported values for this option are:
-
-- `none` - debuginfo and symbols (if they exist) are copied to the produced binary or separate files
-depending on the target (e.g. `.pdb` files in case of MSVC).
-- `debuginfo` - debuginfo sections and debuginfo symbols from the symbol table section
-are stripped at link time and are not copied to the produced binary or separate files.
-- `symbols` - same as `debuginfo`, but the rest of the symbol table section is stripped as well
-if the linker supports it.