Skip to content

Commit e35b7bb

Browse files
committed
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.)
1 parent c4884bb commit e35b7bb

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1034,15 +1034,25 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
10341034
SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
10351035
}
10361036

1037+
let strip = strip_value(sess);
1038+
10371039
if sess.target.is_like_osx {
1038-
match sess.opts.debugging_opts.strip {
1040+
match strip {
10391041
Strip::Debuginfo => strip_symbols_in_osx(sess, &out_filename, Some("-S")),
10401042
Strip::Symbols => strip_symbols_in_osx(sess, &out_filename, None),
10411043
Strip::None => {}
10421044
}
10431045
}
10441046
}
10451047

1048+
// Temporarily support both -Z strip and -C strip
1049+
fn strip_value(sess: &Session) -> Strip {
1050+
match (sess.opts.debugging_opts.strip, sess.opts.cg.strip) {
1051+
(s, Strip::None) => s,
1052+
(_, s) => s,
1053+
}
1054+
}
1055+
10461056
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Option<&str>) {
10471057
let mut cmd = Command::new("strip");
10481058
if let Some(option) = option {
@@ -2014,7 +2024,7 @@ fn add_order_independent_options(
20142024
cmd.optimize();
20152025

20162026
// Pass debuginfo and strip flags down to the linker.
2017-
cmd.debuginfo(sess.opts.debugging_opts.strip);
2027+
cmd.debuginfo(strip_value(sess));
20182028

20192029
// We want to prevent the compiler from accidentally leaking in any system libraries,
20202030
// so by default we tell linkers not to link to any default libraries.

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ fn test_codegen_options_tracking_hash() {
551551
untracked!(remark, Passes::Some(vec![String::from("pass1"), String::from("pass2")]));
552552
untracked!(rpath, true);
553553
untracked!(save_temps, true);
554+
untracked!(strip, Strip::Debuginfo);
554555

555556
macro_rules! tracked {
556557
($name: ident, $non_default_value: expr) => {
@@ -684,7 +685,6 @@ fn test_debugging_options_tracking_hash() {
684685
untracked!(self_profile_events, Some(vec![String::new()]));
685686
untracked!(span_debug, true);
686687
untracked!(span_free_formats, true);
687-
untracked!(strip, Strip::Debuginfo);
688688
untracked!(temps_dir, Some(String::from("abc")));
689689
untracked!(terminal_width, Some(80));
690690
untracked!(threads, 99);

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::iter::{self, FromIterator};
3737
use std::path::{Path, PathBuf};
3838
use std::str::{self, FromStr};
3939

40-
/// The different settings that the `-Z strip` flag can have.
40+
/// The different settings that the `-C strip` flag can have.
4141
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
4242
pub enum Strip {
4343
/// Do not strip at all.

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ options! {
10151015
"use soft float ABI (*eabihf targets only) (default: no)"),
10161016
split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
10171017
"how to handle split-debuginfo, a platform-specific option"),
1018+
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1019+
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
10181020
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
10191021
"select target processor (`rustc --print target-cpus` for details)"),
10201022
target_feature: String = (String::new(), parse_target_feature, [TRACKED],

src/doc/rustc/src/codegen-options/index.md

+16
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,22 @@ platforms. Possible values are:
525525
Note that `packed` and `unpacked` are gated behind `-Z unstable-options` on
526526
non-macOS platforms at this time.
527527

528+
## strip
529+
530+
The option `-C strip=val` controls stripping of debuginfo and similar auxiliary
531+
data from binaries during linking.
532+
533+
Supported values for this option are:
534+
535+
- `none` - debuginfo and symbols (if they exist) are copied to the produced
536+
binary or separate files depending on the target (e.g. `.pdb` files in case
537+
of MSVC).
538+
- `debuginfo` - debuginfo sections and debuginfo symbols from the symbol table
539+
section are stripped at link time and are not copied to the produced binary
540+
or separate files.
541+
- `symbols` - same as `debuginfo`, but the rest of the symbol table section is
542+
stripped as well if the linker supports it.
543+
528544
## target-cpu
529545

530546
This instructs `rustc` to generate code specifically for a particular processor.

src/doc/unstable-book/src/compiler-flags/strip.md

-17
This file was deleted.

0 commit comments

Comments
 (0)