Skip to content

Commit a0dc4ab

Browse files
authored
Rollup merge of #90058 - joshtriplett:stabilize-strip, r=wesleywiser
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.
2 parents c44455a + e35b7bb commit a0dc4ab

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
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

+10-6
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ top_level_options!(
219219
/// generated code to parse an option into its respective field in the struct. There are a few
220220
/// hand-written parsers for parsing specific types of values in this module.
221221
macro_rules! options {
222-
($struct_name:ident, $stat:ident, $prefix:expr, $outputname:expr,
222+
($struct_name:ident, $stat:ident, $optmod:ident, $prefix:expr, $outputname:expr,
223223
$($( #[$attr:meta] )* $opt:ident : $t:ty = (
224224
$init:expr,
225225
$parse:ident,
@@ -264,13 +264,15 @@ macro_rules! options {
264264
}
265265

266266
pub const $stat: OptionDescrs<$struct_name> =
267-
&[ $( (stringify!($opt), $opt, desc::$parse, $desc) ),* ];
267+
&[ $( (stringify!($opt), $optmod::$opt, desc::$parse, $desc) ),* ];
268268

269+
mod $optmod {
269270
$(
270-
fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
271-
parse::$parse(&mut redirect_field!(cg.$opt), v)
271+
pub(super) fn $opt(cg: &mut super::$struct_name, v: Option<&str>) -> bool {
272+
super::parse::$parse(&mut redirect_field!(cg.$opt), v)
272273
}
273274
)*
275+
}
274276

275277
) }
276278

@@ -918,7 +920,7 @@ mod parse {
918920
}
919921

920922
options! {
921-
CodegenOptions, CG_OPTIONS, "C", "codegen",
923+
CodegenOptions, CG_OPTIONS, cgopts, "C", "codegen",
922924

923925
// This list is in alphabetical order.
924926
//
@@ -1013,6 +1015,8 @@ options! {
10131015
"use soft float ABI (*eabihf targets only) (default: no)"),
10141016
split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
10151017
"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`)"),
10161020
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
10171021
"select target processor (`rustc --print target-cpus` for details)"),
10181022
target_feature: String = (String::new(), parse_target_feature, [TRACKED],
@@ -1027,7 +1031,7 @@ options! {
10271031
}
10281032

10291033
options! {
1030-
DebuggingOptions, DB_OPTIONS, "Z", "debugging",
1034+
DebuggingOptions, DB_OPTIONS, dbopts, "Z", "debugging",
10311035

10321036
// This list is in alphabetical order.
10331037
//

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)