2019-12-17 23:22:55 +11:00
use crate ::config ::* ;
use crate ::search_paths ::SearchPath ;
2021-03-24 21:45:09 -07:00
use crate ::utils ::NativeLib ;
2023-12-17 22:01:06 +11:00
use crate ::{ lint , EarlyDiagCtxt } ;
2023-11-27 13:47:26 +01:00
use rustc_data_structures ::fx ::FxIndexMap ;
2023-02-06 06:32:34 +01:00
use rustc_data_structures ::profiling ::TimePassesFormat ;
2023-10-13 17:28:34 +00:00
use rustc_data_structures ::stable_hasher ::Hash64 ;
Add a simple markdown parser for formatting `rustc --explain`
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.
This patch consists of three major components:
1. A markdown parser. This is an extremely simple non-backtracking recursive
implementation that requires normalization of the final token stream
2. A utility to write the token stream to an output buffer
3. Configuration within rustc_driver_impl to invoke this combination for
`--explain`. Like the current implementation, it first attempts to print to
a pager with a fallback colorized terminal, and standard print as a last
resort.
If color is disabled, or if the output does not support it, or if printing
with color fails, it will write the raw markdown (which matches current
behavior).
Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
and `delta`.
The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:
- Headings, including formatting
- Comments
- Code, inline and fenced block (no indented block)
- Strong, emphasis, and strikethrough formatted text
- Links, anchor, inline, and reference-style
- Horizontal rules
- Unordered and ordered list items, including formatting
This parser and writer should be reusable by other systems if ever needed.
2022-12-19 12:09:40 -06:00
use rustc_errors ::ColorConfig ;
2023-02-09 10:16:00 +00:00
use rustc_errors ::{ LanguageIdentifier , TerminalUrl } ;
2024-04-24 09:45:47 +10:00
use rustc_feature ::UnstableFeatures ;
use rustc_span ::edition ::Edition ;
use rustc_span ::RealFileName ;
use rustc_span ::SourceFileHashAlgorithm ;
2024-02-27 23:06:44 +01:00
use rustc_target ::spec ::{
2024-04-28 18:02:21 +02:00
CodeModel , LinkerFlavorCli , MergeFunctions , OnBrokenPipe , PanicStrategy , SanitizerSet , WasmCAbi ,
2024-02-27 23:06:44 +01:00
} ;
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
use rustc_target ::spec ::{
RelocModel , RelroLevel , SplitDebuginfo , StackProtector , TargetTriple , TlsModel ,
} ;
2019-12-17 23:22:55 +11:00
use std ::collections ::BTreeMap ;
2023-10-13 02:44:19 -04:00
use std ::hash ::{ DefaultHasher , Hasher } ;
2024-01-29 23:59:09 +01:00
use std ::num ::{ IntErrorKind , NonZero } ;
2019-12-17 23:22:55 +11:00
use std ::path ::PathBuf ;
use std ::str ;
2021-04-15 19:25:01 -04:00
macro_rules ! insert {
( $opt_name :ident , $opt_expr :expr , $sub_hashes :expr ) = > {
2019-12-17 23:22:55 +11:00
if $sub_hashes
. insert ( stringify! ( $opt_name ) , $opt_expr as & dyn dep_tracking ::DepTrackingHash )
. is_some ( )
{
panic! ( " duplicate key in CLI DepTrackingHash: {} " , stringify! ( $opt_name ) )
}
2021-04-15 19:25:01 -04:00
} ;
}
macro_rules ! hash_opt {
( $opt_name :ident , $opt_expr :expr , $sub_hashes :expr , $_for_crate_hash : ident , [ UNTRACKED ] ) = > { { } } ;
( $opt_name :ident , $opt_expr :expr , $sub_hashes :expr , $_for_crate_hash : ident , [ TRACKED ] ) = > { { insert! ( $opt_name , $opt_expr , $sub_hashes ) } } ;
( $opt_name :ident , $opt_expr :expr , $sub_hashes :expr , $for_crate_hash : ident , [ TRACKED_NO_CRATE_HASH ] ) = > { {
if ! $for_crate_hash {
insert! ( $opt_name , $opt_expr , $sub_hashes )
}
2019-12-17 23:22:55 +11:00
} } ;
2021-04-15 19:25:01 -04:00
( $opt_name :ident , $opt_expr :expr , $sub_hashes :expr , $_for_crate_hash : ident , [ SUBSTRUCT ] ) = > { { } } ;
}
macro_rules ! hash_substruct {
( $opt_name :ident , $opt_expr :expr , $error_format :expr , $for_crate_hash :expr , $hasher :expr , [ UNTRACKED ] ) = > { { } } ;
( $opt_name :ident , $opt_expr :expr , $error_format :expr , $for_crate_hash :expr , $hasher :expr , [ TRACKED ] ) = > { { } } ;
( $opt_name :ident , $opt_expr :expr , $error_format :expr , $for_crate_hash :expr , $hasher :expr , [ TRACKED_NO_CRATE_HASH ] ) = > { { } } ;
( $opt_name :ident , $opt_expr :expr , $error_format :expr , $for_crate_hash :expr , $hasher :expr , [ SUBSTRUCT ] ) = > {
use crate ::config ::dep_tracking ::DepTrackingHash ;
2021-06-19 19:22:14 -05:00
$opt_expr . dep_tracking_hash ( $for_crate_hash , $error_format ) . hash (
$hasher ,
$error_format ,
$for_crate_hash ,
) ;
2021-04-15 19:25:01 -04:00
} ;
2019-12-17 23:22:55 +11:00
}
macro_rules ! top_level_options {
2021-04-27 16:44:14 +00:00
( $( #[ $top_level_attr:meta ] ) * pub struct Options { $(
2021-04-27 16:25:12 +00:00
$( #[ $attr:meta ] ) *
2021-04-15 19:25:01 -04:00
$opt :ident : $t :ty [ $dep_tracking_marker :ident ] ,
2019-12-17 23:22:55 +11:00
) * } ) = > (
#[ derive(Clone) ]
2021-04-27 16:44:14 +00:00
$( #[ $top_level_attr ] ) *
2019-12-17 23:22:55 +11:00
pub struct Options {
2021-04-27 16:25:12 +00:00
$(
$( #[ $attr ] ) *
pub $opt : $t
) , *
2019-12-17 23:22:55 +11:00
}
impl Options {
2021-04-15 19:25:01 -04:00
pub fn dep_tracking_hash ( & self , for_crate_hash : bool ) -> u64 {
2019-12-17 23:22:55 +11:00
let mut sub_hashes = BTreeMap ::new ( ) ;
$( {
2021-04-15 19:25:01 -04:00
hash_opt! ( $opt ,
& self . $opt ,
& mut sub_hashes ,
for_crate_hash ,
[ $dep_tracking_marker ] ) ;
2019-12-17 23:22:55 +11:00
} ) *
let mut hasher = DefaultHasher ::new ( ) ;
dep_tracking ::stable_hash ( sub_hashes ,
& mut hasher ,
2021-06-19 19:22:14 -05:00
self . error_format ,
for_crate_hash ) ;
2021-04-15 19:25:01 -04:00
$( {
hash_substruct! ( $opt ,
& self . $opt ,
self . error_format ,
for_crate_hash ,
& mut hasher ,
[ $dep_tracking_marker ] ) ;
} ) *
2019-12-17 23:22:55 +11:00
hasher . finish ( )
}
}
) ;
}
top_level_options! (
2021-04-27 16:44:14 +00:00
/// The top-level command-line options struct.
///
/// For each option, one has to specify how it behaves with regard to the
/// dependency tracking system of incremental compilation. This is done via the
/// square-bracketed directive after the field type. The options are:
///
/// - `[TRACKED]`
/// A change in the given field will cause the compiler to completely clear the
/// incremental compilation cache before proceeding.
///
/// - `[TRACKED_NO_CRATE_HASH]`
2024-04-24 09:45:47 +10:00
/// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that
/// only affect the incremental cache.
2021-04-27 16:44:14 +00:00
///
/// - `[UNTRACKED]`
/// Incremental compilation is not influenced by this option.
///
/// - `[SUBSTRUCT]`
/// Second-level sub-structs containing more options.
///
/// If you add a new option to this struct or one of the sub-structs like
/// `CodegenOptions`, think about how it influences incremental compilation. If in
/// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
/// unnecessary re-compilation.
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_ty ]
2019-12-17 23:22:55 +11:00
pub struct Options {
2021-04-27 16:44:14 +00:00
/// The crate config requested for the session, which may be combined
/// with additional crate configurations during the compile process.
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::crate_types` instead of this field " ) ]
2019-12-17 23:22:55 +11:00
crate_types : Vec < CrateType > [ TRACKED ] ,
optimize : OptLevel [ TRACKED ] ,
2021-04-27 16:44:14 +00:00
/// Include the `debug_assertions` flag in dependency tracking, since it
/// can influence whether overflow checks are done or not.
2019-12-17 23:22:55 +11:00
debug_assertions : bool [ TRACKED ] ,
debuginfo : DebugInfo [ TRACKED ] ,
2023-07-12 17:07:34 -04:00
debuginfo_compression : DebugInfoCompression [ TRACKED ] ,
2021-07-14 16:39:17 -07:00
lint_opts : Vec < ( String , lint ::Level ) > [ TRACKED_NO_CRATE_HASH ] ,
lint_cap : Option < lint ::Level > [ TRACKED_NO_CRATE_HASH ] ,
2019-12-17 23:22:55 +11:00
describe_lints : bool [ UNTRACKED ] ,
output_types : OutputTypes [ TRACKED ] ,
search_paths : Vec < SearchPath > [ UNTRACKED ] ,
2021-03-24 21:45:09 -07:00
libs : Vec < NativeLib > [ TRACKED ] ,
2019-12-17 23:22:55 +11:00
maybe_sysroot : Option < PathBuf > [ UNTRACKED ] ,
target_triple : TargetTriple [ TRACKED ] ,
2023-11-27 13:47:26 +01:00
/// Effective logical environment used by `env!`/`option_env!` macros
logical_env : FxIndexMap < String , String > [ TRACKED ] ,
2019-12-17 23:22:55 +11:00
test : bool [ TRACKED ] ,
error_format : ErrorOutputType [ UNTRACKED ] ,
2022-07-06 11:57:41 +01:00
diagnostic_width : Option < usize > [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
2021-04-27 16:44:14 +00:00
/// If `Some`, enable incremental compilation, using the given
/// directory to store intermediate results.
2019-12-17 23:22:55 +11:00
incremental : Option < PathBuf > [ UNTRACKED ] ,
2021-10-31 17:05:48 -05:00
assert_incr_state : Option < IncrementalStateAssertion > [ UNTRACKED ] ,
2023-10-13 17:28:34 +00:00
/// Set by the `Config::hash_untracked_state` callback for custom
/// drivers to invalidate the incremental cache
#[ rustc_lint_opt_deny_field_access( " should only be used via `Config::hash_untracked_state` " ) ]
untracked_state_hash : Hash64 [ TRACKED_NO_CRATE_HASH ] ,
2019-12-17 23:22:55 +11:00
2022-07-06 07:44:47 -05:00
unstable_opts : UnstableOptions [ SUBSTRUCT ] ,
2019-12-17 23:22:55 +11:00
prints : Vec < PrintRequest > [ UNTRACKED ] ,
2021-04-15 19:25:01 -04:00
cg : CodegenOptions [ SUBSTRUCT ] ,
2019-12-17 23:22:55 +11:00
externs : Externs [ UNTRACKED ] ,
crate_name : Option < String > [ TRACKED ] ,
2021-04-27 16:44:14 +00:00
/// Indicates how the compiler should treat unstable features.
2019-12-17 23:22:55 +11:00
unstable_features : UnstableFeatures [ TRACKED ] ,
2021-04-27 16:44:14 +00:00
/// Indicates whether this run of the compiler is actually rustdoc. This
/// is currently just a hack and will be removed eventually, so please
/// try to not rely on this too much.
2019-12-17 23:22:55 +11:00
actually_rustdoc : bool [ TRACKED ] ,
2023-02-06 21:57:45 +04:00
/// Whether name resolver should resolve documentation links.
resolve_doc_links : ResolveDocLinks [ TRACKED ] ,
2019-12-17 23:22:55 +11:00
2021-04-27 16:44:14 +00:00
/// Control path trimming.
2024-01-10 12:47:22 +11:00
trimmed_def_paths : bool [ TRACKED ] ,
2020-09-02 10:40:56 +03:00
2021-04-27 16:44:14 +00:00
/// Specifications of codegen units / ThinLTO which are forced as a
/// result of parsing command line options. These are not necessarily
/// what rustc was invoked with, but massaged a bit to agree with
/// commands like `--emit llvm-ir` which they're often incompatible with
/// if we otherwise use the defaults of rustc.
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::codegen_units` instead of this field " ) ]
2019-12-17 23:22:55 +11:00
cli_forced_codegen_units : Option < usize > [ UNTRACKED ] ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::lto` instead of this field " ) ]
2022-10-26 20:28:25 -04:00
cli_forced_local_thinlto_off : bool [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
2021-04-27 16:44:14 +00:00
/// Remap source path prefixes in all output (messages, object files, debug, etc.).
2021-04-15 19:25:01 -04:00
remap_path_prefix : Vec < ( PathBuf , PathBuf ) > [ TRACKED_NO_CRATE_HASH ] ,
2021-04-27 16:25:12 +00:00
/// Base directory containing the `src/` for the Rust standard library, and
2022-10-14 00:25:34 +08:00
/// potentially `rustc` as well, if we can find it. Right now it's always
2021-04-27 16:25:12 +00:00
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
///
/// This directory is what the virtual `/rustc/$hash` is translated back to,
/// if Rust was built with path remapping to `/rustc/$hash` enabled
/// (the `rust.remap-debuginfo` option in `config.toml`).
real_rust_source_base_dir : Option < PathBuf > [ TRACKED_NO_CRATE_HASH ] ,
2019-12-17 23:22:55 +11:00
edition : Edition [ TRACKED ] ,
2021-04-27 16:44:14 +00:00
/// `true` if we're emitting JSON blobs about each artifact produced
/// by the compiler.
2019-12-17 23:22:55 +11:00
json_artifact_notifications : bool [ TRACKED ] ,
2021-04-27 16:44:14 +00:00
/// `true` if we're emitting a JSON blob containing the unused externs
2022-04-16 17:11:33 -07:00
json_unused_externs : JsonUnusedExterns [ UNTRACKED ] ,
2020-06-30 20:17:07 +02:00
2022-03-16 20:12:30 +08:00
/// `true` if we're emitting a JSON job containing a future-incompat report for lints
2021-12-04 14:34:20 -05:00
json_future_incompat : bool [ TRACKED ] ,
2019-12-17 23:22:55 +11:00
pretty : Option < PpMode > [ UNTRACKED ] ,
2021-08-12 15:30:40 -05:00
/// The (potentially remapped) working directory
working_dir : RealFileName [ TRACKED ] ,
Add a simple markdown parser for formatting `rustc --explain`
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.
This patch consists of three major components:
1. A markdown parser. This is an extremely simple non-backtracking recursive
implementation that requires normalization of the final token stream
2. A utility to write the token stream to an output buffer
3. Configuration within rustc_driver_impl to invoke this combination for
`--explain`. Like the current implementation, it first attempts to print to
a pager with a fallback colorized terminal, and standard print as a last
resort.
If color is disabled, or if the output does not support it, or if printing
with color fails, it will write the raw markdown (which matches current
behavior).
Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
and `delta`.
The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:
- Headings, including formatting
- Comments
- Code, inline and fenced block (no indented block)
- Strong, emphasis, and strikethrough formatted text
- Links, anchor, inline, and reference-style
- Horizontal rules
- Unordered and ordered list items, including formatting
This parser and writer should be reusable by other systems if ever needed.
2022-12-19 12:09:40 -06:00
color : ColorConfig [ UNTRACKED ] ,
2023-12-19 13:24:05 -05:00
2024-01-19 18:09:54 -05:00
verbose : bool [ TRACKED_NO_CRATE_HASH ] ,
2019-12-17 23:22:55 +11:00
}
) ;
/// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
/// macro is to define an interface that can be programmatically used by the option parser
/// to initialize the struct without hardcoding field names all over the place.
///
/// The goal is to invoke this macro once with the correct fields, and then this macro generates all
/// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
/// generated code to parse an option into its respective field in the struct. There are a few
/// hand-written parsers for parsing specific types of values in this module.
macro_rules ! options {
2021-10-21 13:18:59 +02:00
( $struct_name :ident , $stat :ident , $optmod :ident , $prefix :expr , $outputname :expr ,
2021-04-27 16:44:14 +00:00
$( $( #[ $attr:meta ] ) * $opt :ident : $t :ty = (
2019-12-17 23:22:55 +11:00
$init :expr ,
$parse :ident ,
2021-04-15 19:25:01 -04:00
[ $dep_tracking_marker :ident ] ,
2019-12-17 23:22:55 +11:00
$desc :expr )
) , * , ) = >
(
#[ derive(Clone) ]
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_ty ]
2022-07-25 13:02:39 +01:00
pub struct $struct_name { $( $( #[ $attr ] ) * pub $opt : $t ) , * }
2019-12-17 23:22:55 +11:00
2021-05-07 15:18:19 +03:00
impl Default for $struct_name {
fn default ( ) -> $struct_name {
2022-07-25 13:02:39 +01:00
$struct_name { $( $opt : $init ) , * }
2019-12-17 23:22:55 +11:00
}
}
2021-04-15 19:25:01 -04:00
impl $struct_name {
2021-05-07 15:18:19 +03:00
pub fn build (
2023-12-18 10:57:26 +11:00
early_dcx : & EarlyDiagCtxt ,
2021-05-07 15:18:19 +03:00
matches : & getopts ::Matches ,
) -> $struct_name {
2023-12-18 10:57:26 +11:00
build_options ( early_dcx , matches , $stat , $prefix , $outputname )
2021-05-07 15:18:19 +03:00
}
2021-06-19 19:22:14 -05:00
fn dep_tracking_hash ( & self , for_crate_hash : bool , error_format : ErrorOutputType ) -> u64 {
2019-12-17 23:22:55 +11:00
let mut sub_hashes = BTreeMap ::new ( ) ;
$( {
2021-04-15 19:25:01 -04:00
hash_opt! ( $opt ,
& self . $opt ,
& mut sub_hashes ,
2021-06-19 19:22:14 -05:00
for_crate_hash ,
2021-04-15 19:25:01 -04:00
[ $dep_tracking_marker ] ) ;
2019-12-17 23:22:55 +11:00
} ) *
2021-04-15 19:25:01 -04:00
let mut hasher = DefaultHasher ::new ( ) ;
dep_tracking ::stable_hash ( sub_hashes ,
& mut hasher ,
2021-06-19 19:22:14 -05:00
error_format ,
for_crate_hash
) ;
2021-04-15 19:25:01 -04:00
hasher . finish ( )
2019-12-17 23:22:55 +11:00
}
}
2021-05-07 15:18:19 +03:00
pub const $stat : OptionDescrs < $struct_name > =
2021-10-21 13:18:59 +02:00
& [ $( ( stringify! ( $opt ) , $optmod ::$opt , desc ::$parse , $desc ) ) , * ] ;
2019-12-17 23:22:55 +11:00
2021-10-21 13:18:59 +02:00
mod $optmod {
2021-05-01 18:48:25 -04:00
$(
2021-10-21 13:18:59 +02:00
pub ( super ) fn $opt ( cg : & mut super ::$struct_name , v : Option < & str > ) -> bool {
super ::parse ::$parse ( & mut redirect_field! ( cg . $opt ) , v )
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
) *
2021-10-21 13:18:59 +02:00
}
2021-05-01 18:48:25 -04:00
) }
2022-07-25 13:02:39 +01:00
impl CodegenOptions {
// JUSTIFICATION: defn of the suggested wrapper fn
2022-08-09 09:56:13 -04:00
#[ allow(rustc::bad_opt_access) ]
2022-07-25 13:02:39 +01:00
pub fn instrument_coverage ( & self ) -> InstrumentCoverage {
2023-10-25 14:36:13 +11:00
self . instrument_coverage
2022-07-25 13:02:39 +01:00
}
}
2021-05-07 15:18:19 +03:00
// Sometimes different options need to build a common structure.
// That structure can be kept in one of the options' fields, the others become dummy.
macro_rules ! redirect_field {
( $cg :ident . link_arg ) = > {
$cg . link_args
} ;
( $cg :ident . pre_link_arg ) = > {
$cg . pre_link_args
} ;
( $cg :ident . $field :ident ) = > {
$cg . $field
} ;
}
type OptionSetter < O > = fn ( & mut O , v : Option < & str > ) -> bool ;
type OptionDescrs < O > = & 'static [ ( & 'static str , OptionSetter < O > , & 'static str , & 'static str ) ] ;
2024-02-20 14:12:50 +11:00
#[ allow(rustc::untranslatable_diagnostic) ] // FIXME: make this translatable
2021-05-07 15:18:19 +03:00
fn build_options < O : Default > (
2023-12-18 10:57:26 +11:00
early_dcx : & EarlyDiagCtxt ,
2021-05-07 15:18:19 +03:00
matches : & getopts ::Matches ,
descrs : OptionDescrs < O > ,
prefix : & str ,
outputname : & str ,
) -> O {
let mut op = O ::default ( ) ;
for option in matches . opt_strs ( prefix ) {
let ( key , value ) = match option . split_once ( '=' ) {
None = > ( option , None ) ,
Some ( ( k , v ) ) = > ( k . to_string ( ) , Some ( v ) ) ,
} ;
2021-05-10 14:52:31 +03:00
2021-12-13 22:58:58 +01:00
let option_to_lookup = key . replace ( '-' , " _ " ) ;
2021-05-10 14:52:31 +03:00
match descrs . iter ( ) . find ( | ( name , .. ) | * name = = option_to_lookup ) {
Some ( ( _ , setter , type_desc , _ ) ) = > {
if ! setter ( & mut op , value ) {
match value {
2023-12-20 14:53:50 +11:00
None = > early_dcx . early_fatal (
2023-05-16 16:04:03 +10:00
format! (
2023-07-25 22:00:13 +02:00
" {outputname} option `{key}` requires {type_desc} ({prefix} {key}=<value>) "
2021-05-10 14:52:31 +03:00
) ,
2021-05-07 15:18:19 +03:00
) ,
2023-12-20 14:53:50 +11:00
Some ( value ) = > early_dcx . early_fatal (
2023-05-16 16:04:03 +10:00
format! (
2022-03-24 22:11:05 -07:00
" incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected "
2021-05-10 14:52:31 +03:00
) ,
2021-05-07 15:18:19 +03:00
) ,
2021-05-10 14:52:31 +03:00
}
2021-05-07 15:18:19 +03:00
}
}
2023-12-20 14:53:50 +11:00
None = > early_dcx . early_fatal ( format! ( " unknown {outputname} option: ` {key} ` " ) ) ,
2021-05-07 15:18:19 +03:00
}
}
return op ;
}
2021-05-01 18:48:25 -04:00
#[ allow(non_upper_case_globals) ]
mod desc {
pub const parse_no_flag : & str = " no value " ;
2023-01-18 20:04:26 +01:00
pub const parse_bool : & str = " one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false` " ;
2021-05-01 18:48:25 -04:00
pub const parse_opt_bool : & str = parse_bool ;
pub const parse_string : & str = " a string " ;
pub const parse_opt_string : & str = parse_string ;
pub const parse_string_push : & str = parse_string ;
2022-03-28 09:36:20 +01:00
pub const parse_opt_langid : & str = " a language identifier " ;
2021-05-01 18:48:25 -04:00
pub const parse_opt_pathbuf : & str = " a path " ;
pub const parse_list : & str = " a space-separated list of strings " ;
2022-04-11 15:17:52 -04:00
pub const parse_list_with_polarity : & str =
" a comma-separated list of strings, with elements beginning with + or - " ;
2024-02-01 13:16:30 -08:00
pub const parse_comma_list : & str = " a comma-separated list of strings " ;
pub const parse_opt_comma_list : & str = parse_comma_list ;
2021-05-01 18:48:25 -04:00
pub const parse_number : & str = " a number " ;
pub const parse_opt_number : & str = parse_number ;
pub const parse_threads : & str = parse_number ;
2023-02-06 06:32:34 +01:00
pub const parse_time_passes_format : & str = " `text` (default) or `json` " ;
2021-05-01 18:48:25 -04:00
pub const parse_passes : & str = " a space-separated list of passes, or `all` " ;
pub const parse_panic_strategy : & str = " either `unwind` or `abort` " ;
2024-04-28 18:02:21 +02:00
pub const parse_on_broken_pipe : & str = " either `kill`, `error`, or `inherit` " ;
2021-09-06 12:21:47 +02:00
pub const parse_opt_panic_strategy : & str = parse_panic_strategy ;
2021-10-06 15:52:54 +01:00
pub const parse_oom_strategy : & str = " either `panic` or `abort` " ;
2021-05-01 18:48:25 -04:00
pub const parse_relro_level : & str = " one of: `full`, `partial`, or `off` " ;
2024-02-01 13:16:30 -08:00
pub const parse_sanitizers : & str = " comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, or `thread` " ;
2021-05-01 18:48:25 -04:00
pub const parse_sanitizer_memory_track_origins : & str = " 0, 1, or 2 " ;
pub const parse_cfguard : & str =
" either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks` " ;
2022-01-28 09:48:59 -08:00
pub const parse_cfprotection : & str = " `none`|`no`|`n` (default), `branch`, `return`, or `full`|`yes`|`y` (equivalent to `branch` and `return`) " ;
2021-04-06 16:00:35 -04:00
pub const parse_debuginfo : & str = " either an integer (0, 1, 2), `none`, `line-directives-only`, `line-tables-only`, `limited`, or `full` " ;
2023-07-12 17:07:34 -04:00
pub const parse_debuginfo_compression : & str = " one of `none`, `zlib`, or `zstd` " ;
2024-01-11 01:36:05 +07:00
pub const parse_collapse_macro_debuginfo : & str = " one of `no`, `external`, or `yes` " ;
2021-05-01 18:48:25 -04:00
pub const parse_strip : & str = " either `none`, `debuginfo`, or `symbols` " ;
2022-08-14 20:28:34 +03:00
pub const parse_linker_flavor : & str = ::rustc_target ::spec ::LinkerFlavorCli ::one_of ( ) ;
2021-05-01 18:48:25 -04:00
pub const parse_optimization_fuel : & str = " crate=integer " ;
2022-12-29 21:08:09 +00:00
pub const parse_dump_mono_stats : & str = " `markdown` (default) or `json` " ;
2024-03-12 12:30:33 +11:00
pub const parse_instrument_coverage : & str = parse_bool ;
2024-06-17 20:09:45 +10:00
pub const parse_coverage_options : & str =
" `block` | `branch` | `condition` | `mcdc` | `no-mir-spans` " ;
2022-09-24 20:02:44 +09:00
pub const parse_instrument_xray : & str = " either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit` " ;
2021-05-01 18:48:25 -04:00
pub const parse_unpretty : & str = " `string` or `string=string` " ;
2023-09-22 13:33:55 +02:00
pub const parse_treat_err_as_bug : & str = " either no value or a non-negative number " ;
2024-05-24 18:23:24 +00:00
pub const parse_next_solver_config : & str =
" a comma separated list of solver configurations: `globally` (default), and `coherence` " ;
2021-05-01 18:48:25 -04:00
pub const parse_lto : & str =
" either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted " ;
pub const parse_linker_plugin_lto : & str =
" either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin " ;
2022-07-22 12:21:32 -07:00
pub const parse_location_detail : & str = " either `none`, or a comma separated list of location details to track: `file`, `line`, or `column` " ;
2021-05-01 18:48:25 -04:00
pub const parse_switch_with_opt_path : & str =
" an optional path to the profiling data output directory " ;
pub const parse_merge_functions : & str = " one of: `disabled`, `trampolines`, or `aliases` " ;
2023-12-05 12:42:57 +08:00
pub const parse_symbol_mangling_version : & str =
" one of: `legacy`, `v0` (RFC 2603), or `hashed` " ;
2021-05-01 18:48:25 -04:00
pub const parse_src_file_hash : & str = " either `md5` or `sha1` " ;
pub const parse_relocation_model : & str =
" one of supported relocation models (`rustc --print relocation-models`) " ;
pub const parse_code_model : & str = " one of supported code models (`rustc --print code-models`) " ;
pub const parse_tls_model : & str = " one of supported TLS models (`rustc --print tls-models`) " ;
pub const parse_target_feature : & str = parse_string ;
2023-02-09 10:16:00 +00:00
pub const parse_terminal_url : & str =
" either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto` " ;
2021-05-01 18:48:25 -04:00
pub const parse_wasi_exec_model : & str = " either `command` or `reactor` " ;
pub const parse_split_debuginfo : & str =
2021-05-19 15:39:50 +01:00
" one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`) " ;
sess/cg: re-introduce split dwarf kind
In #79570, `-Z split-dwarf-kind={none,single,split}` was replaced by `-C
split-debuginfo={off,packed,unpacked}`. `-C split-debuginfo`'s packed
and unpacked aren't exact parallels to single and split, respectively.
On Unix, `-C split-debuginfo=packed` will put debuginfo into object
files and package debuginfo into a DWARF package file (`.dwp`) and
`-C split-debuginfo=unpacked` will put debuginfo into dwarf object files
and won't package it.
In the initial implementation of Split DWARF, split mode wrote sections
which did not require relocation into a DWARF object (`.dwo`) file which
was ignored by the linker and then packaged those DWARF objects into
DWARF packages (`.dwp`). In single mode, sections which did not require
relocation were written into object files but ignored by the linker and
were not packaged. However, both split and single modes could be
packaged or not, the primary difference in behaviour was where the
debuginfo sections that did not require link-time relocation were
written (in a DWARF object or the object file).
This commit re-introduces a `-Z split-dwarf-kind` flag, which can be
used to pick between split and single modes when `-C split-debuginfo` is
used to enable Split DWARF (either packed or unpacked).
Signed-off-by: David Wood <david.wood@huawei.com>
2021-10-08 16:10:17 +00:00
pub const parse_split_dwarf_kind : & str =
" one of supported split dwarf modes (`split` or `single`) " ;
2023-06-21 21:46:36 +00:00
pub const parse_link_self_contained : & str = " one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
components : ` crto ` , ` libc ` , ` unwind ` , ` linker ` , ` sanitizers ` , ` mingw ` " ;
2024-04-08 21:40:44 +00:00
pub const parse_linker_features : & str =
" a list of enabled (`+` prefix) and disabled (`-` prefix) features: `lld` " ;
2023-06-30 11:55:38 +00:00
pub const parse_polonius : & str = " either no value or `legacy` (the default), or `next` " ;
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
pub const parse_stack_protector : & str =
" one of (`none` (default), `basic`, `strong`, or `all`) " ;
2021-07-13 12:14:26 +01:00
pub const parse_branch_protection : & str =
2021-12-01 15:56:59 +00:00
" a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf` " ;
2022-06-18 14:15:03 -04:00
pub const parse_proc_macro_execution_strategy : & str =
" one of supported execution strategies (`same-thread`, or `cross-thread`) " ;
2024-03-19 13:51:22 +01:00
pub const parse_remap_path_scope : & str =
" comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all` " ;
2023-11-06 19:55:05 -05:00
pub const parse_inlining_threshold : & str =
" either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number " ;
2023-10-09 02:22:14 -07:00
pub const parse_llvm_module_flag : & str = " <key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`) " ;
2023-10-18 16:58:17 +02:00
pub const parse_function_return : & str = " `keep` or `thunk-extern` " ;
2024-02-27 23:06:44 +01:00
pub const parse_wasm_c_abi : & str = " `legacy` or `spec` " ;
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
mod parse {
2022-05-20 19:51:09 -04:00
pub ( crate ) use super ::* ;
2021-05-01 18:48:25 -04:00
use std ::str ::FromStr ;
/// This is for boolean options that don't take a value and start with
/// `no-`. This style of option is deprecated.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_no_flag ( slot : & mut bool , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
None = > {
* slot = true ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
Some ( _ ) = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
/// Use this for any boolean option that has a static default.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_bool ( slot : & mut bool , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
2023-01-18 20:04:26 +01:00
Some ( " y " ) | Some ( " yes " ) | Some ( " on " ) | Some ( " true " ) | None = > {
2021-05-01 18:48:25 -04:00
* slot = true ;
true
}
2023-01-18 20:04:26 +01:00
Some ( " n " ) | Some ( " no " ) | Some ( " off " ) | Some ( " false " ) = > {
2021-05-01 18:48:25 -04:00
* slot = false ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
_ = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
/// Use this for any boolean option that lacks a static default. (The
/// actions taken when such an option is not specified will depend on
/// other factors, such as other options, or target options.)
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_bool ( slot : & mut Option < bool > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
2023-01-18 20:04:26 +01:00
Some ( " y " ) | Some ( " yes " ) | Some ( " on " ) | Some ( " true " ) | None = > {
2021-05-01 18:48:25 -04:00
* slot = Some ( true ) ;
true
}
2023-01-18 20:04:26 +01:00
Some ( " n " ) | Some ( " no " ) | Some ( " off " ) | Some ( " false " ) = > {
2021-05-01 18:48:25 -04:00
* slot = Some ( false ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
_ = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2023-06-30 11:55:38 +00:00
/// Parses whether polonius is enabled, and if so, which version.
pub ( crate ) fn parse_polonius ( slot : & mut Polonius , v : Option < & str > ) -> bool {
match v {
Some ( " legacy " ) | None = > {
* slot = Polonius ::Legacy ;
true
}
Some ( " next " ) = > {
* slot = Polonius ::Next ;
true
}
_ = > false ,
}
}
2021-05-01 18:48:25 -04:00
/// Use this for any string option that has a static default.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_string ( slot : & mut String , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
* slot = s . to_string ( ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
/// Use this for any string option that lacks a static default.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_string ( slot : & mut Option < String > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
* slot = Some ( s . to_string ( ) ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-03-28 09:36:20 +01:00
/// Parse an optional language identifier, e.g. `en-US` or `zh-CN`.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_langid ( slot : & mut Option < LanguageIdentifier > , v : Option < & str > ) -> bool {
2022-03-28 09:36:20 +01:00
match v {
Some ( s ) = > {
* slot = rustc_errors ::LanguageIdentifier ::from_str ( s ) . ok ( ) ;
true
}
None = > false ,
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_pathbuf ( slot : & mut Option < PathBuf > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
* slot = Some ( PathBuf ::from ( s ) ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_string_push ( slot : & mut Vec < String > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
slot . push ( s . to_string ( ) ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_list ( slot : & mut Vec < String > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
slot . extend ( s . split_whitespace ( ) . map ( | s | s . to_string ( ) ) ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_list_with_polarity (
slot : & mut Vec < ( String , bool ) > ,
v : Option < & str > ,
) -> bool {
2022-04-11 15:17:52 -04:00
match v {
Some ( s ) = > {
2022-07-20 11:48:11 +02:00
for s in s . split ( ',' ) {
2022-04-16 18:44:27 -04:00
let Some ( pass_name ) = s . strip_prefix ( & [ '+' , '-' ] [ .. ] ) else { return false } ;
slot . push ( ( pass_name . to_string ( ) , & s [ .. 1 ] = = " + " ) ) ;
2022-04-11 15:17:52 -04:00
}
true
}
None = > false ,
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_location_detail ( ld : & mut LocationDetail , v : Option < & str > ) -> bool {
2021-10-13 17:01:31 -07:00
if let Some ( v ) = v {
ld . line = false ;
ld . file = false ;
ld . column = false ;
2022-07-22 12:21:32 -07:00
if v = = " none " {
return true ;
}
2021-10-13 17:01:31 -07:00
for s in v . split ( ',' ) {
match s {
" file " = > ld . file = true ,
" line " = > ld . line = true ,
" column " = > ld . column = true ,
_ = > return false ,
}
}
true
} else {
false
}
}
2024-02-01 13:16:30 -08:00
pub ( crate ) fn parse_comma_list ( slot : & mut Vec < String > , v : Option < & str > ) -> bool {
match v {
Some ( s ) = > {
let mut v : Vec < _ > = s . split ( ',' ) . map ( | s | s . to_string ( ) ) . collect ( ) ;
v . sort_unstable ( ) ;
* slot = v ;
true
}
None = > false ,
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_comma_list ( slot : & mut Option < Vec < String > > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
let mut v : Vec < _ > = s . split ( ',' ) . map ( | s | s . to_string ( ) ) . collect ( ) ;
v . sort_unstable ( ) ;
* slot = Some ( v ) ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_threads ( slot : & mut usize , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | s . parse ( ) . ok ( ) ) {
Some ( 0 ) = > {
2024-01-29 23:59:09 +01:00
* slot = std ::thread ::available_parallelism ( ) . map_or ( 1 , NonZero ::< usize > ::get ) ;
2021-05-01 18:48:25 -04:00
true
}
Some ( i ) = > {
* slot = i ;
2019-12-17 23:22:55 +11:00
true
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
/// Use this for any numeric option that has a static default.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_number < T : Copy + FromStr > ( slot : & mut T , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | s . parse ( ) . ok ( ) ) {
Some ( i ) = > {
* slot = i ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-01 18:48:25 -04:00
/// Use this for any numeric option that lacks a static default.
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_number < T : Copy + FromStr > (
slot : & mut Option < T > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
* slot = s . parse ( ) . ok ( ) ;
slot . is_some ( )
2020-05-03 12:36:12 +08:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2020-05-03 12:36:12 +08:00
}
2021-05-01 18:48:25 -04:00
}
2020-05-03 12:36:12 +08:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_passes ( slot : & mut Passes , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( " all " ) = > {
* slot = Passes ::All ;
true
}
v = > {
let mut passes = vec! [ ] ;
if parse_list ( & mut passes , v ) {
2021-11-13 00:00:00 +00:00
slot . extend ( passes ) ;
2021-05-01 18:48:25 -04:00
true
} else {
false
2020-06-16 17:44:03 +01:00
}
2020-01-13 13:25:39 +00:00
}
2021-05-01 18:48:25 -04:00
}
}
2020-06-16 17:44:03 +01:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_opt_panic_strategy (
slot : & mut Option < PanicStrategy > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( " unwind " ) = > * slot = Some ( PanicStrategy ::Unwind ) ,
Some ( " abort " ) = > * slot = Some ( PanicStrategy ::Abort ) ,
_ = > return false ,
2020-01-13 13:25:39 +00:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-01-13 13:25:39 +00:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_panic_strategy ( slot : & mut PanicStrategy , v : Option < & str > ) -> bool {
2021-09-06 12:21:47 +02:00
match v {
Some ( " unwind " ) = > * slot = PanicStrategy ::Unwind ,
Some ( " abort " ) = > * slot = PanicStrategy ::Abort ,
_ = > return false ,
}
true
}
2024-04-28 18:02:21 +02:00
pub ( crate ) fn parse_on_broken_pipe ( slot : & mut OnBrokenPipe , v : Option < & str > ) -> bool {
match v {
// OnBrokenPipe::Default can't be explicitly specified
Some ( " kill " ) = > * slot = OnBrokenPipe ::Kill ,
Some ( " error " ) = > * slot = OnBrokenPipe ::Error ,
Some ( " inherit " ) = > * slot = OnBrokenPipe ::Inherit ,
_ = > return false ,
}
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_oom_strategy ( slot : & mut OomStrategy , v : Option < & str > ) -> bool {
2021-10-06 15:52:54 +01:00
match v {
2023-04-25 00:08:33 +02:00
Some ( " panic " ) = > * slot = OomStrategy ::Panic ,
2021-10-06 15:52:54 +01:00
Some ( " abort " ) = > * slot = OomStrategy ::Abort ,
_ = > return false ,
}
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_relro_level ( slot : & mut Option < RelroLevel > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > match s . parse ::< RelroLevel > ( ) {
Ok ( level ) = > * slot = Some ( level ) ,
2019-12-17 23:22:55 +11:00
_ = > return false ,
2021-05-01 18:48:25 -04:00
} ,
_ = > return false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
true
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_sanitizers ( slot : & mut SanitizerSet , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
if let Some ( v ) = v {
for s in v . split ( ',' ) {
* slot | = match s {
" address " = > SanitizerSet ::ADDRESS ,
2021-10-07 15:33:13 -07:00
" cfi " = > SanitizerSet ::CFI ,
2024-02-01 13:16:30 -08:00
" dataflow " = > SanitizerSet ::DATAFLOW ,
2022-11-21 21:29:00 -08:00
" kcfi " = > SanitizerSet ::KCFI ,
2022-09-11 19:36:19 -04:00
" kernel-address " = > SanitizerSet ::KERNELADDRESS ,
2021-05-01 18:48:25 -04:00
" leak " = > SanitizerSet ::LEAK ,
" memory " = > SanitizerSet ::MEMORY ,
2021-12-03 16:11:13 -05:00
" memtag " = > SanitizerSet ::MEMTAG ,
2022-06-17 14:14:58 -04:00
" shadow-call-stack " = > SanitizerSet ::SHADOWCALLSTACK ,
2021-05-01 18:48:25 -04:00
" thread " = > SanitizerSet ::THREAD ,
" hwaddress " = > SanitizerSet ::HWADDRESS ,
2023-05-19 19:30:15 -04:00
" safestack " = > SanitizerSet ::SAFESTACK ,
2021-05-01 18:48:25 -04:00
_ = > return false ,
2019-12-17 23:22:55 +11:00
}
}
2021-05-01 18:48:25 -04:00
true
} else {
false
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_sanitizer_memory_track_origins ( slot : & mut usize , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( " 2 " ) | None = > {
* slot = 2 ;
true
}
Some ( " 1 " ) = > {
* slot = 1 ;
true
}
Some ( " 0 " ) = > {
* slot = 0 ;
true
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
Some ( _ ) = > false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_strip ( slot : & mut Strip , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( " none " ) = > * slot = Strip ::None ,
Some ( " debuginfo " ) = > * slot = Strip ::Debuginfo ,
Some ( " symbols " ) = > * slot = Strip ::Symbols ,
_ = > return false ,
}
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_cfguard ( slot : & mut CFGuard , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) { CFGuard ::Checks } else { CFGuard ::Disabled } ;
return true ;
2020-08-29 10:55:46 -07:00
}
2021-05-01 18:48:25 -04:00
}
2020-08-29 10:55:46 -07:00
2021-05-01 18:48:25 -04:00
* slot = match v {
None = > CFGuard ::Checks ,
Some ( " checks " ) = > CFGuard ::Checks ,
Some ( " nochecks " ) = > CFGuard ::NoChecks ,
Some ( _ ) = > return false ,
} ;
true
}
2020-08-29 10:55:46 -07:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_cfprotection ( slot : & mut CFProtection , v : Option < & str > ) -> bool {
2022-01-28 09:48:59 -08:00
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) { CFProtection ::Full } else { CFProtection ::None } ;
return true ;
}
}
* slot = match v {
None | Some ( " none " ) = > CFProtection ::None ,
Some ( " branch " ) = > CFProtection ::Branch ,
Some ( " return " ) = > CFProtection ::Return ,
Some ( " full " ) = > CFProtection ::Full ,
Some ( _ ) = > return false ,
} ;
true
}
2021-04-06 16:00:35 -04:00
pub ( crate ) fn parse_debuginfo ( slot : & mut DebugInfo , v : Option < & str > ) -> bool {
match v {
Some ( " 0 " ) | Some ( " none " ) = > * slot = DebugInfo ::None ,
Some ( " line-directives-only " ) = > * slot = DebugInfo ::LineDirectivesOnly ,
Some ( " line-tables-only " ) = > * slot = DebugInfo ::LineTablesOnly ,
Some ( " 1 " ) | Some ( " limited " ) = > * slot = DebugInfo ::Limited ,
Some ( " 2 " ) | Some ( " full " ) = > * slot = DebugInfo ::Full ,
_ = > return false ,
}
true
}
2023-07-12 17:07:34 -04:00
pub ( crate ) fn parse_debuginfo_compression (
slot : & mut DebugInfoCompression ,
v : Option < & str > ,
) -> bool {
match v {
Some ( " none " ) = > * slot = DebugInfoCompression ::None ,
Some ( " zlib " ) = > * slot = DebugInfoCompression ::Zlib ,
Some ( " zstd " ) = > * slot = DebugInfoCompression ::Zstd ,
_ = > return false ,
} ;
true
}
2022-08-14 20:28:34 +03:00
pub ( crate ) fn parse_linker_flavor ( slot : & mut Option < LinkerFlavorCli > , v : Option < & str > ) -> bool {
match v . and_then ( LinkerFlavorCli ::from_str ) {
2021-05-11 01:17:08 +02:00
Some ( lf ) = > * slot = Some ( lf ) ,
2021-05-01 18:48:25 -04:00
_ = > return false ,
2020-08-29 10:55:46 -07:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-08-29 10:55:46 -07:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_optimization_fuel (
slot : & mut Option < ( String , u64 ) > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v {
None = > false ,
Some ( s ) = > {
let parts = s . split ( '=' ) . collect ::< Vec < _ > > ( ) ;
if parts . len ( ) ! = 2 {
return false ;
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.
Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.
Fixes: #82144
Invalid LLVM coverage data produced when compiled with -C opt-level=1
Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.
The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:
1. Rust's coverage map does not include any overlapping code regions,
making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
functions, including generics. (Clang does not generate coverage for
uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
sufficient for including in the coverage results; while Clang must
generate the complete LLVM IR for each unused function, even though
it will never be called.
This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.
Fixes: #79651
Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates
Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.
Fixes: #82875
Invalid LLVM coverage data produced with crate brotli_decompressor
Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.
2021-03-15 16:32:45 -07:00
}
2021-05-01 18:48:25 -04:00
let crate_name = parts [ 0 ] . to_string ( ) ;
let fuel = parts [ 1 ] . parse ::< u64 > ( ) ;
if fuel . is_err ( ) {
return false ;
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.
Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.
Fixes: #82144
Invalid LLVM coverage data produced when compiled with -C opt-level=1
Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.
The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:
1. Rust's coverage map does not include any overlapping code regions,
making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
functions, including generics. (Clang does not generate coverage for
uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
sufficient for including in the coverage results; while Clang must
generate the complete LLVM IR for each unused function, even though
it will never be called.
This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.
Fixes: #79651
Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates
Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.
Fixes: #82875
Invalid LLVM coverage data produced with crate brotli_decompressor
Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.
2021-03-15 16:32:45 -07:00
}
2021-05-01 18:48:25 -04:00
* slot = Some ( ( crate_name , fuel . unwrap ( ) ) ) ;
true
}
}
}
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.
Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.
Fixes: #82144
Invalid LLVM coverage data produced when compiled with -C opt-level=1
Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.
The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:
1. Rust's coverage map does not include any overlapping code regions,
making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
functions, including generics. (Clang does not generate coverage for
uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
sufficient for including in the coverage results; while Clang must
generate the complete LLVM IR for each unused function, even though
it will never be called.
This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.
Fixes: #79651
Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates
Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.
Fixes: #82875
Invalid LLVM coverage data produced with crate brotli_decompressor
Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.
2021-03-15 16:32:45 -07:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_unpretty ( slot : & mut Option < String > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
None = > false ,
Some ( s ) if s . split ( '=' ) . count ( ) < = 2 = > {
* slot = Some ( s . to_string ( ) ) ;
true
}
_ = > false ,
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.
Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.
Fixes: #82144
Invalid LLVM coverage data produced when compiled with -C opt-level=1
Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.
The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:
1. Rust's coverage map does not include any overlapping code regions,
making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
functions, including generics. (Clang does not generate coverage for
uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
sufficient for including in the coverage results; while Clang must
generate the complete LLVM IR for each unused function, even though
it will never be called.
This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.
Fixes: #79651
Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates
Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.
Fixes: #82875
Invalid LLVM coverage data produced with crate brotli_decompressor
Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.
2021-03-15 16:32:45 -07:00
}
2021-05-01 18:48:25 -04:00
}
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to
address multiple, somewhat related issues.
Fixed a significant flaw in prior coverage solution: Every counter
generated a new counter variable, but there should have only been one
counter variable per function. This appears to have bloated .profraw
files significantly. (For a small program, it increased the size by
about 40%. I have not tested large programs, but there is anecdotal
evidence that profraw files were way too large. This is a good fix,
regardless, but hopefully it also addresses related issues.
Fixes: #82144
Invalid LLVM coverage data produced when compiled with -C opt-level=1
Existing tests now work up to at least `opt-level=3`. This required a
detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR
when compiled with coverage, and a lot of trial and error with codegen
adjustments.
The biggest hurdle was figuring out how to continue to support coverage
results for unused functions and generics. Rust's coverage results have
three advantages over Clang's coverage results:
1. Rust's coverage map does not include any overlapping code regions,
making coverage counting unambiguous.
2. Rust generates coverage results (showing zero counts) for all unused
functions, including generics. (Clang does not generate coverage for
uninstantiated template functions.)
3. Rust's unused functions produce minimal stubbed functions in LLVM IR,
sufficient for including in the coverage results; while Clang must
generate the complete LLVM IR for each unused function, even though
it will never be called.
This PR removes the previous hack of attempting to inject coverage into
some other existing function instance, and generates dedicated instances
for each unused function. This change, and a few other adjustments
(similar to what is required for `-C link-dead-code`, but with lower
impact), makes it possible to support LLVM optimizations.
Fixes: #79651
Coverage report: "Unexecuted instantiation:..." for a generic function
from multiple crates
Fixed by removing the aforementioned hack. Some "Unexecuted
instantiation" notices are unavoidable, as explained in the
`used_crate.rs` test, but `-Zinstrument-coverage` has new options to
back off support for either unused generics, or all unused functions,
which avoids the notice, at the cost of less coverage of unused
functions.
Fixes: #82875
Invalid LLVM coverage data produced with crate brotli_decompressor
Fixed by disabling the LLVM function attribute that forces inlining, if
`-Z instrument-coverage` is enabled. This attribute is applied to
Rust functions with `#[inline(always)], and in some cases, the forced
inlining breaks coverage instrumentation and reports.
2021-03-15 16:32:45 -07:00
2023-02-06 06:32:34 +01:00
pub ( crate ) fn parse_time_passes_format ( slot : & mut TimePassesFormat , v : Option < & str > ) -> bool {
match v {
None = > true ,
Some ( " json " ) = > {
* slot = TimePassesFormat ::Json ;
true
}
Some ( " text " ) = > {
* slot = TimePassesFormat ::Text ;
true
}
Some ( _ ) = > false ,
}
}
2022-12-29 21:08:09 +00:00
pub ( crate ) fn parse_dump_mono_stats ( slot : & mut DumpMonoStatsFormat , v : Option < & str > ) -> bool {
match v {
None = > true ,
Some ( " json " ) = > {
* slot = DumpMonoStatsFormat ::Json ;
true
}
Some ( " markdown " ) = > {
* slot = DumpMonoStatsFormat ::Markdown ;
true
}
Some ( _ ) = > false ,
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_instrument_coverage (
2023-10-25 14:36:13 +11:00
slot : & mut InstrumentCoverage ,
2021-05-01 18:48:25 -04:00
v : Option < & str > ,
) -> bool {
if v . is_some ( ) {
2023-10-25 14:36:13 +11:00
let mut bool_arg = false ;
if parse_bool ( & mut bool_arg , v ) {
2023-10-25 14:57:25 +11:00
* slot = if bool_arg { InstrumentCoverage ::Yes } else { InstrumentCoverage ::No } ;
2021-05-01 18:48:25 -04:00
return true ;
}
2019-12-17 23:22:55 +11:00
}
2022-02-19 00:48:49 +01:00
let Some ( v ) = v else {
2023-10-25 14:57:25 +11:00
* slot = InstrumentCoverage ::Yes ;
2022-02-19 00:48:49 +01:00
return true ;
2021-05-01 18:48:25 -04:00
} ;
2019-12-17 23:22:55 +11:00
2024-03-12 12:30:33 +11:00
// Parse values that have historically been accepted by stable compilers,
// even though they're currently just aliases for boolean values.
2023-10-25 14:36:13 +11:00
* slot = match v {
2023-10-25 14:57:25 +11:00
" all " = > InstrumentCoverage ::Yes ,
" 0 " = > InstrumentCoverage ::No ,
2021-05-01 18:48:25 -04:00
_ = > return false ,
2023-10-25 14:36:13 +11:00
} ;
2021-05-01 18:48:25 -04:00
true
}
2019-12-17 23:22:55 +11:00
2024-03-08 18:07:04 +11:00
pub ( crate ) fn parse_coverage_options ( slot : & mut CoverageOptions , v : Option < & str > ) -> bool {
let Some ( v ) = v else { return true } ;
for option in v . split ( ',' ) {
2024-04-19 10:43:53 +08:00
match option {
2024-04-29 16:19:55 +10:00
" block " = > slot . level = CoverageLevel ::Block ,
" branch " = > slot . level = CoverageLevel ::Branch ,
2024-04-26 13:01:06 +00:00
" condition " = > slot . level = CoverageLevel ::Condition ,
2024-04-29 16:19:55 +10:00
" mcdc " = > slot . level = CoverageLevel ::Mcdc ,
2024-06-17 20:09:45 +10:00
" no-mir-spans " = > slot . no_mir_spans = true ,
2024-03-08 18:07:04 +11:00
_ = > return false ,
2024-04-19 10:43:53 +08:00
}
2024-03-08 18:07:04 +11:00
}
true
}
2022-09-24 20:02:44 +09:00
pub ( crate ) fn parse_instrument_xray (
slot : & mut Option < InstrumentXRay > ,
v : Option < & str > ,
) -> bool {
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) { Some ( InstrumentXRay ::default ( ) ) } else { None } ;
return true ;
}
}
2023-04-28 20:19:48 +02:00
let options = slot . get_or_insert_default ( ) ;
2022-09-24 20:02:44 +09:00
let mut seen_always = false ;
let mut seen_never = false ;
let mut seen_ignore_loops = false ;
let mut seen_instruction_threshold = false ;
let mut seen_skip_entry = false ;
let mut seen_skip_exit = false ;
2023-04-01 23:50:45 +02:00
for option in v . into_iter ( ) . flat_map ( | v | v . split ( ',' ) ) {
2022-09-24 20:02:44 +09:00
match option {
" always " if ! seen_always & & ! seen_never = > {
options . always = true ;
options . never = false ;
seen_always = true ;
}
" never " if ! seen_never & & ! seen_always = > {
options . never = true ;
options . always = false ;
seen_never = true ;
}
" ignore-loops " if ! seen_ignore_loops = > {
options . ignore_loops = true ;
seen_ignore_loops = true ;
}
option
if option . starts_with ( " instruction-threshold " )
& & ! seen_instruction_threshold = >
{
let Some ( ( " instruction-threshold " , n ) ) = option . split_once ( '=' ) else {
return false ;
} ;
match n . parse ( ) {
Ok ( n ) = > options . instruction_threshold = Some ( n ) ,
Err ( _ ) = > return false ,
}
seen_instruction_threshold = true ;
}
" skip-entry " if ! seen_skip_entry = > {
options . skip_entry = true ;
seen_skip_entry = true ;
}
" skip-exit " if ! seen_skip_exit = > {
options . skip_exit = true ;
seen_skip_exit = true ;
}
_ = > return false ,
}
}
true
}
2024-01-29 23:59:09 +01:00
pub ( crate ) fn parse_treat_err_as_bug (
slot : & mut Option < NonZero < usize > > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v {
2023-09-22 13:33:55 +02:00
Some ( s ) = > match s . parse ( ) {
Ok ( val ) = > {
* slot = Some ( val ) ;
true
}
Err ( e ) = > {
* slot = None ;
e . kind ( ) = = & IntErrorKind ::Zero
}
} ,
2021-05-01 18:48:25 -04:00
None = > {
2024-02-08 23:03:25 +01:00
* slot = NonZero ::new ( 1 ) ;
2021-05-01 18:48:25 -04:00
true
}
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2023-12-14 13:00:23 +01:00
pub ( crate ) fn parse_next_solver_config (
slot : & mut Option < NextSolverConfig > ,
v : Option < & str > ,
) -> bool {
if let Some ( config ) = v {
let mut coherence = false ;
let mut globally = true ;
for c in config . split ( ',' ) {
match c {
" globally " = > globally = true ,
" coherence " = > {
globally = false ;
coherence = true ;
}
_ = > return false ,
}
}
2024-05-24 18:23:24 +00:00
* slot = Some ( NextSolverConfig { coherence : coherence | | globally , globally } ) ;
2023-12-14 13:00:23 +01:00
} else {
2024-05-24 18:23:24 +00:00
* slot = Some ( NextSolverConfig { coherence : true , globally : true } ) ;
2023-01-02 23:12:47 +00:00
}
2023-12-14 13:00:23 +01:00
2023-01-02 23:12:47 +00:00
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_lto ( slot : & mut LtoCli , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) { LtoCli ::Yes } else { LtoCli ::No } ;
return true ;
2019-12-17 23:22:55 +11:00
}
}
2021-05-01 18:48:25 -04:00
* slot = match v {
None = > LtoCli ::NoParam ,
Some ( " thin " ) = > LtoCli ::Thin ,
Some ( " fat " ) = > LtoCli ::Fat ,
Some ( _ ) = > return false ,
} ;
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_linker_plugin_lto ( slot : & mut LinkerPluginLto , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) {
LinkerPluginLto ::LinkerPluginAuto
} else {
LinkerPluginLto ::Disabled
} ;
return true ;
2020-04-23 00:46:45 +03:00
}
}
2021-05-01 18:48:25 -04:00
* slot = match v {
None = > LinkerPluginLto ::LinkerPluginAuto ,
Some ( path ) = > LinkerPluginLto ::LinkerPlugin ( PathBuf ::from ( path ) ) ,
} ;
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_switch_with_opt_path (
slot : & mut SwitchWithOptPath ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
* slot = match v {
None = > SwitchWithOptPath ::Enabled ( None ) ,
Some ( path ) = > SwitchWithOptPath ::Enabled ( Some ( PathBuf ::from ( path ) ) ) ,
} ;
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_merge_functions (
slot : & mut Option < MergeFunctions > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | MergeFunctions ::from_str ( s ) . ok ( ) ) {
Some ( mergefunc ) = > * slot = Some ( mergefunc ) ,
_ = > return false ,
2020-05-07 03:34:27 +03:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-05-07 03:34:27 +03:00
2023-08-23 11:18:20 +02:00
pub ( crate ) fn parse_remap_path_scope (
slot : & mut RemapPathScopeComponents ,
v : Option < & str > ,
) -> bool {
if let Some ( v ) = v {
* slot = RemapPathScopeComponents ::empty ( ) ;
for s in v . split ( ',' ) {
* slot | = match s {
" macro " = > RemapPathScopeComponents ::MACRO ,
" diagnostics " = > RemapPathScopeComponents ::DIAGNOSTICS ,
2024-03-19 13:51:22 +01:00
" debuginfo " = > RemapPathScopeComponents ::DEBUGINFO ,
2023-08-23 11:18:20 +02:00
" object " = > RemapPathScopeComponents ::OBJECT ,
" all " = > RemapPathScopeComponents ::all ( ) ,
_ = > return false ,
}
}
true
} else {
false
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_relocation_model ( slot : & mut Option < RelocModel > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | RelocModel ::from_str ( s ) . ok ( ) ) {
Some ( relocation_model ) = > * slot = Some ( relocation_model ) ,
None if v = = Some ( " default " ) = > * slot = None ,
_ = > return false ,
2020-04-25 21:45:21 +03:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-04-25 21:45:21 +03:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_code_model ( slot : & mut Option < CodeModel > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | CodeModel ::from_str ( s ) . ok ( ) ) {
Some ( code_model ) = > * slot = Some ( code_model ) ,
_ = > return false ,
2019-12-17 23:22:55 +11:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-03-30 22:17:15 -07:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_tls_model ( slot : & mut Option < TlsModel > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | TlsModel ::from_str ( s ) . ok ( ) ) {
Some ( tls_model ) = > * slot = Some ( tls_model ) ,
_ = > return false ,
2020-03-30 22:17:15 -07:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-05-11 00:16:16 +03:00
2023-02-09 10:16:00 +00:00
pub ( crate ) fn parse_terminal_url ( slot : & mut TerminalUrl , v : Option < & str > ) -> bool {
* slot = match v {
Some ( " on " | " " | " yes " | " y " ) | None = > TerminalUrl ::Yes ,
Some ( " off " | " no " | " n " ) = > TerminalUrl ::No ,
Some ( " auto " ) = > TerminalUrl ::Auto ,
_ = > return false ,
} ;
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_symbol_mangling_version (
2021-05-01 18:48:25 -04:00
slot : & mut Option < SymbolManglingVersion > ,
v : Option < & str > ,
) -> bool {
* slot = match v {
Some ( " legacy " ) = > Some ( SymbolManglingVersion ::Legacy ) ,
Some ( " v0 " ) = > Some ( SymbolManglingVersion ::V0 ) ,
2023-12-05 12:42:57 +08:00
Some ( " hashed " ) = > Some ( SymbolManglingVersion ::Hashed ) ,
2021-05-01 18:48:25 -04:00
_ = > return false ,
} ;
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_src_file_hash (
2021-05-01 18:48:25 -04:00
slot : & mut Option < SourceFileHashAlgorithm > ,
v : Option < & str > ,
) -> bool {
match v . and_then ( | s | SourceFileHashAlgorithm ::from_str ( s ) . ok ( ) ) {
Some ( hash_kind ) = > * slot = Some ( hash_kind ) ,
_ = > return false ,
}
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_target_feature ( slot : & mut String , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( s ) = > {
if ! slot . is_empty ( ) {
2021-11-07 10:33:27 +01:00
slot . push ( ',' ) ;
2020-05-11 00:16:16 +03:00
}
2021-05-01 18:48:25 -04:00
slot . push_str ( s ) ;
true
2020-05-11 00:16:16 +03:00
}
2021-05-01 18:48:25 -04:00
None = > false ,
2020-05-11 00:16:16 +03:00
}
2021-05-01 18:48:25 -04:00
}
2020-12-12 21:38:23 -06:00
2023-06-21 21:46:36 +00:00
pub ( crate ) fn parse_link_self_contained ( slot : & mut LinkSelfContained , v : Option < & str > ) -> bool {
// Whenever `-C link-self-contained` is passed without a value, it's an opt-in
// just like `parse_opt_bool`, the historical value of this flag.
//
// 1. Parse historical single bool values
let s = v . unwrap_or ( " y " ) ;
match s {
" y " | " yes " | " on " = > {
slot . set_all_explicitly ( true ) ;
return true ;
}
" n " | " no " | " off " = > {
slot . set_all_explicitly ( false ) ;
return true ;
}
_ = > { }
}
// 2. Parse a list of enabled and disabled components.
2023-07-23 10:12:40 +02:00
for comp in s . split ( ',' ) {
2023-09-20 20:09:06 +00:00
if slot . handle_cli_component ( comp ) . is_none ( ) {
2023-06-21 21:46:36 +00:00
return false ;
}
}
true
}
2024-04-08 21:40:44 +00:00
/// Parse a comma-separated list of enabled and disabled linker features.
pub ( crate ) fn parse_linker_features ( slot : & mut LinkerFeaturesCli , v : Option < & str > ) -> bool {
match v {
Some ( s ) = > {
for feature in s . split ( ',' ) {
if slot . handle_cli_feature ( feature ) . is_none ( ) {
return false ;
}
}
true
}
None = > false ,
}
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_wasi_exec_model ( slot : & mut Option < WasiExecModel > , v : Option < & str > ) -> bool {
2021-05-01 18:48:25 -04:00
match v {
Some ( " command " ) = > * slot = Some ( WasiExecModel ::Command ) ,
Some ( " reactor " ) = > * slot = Some ( WasiExecModel ::Reactor ) ,
_ = > return false ,
2020-12-12 21:38:23 -06:00
}
2021-05-01 18:48:25 -04:00
true
}
2020-11-30 08:39:08 -08:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_split_debuginfo (
slot : & mut Option < SplitDebuginfo > ,
v : Option < & str > ,
) -> bool {
2021-05-01 18:48:25 -04:00
match v . and_then ( | s | SplitDebuginfo ::from_str ( s ) . ok ( ) ) {
Some ( e ) = > * slot = Some ( e ) ,
_ = > return false ,
2020-11-30 08:39:08 -08:00
}
2021-05-01 18:48:25 -04:00
true
2019-12-17 23:22:55 +11:00
}
2021-06-02 19:48:33 +10:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_split_dwarf_kind ( slot : & mut SplitDwarfKind , v : Option < & str > ) -> bool {
sess/cg: re-introduce split dwarf kind
In #79570, `-Z split-dwarf-kind={none,single,split}` was replaced by `-C
split-debuginfo={off,packed,unpacked}`. `-C split-debuginfo`'s packed
and unpacked aren't exact parallels to single and split, respectively.
On Unix, `-C split-debuginfo=packed` will put debuginfo into object
files and package debuginfo into a DWARF package file (`.dwp`) and
`-C split-debuginfo=unpacked` will put debuginfo into dwarf object files
and won't package it.
In the initial implementation of Split DWARF, split mode wrote sections
which did not require relocation into a DWARF object (`.dwo`) file which
was ignored by the linker and then packaged those DWARF objects into
DWARF packages (`.dwp`). In single mode, sections which did not require
relocation were written into object files but ignored by the linker and
were not packaged. However, both split and single modes could be
packaged or not, the primary difference in behaviour was where the
debuginfo sections that did not require link-time relocation were
written (in a DWARF object or the object file).
This commit re-introduces a `-Z split-dwarf-kind` flag, which can be
used to pick between split and single modes when `-C split-debuginfo` is
used to enable Split DWARF (either packed or unpacked).
Signed-off-by: David Wood <david.wood@huawei.com>
2021-10-08 16:10:17 +00:00
match v . and_then ( | s | SplitDwarfKind ::from_str ( s ) . ok ( ) ) {
Some ( e ) = > * slot = e ,
_ = > return false ,
}
true
}
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_stack_protector ( slot : & mut StackProtector , v : Option < & str > ) -> bool {
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
match v . and_then ( | s | StackProtector ::from_str ( s ) . ok ( ) ) {
Some ( ssp ) = > * slot = ssp ,
_ = > return false ,
}
true
}
2021-07-13 12:14:26 +01:00
2022-05-20 19:51:09 -04:00
pub ( crate ) fn parse_branch_protection (
slot : & mut Option < BranchProtection > ,
v : Option < & str > ,
) -> bool {
2021-07-13 12:14:26 +01:00
match v {
Some ( s ) = > {
2022-01-31 21:47:07 +02:00
let slot = slot . get_or_insert_default ( ) ;
2021-12-01 15:56:59 +00:00
for opt in s . split ( ',' ) {
2021-07-13 12:14:26 +01:00
match opt {
" bti " = > slot . bti = true ,
" pac-ret " if slot . pac_ret . is_none ( ) = > {
slot . pac_ret = Some ( PacRet { leaf : false , key : PAuthKey ::A } )
}
" leaf " = > match slot . pac_ret . as_mut ( ) {
Some ( pac ) = > pac . leaf = true ,
_ = > return false ,
} ,
" b-key " = > match slot . pac_ret . as_mut ( ) {
Some ( pac ) = > pac . key = PAuthKey ::B ,
_ = > return false ,
} ,
_ = > return false ,
} ;
}
}
_ = > return false ,
}
true
}
2022-06-18 14:15:03 -04:00
2024-01-11 01:36:05 +07:00
pub ( crate ) fn parse_collapse_macro_debuginfo (
slot : & mut CollapseMacroDebuginfo ,
v : Option < & str > ,
) -> bool {
2024-02-09 15:39:25 +03:00
if v . is_some ( ) {
let mut bool_arg = None ;
if parse_opt_bool ( & mut bool_arg , v ) {
* slot = if bool_arg . unwrap ( ) {
CollapseMacroDebuginfo ::Yes
} else {
CollapseMacroDebuginfo ::No
} ;
return true ;
}
}
2024-01-11 01:36:05 +07:00
* slot = match v {
Some ( " external " ) = > CollapseMacroDebuginfo ::External ,
_ = > return false ,
} ;
true
}
2022-06-18 14:15:03 -04:00
pub ( crate ) fn parse_proc_macro_execution_strategy (
slot : & mut ProcMacroExecutionStrategy ,
v : Option < & str > ,
) -> bool {
* slot = match v {
Some ( " same-thread " ) = > ProcMacroExecutionStrategy ::SameThread ,
Some ( " cross-thread " ) = > ProcMacroExecutionStrategy ::CrossThread ,
_ = > return false ,
} ;
true
}
2023-07-03 21:00:10 +01:00
2023-11-06 19:55:05 -05:00
pub ( crate ) fn parse_inlining_threshold ( slot : & mut InliningThreshold , v : Option < & str > ) -> bool {
match v {
Some ( " always " | " yes " ) = > {
* slot = InliningThreshold ::Always ;
}
Some ( " never " ) = > {
* slot = InliningThreshold ::Never ;
}
Some ( v ) = > {
if let Ok ( threshold ) = v . parse ( ) {
* slot = InliningThreshold ::Sometimes ( threshold ) ;
} else {
return false ;
}
}
None = > return false ,
}
true
}
2023-10-09 02:22:14 -07:00
pub ( crate ) fn parse_llvm_module_flag (
slot : & mut Vec < ( String , u32 , String ) > ,
v : Option < & str > ,
) -> bool {
let elements = v . unwrap_or_default ( ) . split ( ':' ) . collect ::< Vec < _ > > ( ) ;
let [ key , md_type , value , behavior ] = elements . as_slice ( ) else {
return false ;
} ;
if * md_type ! = " u32 " {
// Currently we only support u32 metadata flags, but require the
// type for forward-compatibility.
return false ;
}
let Ok ( value ) = value . parse ::< u32 > ( ) else {
return false ;
} ;
let behavior = behavior . to_lowercase ( ) ;
let all_behaviors =
[ " error " , " warning " , " require " , " override " , " append " , " appendunique " , " max " , " min " ] ;
if ! all_behaviors . contains ( & behavior . as_str ( ) ) {
return false ;
}
slot . push ( ( key . to_string ( ) , value , behavior ) ) ;
true
}
2023-10-18 16:58:17 +02:00
pub ( crate ) fn parse_function_return ( slot : & mut FunctionReturn , v : Option < & str > ) -> bool {
match v {
Some ( " keep " ) = > * slot = FunctionReturn ::Keep ,
Some ( " thunk-extern " ) = > * slot = FunctionReturn ::ThunkExtern ,
_ = > return false ,
}
true
}
2024-02-27 23:06:44 +01:00
pub ( crate ) fn parse_wasm_c_abi ( slot : & mut WasmCAbi , v : Option < & str > ) -> bool {
match v {
Some ( " spec " ) = > * slot = WasmCAbi ::Spec ,
Some ( " legacy " ) = > * slot = WasmCAbi ::Legacy ,
_ = > return false ,
}
true
}
2021-05-01 18:48:25 -04:00
}
2019-12-17 23:22:55 +11:00
2021-05-07 15:18:19 +03:00
options! {
2021-10-21 13:18:59 +02:00
CodegenOptions , CG_OPTIONS , cgopts , " C " , " codegen " ,
2020-04-21 10:06:13 +10:00
// If you add a new option, please update:
2020-10-26 20:54:51 +01:00
// - compiler/rustc_interface/src/tests.rs
2020-04-21 10:06:13 +10:00
// - src/doc/rustc/src/codegen-options/index.md
2022-10-05 21:46:21 +02:00
// tidy-alphabetical-start
2020-04-02 16:44:47 +11:00
ar : String = ( String ::new ( ) , parse_string , [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
" this option is deprecated and does nothing " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::code_model` instead of this field " ) ]
2020-05-07 03:34:27 +03:00
code_model : Option < CodeModel > = ( None , parse_code_model , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" choose the code model to use (`rustc --print code-models` for details) " ) ,
2021-02-24 00:00:00 +00:00
codegen_units : Option < usize > = ( None , parse_opt_number , [ UNTRACKED ] ,
2020-04-21 10:06:13 +10:00
" divide crate into N units to optimize in parallel " ) ,
2024-02-09 15:39:25 +03:00
collapse_macro_debuginfo : CollapseMacroDebuginfo = ( CollapseMacroDebuginfo ::Unspecified ,
parse_collapse_macro_debuginfo , [ TRACKED ] ,
" set option to collapse debuginfo for macros " ) ,
2020-07-14 15:27:42 +01:00
control_flow_guard : CFGuard = ( CFGuard ::Disabled , parse_cfguard , [ TRACKED ] ,
" use Windows Control Flow Guard (default: no) " ) ,
2020-04-21 10:06:13 +10:00
debug_assertions : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" explicitly enable the `cfg(debug_assertions)` directive " ) ,
2021-04-06 16:00:35 -04:00
debuginfo : DebugInfo = ( DebugInfo ::None , parse_debuginfo , [ TRACKED ] ,
" debug info emission level (0-2, none, line-directives-only, \
line - tables - only , limited , or full ; default : 0 ) " ),
2020-04-21 10:06:13 +10:00
default_linker_libraries : bool = ( false , parse_bool , [ UNTRACKED ] ,
" allow the linker to link its default libraries (default: no) " ) ,
2023-03-27 10:42:22 -07:00
dlltool : Option < PathBuf > = ( None , parse_opt_pathbuf , [ UNTRACKED ] ,
" import library generation tool (ignored except when targeting windows-gnu) " ) ,
2020-04-30 10:53:16 -07:00
embed_bitcode : bool = ( true , parse_bool , [ TRACKED ] ,
" emit bitcode in rlibs (default: yes) " ) ,
2020-04-21 10:06:13 +10:00
extra_filename : String = ( String ::new ( ) , parse_string , [ UNTRACKED ] ,
" extra data to put in each output filename " ) ,
force_frame_pointers : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" force use of the frame pointers " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::must_emit_unwind_tables` instead of this field " ) ]
Add Option to Force Unwind Tables
When panic != unwind, `nounwind` is added to all functions for a target.
This can cause issues when a panic happens with RUST_BACKTRACE=1, as
there needs to be a way to reconstruct the backtrace. There are three
possible sources of this information: forcing frame pointers (for which
an option exists already), debug info (for which an option exists), or
unwind tables.
Especially for embedded devices, forcing frame pointers can have code
size overheads (RISC-V sees ~10% overheads, ARM sees ~2-3% overheads).
In code, it can be the case that debug info is not kept, so it is useful
to provide this third option, unwind tables, that users can use to
reconstruct the call stack. Reconstructing this stack is harder than
with frame pointers, but it is still possible.
This commit adds a compiler option which allows a user to force the
addition of unwind tables. Unwind tables cannot be disabled on targets
that require them for correctness, or when using `-C panic=unwind`.
2020-05-04 12:08:35 +01:00
force_unwind_tables : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" force use of unwind tables " ) ,
2020-04-21 10:06:13 +10:00
incremental : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
" enable incremental compilation " ) ,
2021-02-24 00:00:00 +00:00
inline_threshold : Option < u32 > = ( None , parse_opt_number , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" set the threshold for inlining a function " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::instrument_coverage` instead of this field " ) ]
2023-10-25 14:57:25 +11:00
instrument_coverage : InstrumentCoverage = ( InstrumentCoverage ::No , parse_instrument_coverage , [ TRACKED ] ,
2024-03-12 12:30:33 +11:00
" instrument the generated code to support LLVM source-based code coverage reports \
( note , the compiler build config must include ` profiler = true ` ) ; \
implies ` - C symbol - mangling - version = v0 ` " ),
2020-04-01 19:17:08 +03:00
link_arg : ( /* redirected to link_args */ ) = ( ( ) , parse_string_push , [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
" a single extra argument to append to the linker invocation (can be used several times) " ) ,
2020-04-01 19:17:08 +03:00
link_args : Vec < String > = ( Vec ::new ( ) , parse_list , [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
" extra arguments to append to the linker invocation (space separated) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::link_dead_code` instead of this field " ) ]
2021-04-15 15:05:26 -04:00
link_dead_code : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
2020-04-03 10:42:29 +11:00
" keep dead code at link time (useful for code coverage) (default: no) " ) ,
2023-06-21 21:46:36 +00:00
link_self_contained : LinkSelfContained = ( LinkSelfContained ::default ( ) , parse_link_self_contained , [ UNTRACKED ] ,
2020-07-30 22:10:48 +02:00
" control whether to link Rust provided C objects/libraries or rely
2023-06-21 21:46:36 +00:00
on a C toolchain or linker installed in the system " ),
2020-04-21 10:06:13 +10:00
linker : Option < PathBuf > = ( None , parse_opt_pathbuf , [ UNTRACKED ] ,
" system linker to link outputs with " ) ,
2022-08-14 20:28:34 +03:00
linker_flavor : Option < LinkerFlavorCli > = ( None , parse_linker_flavor , [ UNTRACKED ] ,
2020-04-21 10:06:13 +10:00
" linker flavor " ) ,
linker_plugin_lto : LinkerPluginLto = ( LinkerPluginLto ::Disabled ,
parse_linker_plugin_lto , [ TRACKED ] ,
" generate build artifacts that are compatible with linker-based LTO " ) ,
2019-12-17 23:22:55 +11:00
llvm_args : Vec < String > = ( Vec ::new ( ) , parse_list , [ TRACKED ] ,
" a list of arguments to pass to LLVM (space separated) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::lto` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
lto : LtoCli = ( LtoCli ::Unspecified , parse_lto , [ TRACKED ] ,
" perform LLVM link-time optimizations " ) ,
metadata : Vec < String > = ( Vec ::new ( ) , parse_list , [ TRACKED ] ,
" metadata to mangle symbol names with " ) ,
2020-04-06 09:29:19 +10:00
no_prepopulate_passes : bool = ( false , parse_no_flag , [ TRACKED ] ,
" give an empty list of passes to the pass manager " ) ,
2019-12-17 23:22:55 +11:00
no_redzone : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" disable the use of the redzone " ) ,
2020-04-06 09:29:19 +10:00
no_stack_check : bool = ( false , parse_no_flag , [ UNTRACKED ] ,
2020-04-03 10:42:29 +11:00
" this option is deprecated and does nothing " ) ,
2020-04-21 10:06:13 +10:00
no_vectorize_loops : bool = ( false , parse_no_flag , [ TRACKED ] ,
" disable loop vectorization optimization passes " ) ,
no_vectorize_slp : bool = ( false , parse_no_flag , [ TRACKED ] ,
" disable LLVM's SLP vectorization pass " ) ,
2020-04-02 16:44:47 +11:00
opt_level : String = ( " 0 " . to_string ( ) , parse_string , [ TRACKED ] ,
2020-04-03 10:42:29 +11:00
" optimization level (0-3, s, or z; default: 0) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::overflow_checks` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
overflow_checks : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" use overflow checks for integer arithmetic " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::panic_strategy` instead of this field " ) ]
2021-09-06 12:21:47 +02:00
panic : Option < PanicStrategy > = ( None , parse_opt_panic_strategy , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" panic strategy to compile crate with " ) ,
passes : Vec < String > = ( Vec ::new ( ) , parse_list , [ TRACKED ] ,
" a list of extra LLVM passes to run (space separated) " ) ,
prefer_dynamic : bool = ( false , parse_bool , [ TRACKED ] ,
" prefer dynamic linking to static linking (default: no) " ) ,
2019-12-17 23:22:55 +11:00
profile_generate : SwitchWithOptPath = ( SwitchWithOptPath ::Disabled ,
parse_switch_with_opt_path , [ TRACKED ] ,
" compile the program with profiling instrumentation " ) ,
profile_use : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" use the given `.profdata` file for profile-guided optimization " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::relocation_model` instead of this field " ) ]
2020-04-23 00:46:45 +03:00
relocation_model : Option < RelocModel > = ( None , parse_relocation_model , [ TRACKED ] ,
2020-04-24 00:53:25 +03:00
" control generation of position-independent code (PIC) \
( ` rustc - - print relocation - models ` for details ) " ),
2024-02-27 15:05:02 +00:00
relro_level : Option < RelroLevel > = ( None , parse_relro_level , [ TRACKED ] ,
" choose which RELRO level to use " ) ,
2020-04-21 10:06:13 +10:00
remark : Passes = ( Passes ::Some ( Vec ::new ( ) ) , parse_passes , [ UNTRACKED ] ,
2023-06-25 23:39:02 +02:00
" output remarks for these optimization passes (space separated, or \" all \" ) " ) ,
2020-04-21 10:06:13 +10:00
rpath : bool = ( false , parse_bool , [ UNTRACKED ] ,
" set rpath values in libs/exes (default: no) " ) ,
save_temps : bool = ( false , parse_bool , [ UNTRACKED ] ,
" save all temporary output files during compilation (default: no) " ) ,
soft_float : bool = ( false , parse_bool , [ TRACKED ] ,
" use soft float ABI (*eabihf targets only) (default: no) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::split_debuginfo` instead of this field " ) ]
2020-11-30 08:39:08 -08:00
split_debuginfo : Option < SplitDebuginfo > = ( None , parse_split_debuginfo , [ TRACKED ] ,
" how to handle split-debuginfo, a platform-specific option " ) ,
2021-10-21 13:19:46 +02:00
strip : Strip = ( Strip ::None , parse_strip , [ UNTRACKED ] ,
" tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`) " ) ,
2021-10-21 14:02:59 +02:00
symbol_mangling_version : Option < SymbolManglingVersion > = ( None ,
parse_symbol_mangling_version , [ TRACKED ] ,
2023-12-05 12:42:57 +08:00
" which mangling version to use for symbol names ('legacy' (default), 'v0', or 'hashed') " ) ,
2020-04-21 10:06:13 +10:00
target_cpu : Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
" select target processor (`rustc --print target-cpus` for details) " ) ,
2020-05-11 00:16:16 +03:00
target_feature : String = ( String ::new ( ) , parse_target_feature , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" target specific attributes. (`rustc --print target-features` for details). \
This feature is unsafe . " ),
2022-10-05 21:46:21 +02:00
// tidy-alphabetical-end
2020-04-21 10:06:13 +10:00
// If you add a new option, please update:
2020-10-26 20:54:51 +01:00
// - compiler/rustc_interface/src/tests.rs
2020-04-21 10:06:13 +10:00
// - src/doc/rustc/src/codegen-options/index.md
2019-12-17 23:22:55 +11:00
}
2021-05-07 15:18:19 +03:00
options! {
2022-07-06 07:44:47 -05:00
UnstableOptions , Z_OPTIONS , dbopts , " Z " , " unstable " ,
2020-04-21 10:06:13 +10:00
// If you add a new option, please update:
2020-10-26 20:54:51 +01:00
// - compiler/rustc_interface/src/tests.rs
2022-07-06 07:44:47 -05:00
// - src/doc/unstable-book/src/compiler-flags
2020-04-21 10:06:13 +10:00
2022-10-05 21:46:21 +02:00
// tidy-alphabetical-start
2020-04-21 10:06:13 +10:00
allow_features : Option < Vec < String > > = ( None , parse_opt_comma_list , [ TRACKED ] ,
2023-01-09 12:36:39 -08:00
" only allow the listed language features to be enabled in code (comma separated) " ) ,
2020-04-21 10:06:13 +10:00
always_encode_mir : bool = ( false , parse_bool , [ TRACKED ] ,
" encode MIR of all functions into the crate metadata (default: no) " ) ,
2019-12-17 23:22:55 +11:00
asm_comments : bool = ( false , parse_bool , [ TRACKED ] ,
2020-04-03 10:42:29 +11:00
" generate comments into the assembly (may change behavior) (default: no) " ) ,
2021-10-31 17:05:48 -05:00
assert_incr_state : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
" assert that the incremental cache is in given state: \
either ` loaded ` or ` not - loaded ` . " ),
2022-10-05 21:46:21 +02:00
assume_incomplete_release : bool = ( false , parse_bool , [ TRACKED ] ,
" make cfg(version) treat the current version as incomplete (default: no) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::binary_dep_depinfo` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
binary_dep_depinfo : bool = ( false , parse_bool , [ TRACKED ] ,
" include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
( default : no ) " ),
2023-01-06 00:00:00 +00:00
box_noalias : bool = ( true , parse_bool , [ TRACKED ] ,
2022-07-18 18:17:27 +02:00
" emit noalias metadata for box (default: yes) " ) ,
2022-01-31 21:47:07 +02:00
branch_protection : Option < BranchProtection > = ( None , parse_branch_protection , [ TRACKED ] ,
2021-12-01 15:56:59 +00:00
" set options for branch target identification and pointer authentication on AArch64 " ) ,
2022-01-28 09:48:59 -08:00
cf_protection : CFProtection = ( CFProtection ::None , parse_cfprotection , [ TRACKED ] ,
" instrument control-flow architecture protection " ) ,
2024-02-16 21:32:53 +01:00
check_cfg_all_expected : bool = ( false , parse_bool , [ UNTRACKED ] ,
" show all expected values in check-cfg diagnostics (default: no) " ) ,
2020-04-21 10:06:13 +10:00
codegen_backend : Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
" the backend to use " ) ,
2020-09-09 14:51:16 +10:00
combine_cgu : bool = ( false , parse_bool , [ TRACKED ] ,
" combine CGUs into a single one " ) ,
2024-03-08 18:07:04 +11:00
coverage_options : CoverageOptions = ( CoverageOptions ::default ( ) , parse_coverage_options , [ TRACKED ] ,
" control details of coverage instrumentation " ) ,
2020-04-21 10:06:13 +10:00
crate_attr : Vec < String > = ( Vec ::new ( ) , parse_string_push , [ TRACKED ] ,
" inject the given attribute in the crate " ) ,
2023-11-06 19:55:05 -05:00
cross_crate_inline_threshold : InliningThreshold = ( InliningThreshold ::Sometimes ( 100 ) , parse_inlining_threshold , [ TRACKED ] ,
2023-10-06 20:29:42 -04:00
" threshold to allow cross crate inlining of functions " ) ,
2021-05-07 07:41:37 +00:00
debug_info_for_profiling : bool = ( false , parse_bool , [ TRACKED ] ,
" emit discriminators and other data necessary for AutoFDO " ) ,
2023-09-05 09:56:51 -04:00
debuginfo_compression : DebugInfoCompression = ( DebugInfoCompression ::None , parse_debuginfo_compression , [ TRACKED ] ,
" compress debug info sections (none, zlib, zstd, default: none) " ) ,
2020-04-21 10:06:13 +10:00
deduplicate_diagnostics : bool = ( true , parse_bool , [ UNTRACKED ] ,
" deduplicate identical diagnostics (default: yes) " ) ,
2023-12-13 21:14:18 +00:00
default_hidden_visibility : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" overrides the `default_hidden_visibility` setting of the target " ) ,
2020-04-21 10:06:13 +10:00
dep_info_omit_d_target : bool = ( false , parse_bool , [ TRACKED ] ,
" in dep-info output, omit targets for tracking dependencies of the dep-info files \
themselves ( default : no ) " ),
2023-12-14 22:07:53 +08:00
direct_access_external_data : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" Direct or use GOT indirect to reference external data symbols " ) ,
2020-04-21 10:06:13 +10:00
dual_proc_macros : bool = ( false , parse_bool , [ TRACKED ] ,
" load proc macros for both target and host, but only link to the target (default: no) " ) ,
2019-12-17 23:22:55 +11:00
dump_dep_graph : bool = ( false , parse_bool , [ UNTRACKED ] ,
2020-04-03 10:42:29 +11:00
" dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
( default : no ) " ),
2019-12-17 23:22:55 +11:00
dump_mir : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
" dump MIR state to file.
` val ` is used to select which passes and functions to dump . For example :
` all ` matches all passes and functions ,
` foo ` matches all passes for functions whose name contains ' foo ' ,
` foo & ConstProp ` only the ' ConstProp ' pass for function names containing ' foo ' ,
` foo | bar ` all passes for function names containing ' foo ' or ' bar ' . " ),
2020-04-21 10:06:13 +10:00
dump_mir_dataflow : bool = ( false , parse_bool , [ UNTRACKED ] ,
" in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
( default : no ) " ),
2020-04-02 16:44:47 +11:00
dump_mir_dir : String = ( " mir_dump " . to_string ( ) , parse_string , [ UNTRACKED ] ,
2020-04-03 10:42:29 +11:00
" the directory the MIR is dumped into (default: `mir_dump`) " ) ,
2019-12-17 23:22:55 +11:00
dump_mir_exclude_pass_number : bool = ( false , parse_bool , [ UNTRACKED ] ,
2020-04-03 10:42:29 +11:00
" exclude the pass number when dumping MIR (used in tests) (default: no) " ) ,
2020-04-21 10:06:13 +10:00
dump_mir_graphviz : bool = ( false , parse_bool , [ UNTRACKED ] ,
2023-09-19 20:26:23 +10:00
" in addition to `.mir` files, create graphviz `.dot` files (default: no) " ) ,
2022-12-08 19:21:08 +00:00
dump_mono_stats : SwitchWithOptPath = ( SwitchWithOptPath ::Disabled ,
parse_switch_with_opt_path , [ UNTRACKED ] ,
2022-12-29 21:08:09 +00:00
" output statistics about monomorphization collection " ) ,
dump_mono_stats_format : DumpMonoStatsFormat = ( DumpMonoStatsFormat ::Markdown , parse_dump_mono_stats , [ UNTRACKED ] ,
" the format to use for -Z dump-mono-stats (`markdown` (default) or `json`) " ) ,
2022-06-20 16:26:51 -07:00
dwarf_version : Option < u32 > = ( None , parse_opt_number , [ TRACKED ] ,
" version of DWARF debug information to emit (default: 2 or 4, depending on platform) " ) ,
2022-09-29 16:31:03 +02:00
dylib_lto : bool = ( false , parse_bool , [ UNTRACKED ] ,
" enables LTO for dylib crate type " ) ,
2024-01-12 00:30:04 +00:00
eagerly_emit_delayed_bugs : bool = ( false , parse_bool , [ UNTRACKED ] ,
" emit delayed bugs eagerly as errors instead of stashing them and emitting \
them only if an error has not been emitted " ),
2023-11-21 14:24:23 -08:00
ehcont_guard : bool = ( false , parse_bool , [ TRACKED ] ,
" generate Windows EHCont Guard tables " ) ,
2020-04-21 10:06:13 +10:00
emit_stack_sizes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" emit a section containing stack size metadata (default: no) " ) ,
2022-06-08 17:30:16 +03:00
emit_thin_lto : bool = ( true , parse_bool , [ TRACKED ] ,
" emit the bc module with thin LTO info (default: yes) " ) ,
2022-07-25 05:20:23 +00:00
export_executable_symbols : bool = ( false , parse_bool , [ TRACKED ] ,
" export symbols from executables, as if they were dynamic libraries " ) ,
2023-10-17 16:18:59 -07:00
external_clangrt : bool = ( false , parse_bool , [ UNTRACKED ] ,
" rely on user specified linker commands to find clangrt " ) ,
2022-08-07 08:30:03 -04:00
extra_const_ub_checks : bool = ( false , parse_bool , [ TRACKED ] ,
" turns on more checks to detect const UB, which can be slow (default: no) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::fewer_names` instead of this field " ) ]
2020-11-23 00:00:00 +00:00
fewer_names : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
( default : no ) " ),
2024-05-03 14:32:01 +02:00
fixed_x18 : bool = ( false , parse_bool , [ TRACKED ] ,
" make the x18 register reserved on AArch64 (default: no) " ) ,
2023-04-06 12:29:43 +02:00
flatten_format_args : bool = ( true , parse_bool , [ TRACKED ] ,
2023-03-16 11:13:07 +01:00
" flatten nested format_args!() and literals into a simplified format_args!() call \
2023-04-06 12:29:43 +02:00
( default : yes ) " ),
2020-04-21 10:06:13 +10:00
force_unstable_if_unmarked : bool = ( false , parse_bool , [ TRACKED ] ,
" force all crates to be `rustc_private` unstable (default: no) " ) ,
fuel : Option < ( String , u64 ) > = ( None , parse_optimization_fuel , [ TRACKED ] ,
" set the optimization fuel quota for a crate " ) ,
2023-10-18 16:58:17 +02:00
function_return : FunctionReturn = ( FunctionReturn ::default ( ) , parse_function_return , [ TRACKED ] ,
" replace returns with jumps to `__x86_return_thunk` (default: `keep`) " ) ,
2020-10-26 20:55:07 +01:00
function_sections : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" whether each function should go in its own section " ) ,
2021-06-19 17:06:46 -07:00
future_incompat_test : bool = ( false , parse_bool , [ UNTRACKED ] ,
" forces all lints to be future incompatible, used for internal testing (default: no) " ) ,
2020-09-08 16:08:35 -07:00
graphviz_dark_mode : bool = ( false , parse_bool , [ UNTRACKED ] ,
" use dark-themed colors in graphviz output (default: no) " ) ,
2020-09-16 08:10:06 -07:00
graphviz_font : String = ( " Courier, monospace " . to_string ( ) , parse_string , [ UNTRACKED ] ,
2020-09-16 10:47:56 -07:00
" use the given `fontname` in graphviz output; can be overridden by setting \
environment variable ` RUSTC_GRAPHVIZ_FONT ` ( default : ` Courier , monospace ` ) " ),
2023-11-13 20:48:23 +08:00
has_thread_local : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" explicitly enable the `cfg(target_thread_local)` directive " ) ,
2020-04-21 10:06:13 +10:00
hir_stats : bool = ( false , parse_bool , [ UNTRACKED ] ,
2020-04-03 10:42:29 +11:00
" print some statistics about AST and HIR (default: no) " ) ,
2020-04-21 10:06:13 +10:00
human_readable_cgu_names : bool = ( false , parse_bool , [ TRACKED ] ,
" generate human-readable, predictable names for codegen units (default: no) " ) ,
identify_regions : bool = ( false , parse_bool , [ UNTRACKED ] ,
" display unnamed regions as `'<id>`, using a non-ident unique id (default: no) " ) ,
2023-09-15 15:32:34 +02:00
ignore_directory_in_diagnostics_source_blocks : Vec < String > = ( Vec ::new ( ) , parse_string_push , [ UNTRACKED ] ,
" do not display the source code block in diagnostics for files in the directory " ) ,
2022-10-31 16:39:45 +00:00
incremental_ignore_spans : bool = ( false , parse_bool , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" ignore spans during ICH computation -- used for testing (default: no) " ) ,
incremental_info : bool = ( false , parse_bool , [ UNTRACKED ] ,
" print high-level information about incremental reuse (or the lack thereof) \
( default : no ) " ),
incremental_verify_ich : bool = ( false , parse_bool , [ UNTRACKED ] ,
2024-03-09 09:29:16 +01:00
" verify extended properties for incr. comp. (default: no):
- hashes of green query instances
- hash collisions of query keys " ),
2022-10-05 21:46:21 +02:00
inline_in_all_cgus : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" control whether `#[inline]` functions are in all CGUs " ) ,
2022-08-08 16:58:27 -07:00
inline_llvm : bool = ( true , parse_bool , [ TRACKED ] ,
" enable LLVM inlining (default: yes) " ) ,
2021-02-21 00:00:00 +00:00
inline_mir : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" enable MIR inlining (default: no) " ) ,
2021-02-24 00:00:00 +00:00
inline_mir_hint_threshold : Option < usize > = ( None , parse_opt_number , [ TRACKED ] ,
2020-11-10 00:00:00 +00:00
" inlining threshold for functions with inline hint (default: 100) " ) ,
2024-04-17 18:14:16 -07:00
inline_mir_preserve_debug : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" when MIR inlining, whether to preserve debug info for callee variables \
( default : preserve for debuginfo ! = None , otherwise remove ) " ),
2022-10-05 21:46:21 +02:00
inline_mir_threshold : Option < usize > = ( None , parse_opt_number , [ TRACKED ] ,
" a default MIR inlining threshold (default: 50) " ) ,
2020-04-21 10:06:13 +10:00
input_stats : bool = ( false , parse_bool , [ UNTRACKED ] ,
" gather statistics about the input (default: no) " ) ,
instrument_mcount : bool = ( false , parse_bool , [ TRACKED ] ,
" insert function instrument code for mcount-based tracing (default: no) " ) ,
2022-09-24 20:02:44 +09:00
instrument_xray : Option < InstrumentXRay > = ( None , parse_instrument_xray , [ TRACKED ] ,
" insert function instrument code for XRay-based tracing (default: no)
Optional extra settings :
` = always `
` = never `
` = ignore - loops `
` = instruction - threshold = N `
` = skip - entry `
` = skip - exit `
Multiple options can be combined with commas . " ),
2022-10-05 21:46:21 +02:00
layout_seed : Option < u64 > = ( None , parse_opt_number , [ TRACKED ] ,
" seed layout randomization " ) ,
2023-02-04 15:07:41 -08:00
link_directives : bool = ( true , parse_bool , [ TRACKED ] ,
2023-02-08 12:05:53 -08:00
" honor #[link] directives in the compiled crate (default: yes) " ) ,
2020-04-21 10:06:13 +10:00
link_native_libraries : bool = ( true , parse_bool , [ UNTRACKED ] ,
" link native libraries in the linker invocation (default: yes) " ) ,
link_only : bool = ( false , parse_bool , [ TRACKED ] ,
" link the `.rlink` file generated by `-Z no-link` (default: no) " ) ,
2024-04-08 21:40:44 +00:00
linker_features : LinkerFeaturesCli = ( LinkerFeaturesCli ::default ( ) , parse_linker_features , [ UNTRACKED ] ,
" a comma-separated list of linker features to enable (+) or disable (-): `lld` " ) ,
2023-12-12 00:00:00 +00:00
lint_mir : bool = ( false , parse_bool , [ UNTRACKED ] ,
" lint MIR before and after each transformation " ) ,
2023-10-09 02:22:14 -07:00
llvm_module_flag : Vec < ( String , u32 , String ) > = ( Vec ::new ( ) , parse_llvm_module_flag , [ TRACKED ] ,
" a list of module flags to pass to LLVM (space separated) " ) ,
2021-06-13 18:23:01 +02:00
llvm_plugins : Vec < String > = ( Vec ::new ( ) , parse_list , [ TRACKED ] ,
" a list LLVM plugins to enable (space separated) " ) ,
2020-04-21 10:06:13 +10:00
llvm_time_trace : bool = ( false , parse_bool , [ UNTRACKED ] ,
" generate JSON tracing data file from LLVM data (default: no) " ) ,
2021-10-13 17:01:31 -07:00
location_detail : LocationDetail = ( LocationDetail ::all ( ) , parse_location_detail , [ TRACKED ] ,
2022-07-22 12:21:32 -07:00
" what location details should be tracked when using caller_location, either \
` none ` , or a comma separated list of location details , for which \
valid options are ` file ` , ` line ` , and ` column ` ( default : ` file , line , column ` ) " ),
2023-09-10 13:24:20 +00:00
ls : Vec < String > = ( Vec ::new ( ) , parse_list , [ UNTRACKED ] ,
2023-09-12 14:42:53 +00:00
" decode and print various parts of the crate metadata for a library crate \
2023-09-10 13:24:20 +00:00
( space separated ) " ),
2020-04-21 10:06:13 +10:00
macro_backtrace : bool = ( false , parse_bool , [ UNTRACKED ] ,
" show macro backtraces (default: no) " ) ,
2022-12-04 21:07:55 -08:00
maximal_hir_to_mir_coverage : bool = ( false , parse_bool , [ TRACKED ] ,
" save as much information as possible about the correspondence between MIR and HIR \
as source scopes ( default : no ) " ),
2020-04-21 10:06:13 +10:00
merge_functions : Option < MergeFunctions > = ( None , parse_merge_functions , [ TRACKED ] ,
" control the operation of the MergeFunctions LLVM pass, taking \
the same values as the target option of the same name " ),
meta_stats : bool = ( false , parse_bool , [ UNTRACKED ] ,
" gather metadata statistics (default: no) " ) ,
mir_emit_retag : bool = ( false , parse_bool , [ TRACKED ] ,
" emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
( default : no ) " ),
2022-04-11 15:17:52 -04:00
mir_enable_passes : Vec < ( String , bool ) > = ( Vec ::new ( ) , parse_list_with_polarity , [ TRACKED ] ,
2023-10-10 11:08:47 +02:00
" use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the \
specified passes to be enabled , overriding all other checks . In particular , this will \
enable unsound ( known - buggy and hence usually disabled ) passes without further warning ! \
Passes that are not specified are enabled or disabled by other flags as usual . " ),
2023-06-06 09:47:00 -04:00
mir_include_spans : bool = ( false , parse_bool , [ UNTRACKED ] ,
" use line numbers relative to the function in mir pretty printing " ) ,
2023-03-18 16:11:48 +00:00
mir_keep_place_mention : bool = ( false , parse_bool , [ TRACKED ] ,
" keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
( default : no ) " ),
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::mir_opt_level` instead of this field " ) ]
2021-02-24 00:00:00 +00:00
mir_opt_level : Option < usize > = ( None , parse_opt_number , [ TRACKED ] ,
2021-03-04 21:11:28 -03:00
" MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds) " ) ,
2021-06-19 00:00:00 +00:00
move_size_limit : Option < usize > = ( None , parse_opt_number , [ TRACKED ] ,
" the size at which the `large_assignments` lint starts to be emitted " ) ,
2023-01-06 00:00:00 +00:00
mutable_noalias : bool = ( true , parse_bool , [ TRACKED ] ,
2021-11-05 12:01:59 -07:00
" emit noalias metadata for mutable references (default: yes) " ) ,
2023-12-14 13:00:23 +01:00
next_solver : Option < NextSolverConfig > = ( None , parse_next_solver_config , [ TRACKED ] ,
" enable and configure the next generation trait solver used by rustc " ) ,
2020-04-21 10:06:13 +10:00
nll_facts : bool = ( false , parse_bool , [ UNTRACKED ] ,
" dump facts from NLL analysis into side files (default: no) " ) ,
2020-10-30 17:59:43 +01:00
nll_facts_dir : String = ( " nll-facts " . to_string ( ) , parse_string , [ UNTRACKED ] ,
" the directory the NLL facts are dumped into (default: `nll-facts`) " ) ,
2020-04-21 10:06:13 +10:00
no_analysis : bool = ( false , parse_no_flag , [ UNTRACKED ] ,
" parse and expand the source, but run no analysis " ) ,
2021-06-09 16:51:58 -07:00
no_codegen : bool = ( false , parse_no_flag , [ TRACKED_NO_CRATE_HASH ] ,
2020-04-21 10:06:13 +10:00
" run all passes except codegen; no output " ) ,
no_generate_arange_section : bool = ( false , parse_no_flag , [ TRACKED ] ,
" omit DWARF address ranges that give faster lookups " ) ,
2024-01-16 18:39:00 -05:00
no_implied_bounds_compat : bool = ( false , parse_bool , [ TRACKED ] ,
" disable the compatibility version of the `implied_bounds_ty` query " ) ,
2022-12-17 02:50:08 +01:00
no_jump_tables : bool = ( false , parse_no_flag , [ TRACKED ] ,
" disable the jump tables and lookup tables that can be generated from a switch case lowering " ) ,
2020-04-21 10:06:13 +10:00
no_leak_check : bool = ( false , parse_no_flag , [ UNTRACKED ] ,
" disable the 'leak check' for subtyping; unsound, but useful for tests " ) ,
no_link : bool = ( false , parse_no_flag , [ TRACKED ] ,
" compile without linking " ) ,
2024-02-15 00:14:44 +00:00
no_parallel_backend : bool = ( false , parse_no_flag , [ UNTRACKED ] ,
2020-04-21 10:06:13 +10:00
" run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO) " ) ,
2021-08-04 10:43:44 +01:00
no_profiler_runtime : bool = ( false , parse_no_flag , [ TRACKED ] ,
" prevent automatic injection of the profiler_builtins crate " ) ,
2023-08-17 12:07:22 +01:00
no_trait_vptr : bool = ( false , parse_no_flag , [ TRACKED ] ,
" disable generation of trait vptr in vtable for upcasting " ) ,
2022-10-05 21:46:21 +02:00
no_unique_section_names : bool = ( false , parse_bool , [ TRACKED ] ,
" do not use unique names for text and data sections when -Z function-sections is used " ) ,
2020-11-28 19:19:41 -05:00
normalize_docs : bool = ( false , parse_bool , [ TRACKED ] ,
" normalize associated items in rustdoc when generating documentation " ) ,
2024-04-28 18:02:21 +02:00
on_broken_pipe : OnBrokenPipe = ( OnBrokenPipe ::Default , parse_on_broken_pipe , [ TRACKED ] ,
" behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE) " ) ,
2021-10-06 15:52:54 +01:00
oom : OomStrategy = ( OomStrategy ::Abort , parse_oom_strategy , [ TRACKED ] ,
" panic strategy for out-of-memory handling " ) ,
2019-12-17 23:22:55 +11:00
osx_rpath_install_name : bool = ( false , parse_bool , [ TRACKED ] ,
2020-04-03 10:42:29 +11:00
" pass `-install_name @rpath/...` to the macOS linker (default: no) " ) ,
2022-08-24 13:10:40 +03:00
packed_bundled_libs : bool = ( false , parse_bool , [ TRACKED ] ,
" change rlib format to store native libraries as archives " ) ,
2020-04-21 10:06:13 +10:00
panic_abort_tests : bool = ( false , parse_bool , [ TRACKED ] ,
" support compiling tests with panic=abort (default: no) " ) ,
2021-09-06 12:21:47 +02:00
panic_in_drop : PanicStrategy = ( PanicStrategy ::Unwind , parse_panic_strategy , [ TRACKED ] ,
" panic strategy for panics in drops " ) ,
2020-04-21 10:06:13 +10:00
parse_only : bool = ( false , parse_bool , [ UNTRACKED ] ,
" parse only; do not compile, assemble, or link (default: no) " ) ,
plt : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" whether to use the PLT when calling into shared libraries;
only has effect for PIC code on systems with ELF binaries
2023-04-05 15:02:57 -04:00
( default : PLT is disabled if full relro is enabled on x86_64 ) " ),
2023-06-30 11:55:38 +00:00
polonius : Polonius = ( Polonius ::default ( ) , parse_polonius , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" enable polonius-based borrow-checker (default: no) " ) ,
2020-07-22 15:03:56 +01:00
polymorphize : bool = ( false , parse_bool , [ TRACKED ] ,
2020-06-22 13:57:03 +01:00
" perform polymorphization analysis " ) ,
2020-04-01 19:17:08 +03:00
pre_link_arg : ( /* redirected to pre_link_args */ ) = ( ( ) , parse_string_push , [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
" a single extra argument to prepend the linker invocation (can be used several times) " ) ,
2020-04-01 19:17:08 +03:00
pre_link_args : Vec < String > = ( Vec ::new ( ) , parse_list , [ UNTRACKED ] ,
2019-12-17 23:22:55 +11:00
" extra arguments to prepend to the linker invocation (space separated) " ) ,
2020-10-01 11:31:43 -07:00
precise_enum_drop_elaboration : bool = ( true , parse_bool , [ TRACKED ] ,
" use a more precise version of drop elaboration for matches on enums (default: yes). \
This results in better codegen , but has caused miscompilations on some tier 2 platforms . \
See #77382 and #74551. " ),
2023-07-17 00:37:52 +09:00
#[ rustc_lint_opt_deny_field_access( " use `Session::print_codegen_stats` instead of this field " ) ]
print_codegen_stats : bool = ( false , parse_bool , [ UNTRACKED ] ,
" print codegen statistics (default: no) " ) ,
2020-04-21 10:06:13 +10:00
print_fuel : Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
" make rustc print the total optimization fuel used by a crate " ) ,
print_llvm_passes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" print the LLVM optimization passes being run (default: no) " ) ,
print_mono_items : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
2024-03-13 16:11:48 +01:00
" print the result of the monomorphization collection pass. \
Value ` lazy ` means to use normal collection ; ` eager ` means to collect all items .
Note that this overwrites the effect ` - Clink - dead - code ` has on collection ! " ),
2020-04-21 10:06:13 +10:00
print_type_sizes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" print layout information for each type encountered (default: no) " ) ,
2023-05-17 12:28:04 +00:00
print_vtable_sizes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" print size comparison between old and new vtable layouts (default: no) " ) ,
2020-08-30 22:17:24 -04:00
proc_macro_backtrace : bool = ( false , parse_bool , [ UNTRACKED ] ,
" show backtraces for panics during proc-macro execution (default: no) " ) ,
2022-06-18 14:15:03 -04:00
proc_macro_execution_strategy : ProcMacroExecutionStrategy = ( ProcMacroExecutionStrategy ::SameThread ,
parse_proc_macro_execution_strategy , [ UNTRACKED ] ,
" how to run proc-macro code (default: same-thread) " ) ,
2019-12-17 23:22:55 +11:00
profile : bool = ( false , parse_bool , [ TRACKED ] ,
2020-04-03 10:42:29 +11:00
" insert profiling code (default: no) " ) ,
2021-05-05 15:57:08 -04:00
profile_closures : bool = ( false , parse_no_flag , [ UNTRACKED ] ,
" profile size of closures " ) ,
2020-05-26 13:41:40 -04:00
profile_emit : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" file path to emit profiling data at runtime when using 'profile' \
( default based on relative source path ) " ),
2021-05-07 07:41:37 +00:00
profile_sample_use : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO) " ) ,
2022-10-05 21:46:21 +02:00
profiler_runtime : String = ( String ::from ( " profiler_builtins " ) , parse_string , [ TRACKED ] ,
" name of the profiler runtime crate to automatically inject (default: `profiler_builtins`) " ) ,
2020-04-21 10:06:13 +10:00
query_dep_graph : bool = ( false , parse_bool , [ UNTRACKED ] ,
" enable queries of the dependency graph for regression testing (default: no) " ) ,
2021-08-29 08:55:29 -07:00
randomize_layout : bool = ( false , parse_bool , [ TRACKED ] ,
" randomize the layout of types (default: no) " ) ,
2020-10-26 20:55:07 +01:00
relax_elf_relocations : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" whether ELF relocations can be relaxed " ) ,
2021-07-22 14:52:45 -04:00
remap_cwd_prefix : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" remap paths under the current working directory to this path prefix " ) ,
2023-08-23 11:18:20 +02:00
remap_path_scope : RemapPathScopeComponents = ( RemapPathScopeComponents ::all ( ) , parse_remap_path_scope , [ TRACKED ] ,
" remap path scope (default: all) " ) ,
2023-06-25 23:39:02 +02:00
remark_dir : Option < PathBuf > = ( None , parse_opt_pathbuf , [ UNTRACKED ] ,
" directory into which to write optimization remarks (if not specified, they will be \
written to standard error output ) " ),
2020-06-14 00:00:00 +00:00
sanitizer : SanitizerSet = ( SanitizerSet ::empty ( ) , parse_sanitizers , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" use a sanitizer " ) ,
2022-12-12 22:42:44 -08:00
sanitizer_cfi_canonical_jump_tables : Option < bool > = ( Some ( true ) , parse_opt_bool , [ TRACKED ] ,
" enable canonical jump tables (default: yes) " ) ,
sanitizer_cfi_generalize_pointers : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" enable generalizing pointer types (default: no) " ) ,
sanitizer_cfi_normalize_integers : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" enable normalizing integer types (default: no) " ) ,
2024-02-01 13:16:30 -08:00
sanitizer_dataflow_abilist : Vec < String > = ( Vec ::new ( ) , parse_comma_list , [ TRACKED ] ,
" additional ABI list files that control how shadow parameters are passed (comma separated) " ) ,
2020-04-21 10:06:13 +10:00
sanitizer_memory_track_origins : usize = ( 0 , parse_sanitizer_memory_track_origins , [ TRACKED ] ,
" enable origins tracking in MemorySanitizer " ) ,
2020-06-14 00:00:00 +00:00
sanitizer_recover : SanitizerSet = ( SanitizerSet ::empty ( ) , parse_sanitizers , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" enable recovery for selected sanitizers " ) ,
2020-04-17 21:42:22 -04:00
saturating_float_casts : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" make float->int casts UB-free: numbers outside the integer type's range are clipped to \
2020-04-17 21:42:22 -04:00
the max / min integer respectively , and NaN is mapped to 0 ( default : yes ) " ),
2019-12-17 23:22:55 +11:00
self_profile : SwitchWithOptPath = ( SwitchWithOptPath ::Disabled ,
parse_switch_with_opt_path , [ UNTRACKED ] ,
" run the self profiler and output the raw event data " ) ,
2020-10-22 08:51:31 +03:00
self_profile_counter : String = ( " wall-time " . to_string ( ) , parse_string , [ UNTRACKED ] ,
" counter used by the self profiler (default: `wall-time`), one of:
` wall - time ` ( monotonic clock , i . e . ` std ::time ::Instant ` )
` instructions :u ` ( retired instructions , userspace - only )
` instructions - minus - irqs :u ` ( subtracting hardware interrupt counts for extra accuracy ) "
) ,
2022-10-05 21:46:21 +02:00
/// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
self_profile_events : Option < Vec < String > > = ( None , parse_opt_comma_list , [ UNTRACKED ] ,
" specify the events recorded by the self profiler;
for example : ` - Z self - profile - events = default , query - keys `
all options : none , all , default , generic - activity , query - provider , query - cache - hit
query - blocked , incr - cache - load , incr - result - hashing , query - keys , function - args , args , llvm , artifact - sizes " ),
2020-04-21 10:06:13 +10:00
share_generics : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" make the current crate share its generic instantiations " ) ,
2023-12-06 18:25:13 +00:00
shell_argfiles : bool = ( false , parse_bool , [ UNTRACKED ] ,
" allow argument files to be specified with POSIX \" shell-style \" argument quoting " ) ,
2020-04-21 10:06:13 +10:00
show_span : Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
" show spans for compiler debugging (expr|pat|ty) " ) ,
2022-10-05 21:46:21 +02:00
simulate_remapped_rust_src_base : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
to rust ' s source base directory . only meant for testing purposes " ),
2020-05-31 16:20:50 -04:00
span_debug : bool = ( false , parse_bool , [ UNTRACKED ] ,
" forward proc_macro::Span's `Debug` impl to `Span` " ) ,
2021-04-27 16:44:14 +00:00
/// o/w tests have closure@path
2020-04-21 10:06:13 +10:00
span_free_formats : bool = ( false , parse_bool , [ UNTRACKED ] ,
" exclude spans when debug-printing compiler state (default: no) " ) ,
2023-01-10 22:34:09 -08:00
split_dwarf_inlining : bool = ( false , parse_bool , [ TRACKED ] ,
2022-10-05 21:46:21 +02:00
" provide minimal debug info in the object/executable to facilitate online \
symbolication / stack traces in the absence of . dwo / . dwp files when using Split DWARF " ),
split_dwarf_kind : SplitDwarfKind = ( SplitDwarfKind ::Split , parse_split_dwarf_kind , [ TRACKED ] ,
" split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
( default : ` split ` )
` split ` : sections which do not require relocation are written into a DWARF object ( ` . dwo ` )
file which is ignored by the linker
` single ` : sections which do not require relocation are written into object file but ignored
by the linker " ),
2022-12-12 22:42:44 -08:00
split_lto_unit : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" enable LTO unit splitting (default: no) " ) ,
2020-04-21 10:06:13 +10:00
src_hash_algorithm : Option < SourceFileHashAlgorithm > = ( None , parse_src_file_hash , [ TRACKED ] ,
2020-10-13 08:41:06 -07:00
" hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::stack_protector` instead of this field " ) ]
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
stack_protector : StackProtector = ( StackProtector ::None , parse_stack_protector , [ TRACKED ] ,
" control stack smash protection strategy (`rustc --print stack-protector-strategies` for details) " ) ,
2023-01-04 20:24:03 +00:00
staticlib_allow_rdylib_deps : bool = ( false , parse_bool , [ TRACKED ] ,
" allow staticlibs to have rust dylib dependencies " ) ,
staticlib_prefer_dynamic : bool = ( false , parse_bool , [ TRACKED ] ,
" prefer dynamic linking to static linking for staticlibs (default: no) " ) ,
2022-05-23 16:44:05 +01:00
strict_init_checks : bool = ( false , parse_bool , [ TRACKED ] ,
" control if mem::uninitialized and mem::zeroed panic on more UB " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::teach` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
teach : bool = ( false , parse_bool , [ TRACKED ] ,
" show extended diagnostic help (default: no) " ) ,
2021-11-07 00:14:54 +01:00
temps_dir : Option < String > = ( None , parse_opt_string , [ UNTRACKED ] ,
" the directory the intermediate files are written to " ) ,
2023-02-09 10:16:00 +00:00
terminal_urls : TerminalUrl = ( TerminalUrl ::No , parse_terminal_url , [ UNTRACKED ] ,
" use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::lto` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
thinlto : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" enable ThinLTO when possible " ) ,
2021-04-27 16:44:14 +00:00
/// We default to 1 here since we want to behave like
/// a sequential compiler for now. This'll likely be adjusted
/// in the future. Note that -Zthreads=0 is the way to get
/// the num_cpus behavior.
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::threads` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
threads : usize = ( 1 , parse_threads , [ UNTRACKED ] ,
" use a thread pool with N threads " ) ,
time_llvm_passes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" measure time of each LLVM pass (default: no) " ) ,
time_passes : bool = ( false , parse_bool , [ UNTRACKED ] ,
" measure time of each rustc pass (default: no) " ) ,
2023-02-06 06:32:34 +01:00
time_passes_format : TimePassesFormat = ( TimePassesFormat ::Text , parse_time_passes_format , [ UNTRACKED ] ,
" the format to use for -Z time-passes (`text` (default) or `json`) " ) ,
2022-12-29 23:14:29 +00:00
tiny_const_eval_limit : bool = ( false , parse_bool , [ TRACKED ] ,
" sets a tiny, non-configurable limit for const eval; useful for compiler tests " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::tls_model` instead of this field " ) ]
2020-04-25 21:45:21 +03:00
tls_model : Option < TlsModel > = ( None , parse_tls_model , [ TRACKED ] ,
2020-04-21 10:06:13 +10:00
" choose the TLS model to use (`rustc --print tls-models` for details) " ) ,
trace_macros : bool = ( false , parse_bool , [ UNTRACKED ] ,
" for every macro invocation, print its name and arguments (default: no) " ) ,
2022-10-24 20:52:51 +02:00
track_diagnostics : bool = ( false , parse_bool , [ UNTRACKED ] ,
" tracks where in rustc a diagnostic was emitted " ) ,
2022-10-05 21:46:21 +02:00
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
// alongside query results and changes to translation options can affect diagnostics - so
// translation options should be tracked.
translate_additional_ftl : Option < PathBuf > = ( None , parse_opt_pathbuf , [ TRACKED ] ,
" additional fluent translation to preferentially use (for testing translation) " ) ,
translate_directionality_markers : bool = ( false , parse_bool , [ TRACKED ] ,
" emit directionality isolation markers in translated diagnostics " ) ,
translate_lang : Option < LanguageIdentifier > = ( None , parse_opt_langid , [ TRACKED ] ,
" language identifier for diagnostic output " ) ,
2022-06-06 11:54:01 +02:00
translate_remapped_path_to_local_path : bool = ( true , parse_bool , [ TRACKED ] ,
" translate remapped paths into local paths when possible (default: yes) " ) ,
2020-11-24 00:55:10 +01:00
trap_unreachable : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" generate trap instructions for unreachable intrinsics (default: use target setting, usually yes) " ) ,
2024-01-29 23:59:09 +01:00
treat_err_as_bug : Option < NonZero < usize > > = ( None , parse_treat_err_as_bug , [ TRACKED ] ,
2023-09-22 13:33:55 +02:00
" treat the `val`th error that occurs as bug (default if not specified: 0 - don't treat errors as bugs. \
default if specified without a value : 1 - treat the first error as bug ) " ),
2020-09-02 10:40:56 +03:00
trim_diagnostic_paths : bool = ( true , parse_bool , [ UNTRACKED ] ,
" in diagnostics, use heuristics to shorten paths referring to items " ) ,
2022-10-05 21:46:21 +02:00
tune_cpu : Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
" select processor to schedule for (`rustc --print target-cpus` for details) " ) ,
2024-04-03 08:54:03 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::ub_checks` instead of this field " ) ]
ub_checks : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" emit runtime checks for Undefined Behavior (default: -Cdebug-assertions) " ) ,
2020-04-21 10:06:13 +10:00
ui_testing : bool = ( false , parse_bool , [ UNTRACKED ] ,
" emit compiler diagnostics in a form suitable for UI testing (default: no) " ) ,
2022-02-19 10:35:44 -05:00
uninit_const_chunk_threshold : usize = ( 16 , parse_number , [ TRACKED ] ,
2022-02-19 01:17:31 -05:00
" allow generating const initializers with mixed init/uninit chunks, \
2022-02-19 10:35:44 -05:00
and set the maximum number of chunks for which this is allowed ( default : 16 ) " ),
2020-04-21 10:06:13 +10:00
unleash_the_miri_inside_of_you : bool = ( false , parse_bool , [ TRACKED ] ,
" take the brakes off const evaluation. NOTE: this is unsound (default: no) " ) ,
unpretty : Option < String > = ( None , parse_unpretty , [ UNTRACKED ] ,
" present the input source, unstable (and less-pretty) variants;
2021-03-25 15:48:21 -04:00
` normal ` , ` identified ` ,
2020-04-21 10:06:13 +10:00
` expanded ` , ` expanded , identified ` ,
` expanded , hygiene ` ( with internal representations ) ,
2021-02-19 22:40:28 +01:00
` ast - tree ` ( raw AST before expansion ) ,
` ast - tree , expanded ` ( raw AST after expansion ) ,
2020-04-21 10:06:13 +10:00
` hir ` ( the HIR ) , ` hir , identified ` ,
` hir , typed ` ( HIR with types for each node ) ,
` hir - tree ` ( dump the raw HIR ) ,
2023-10-28 11:34:13 +02:00
` thir - tree ` , ` thir - flat ` ,
2020-04-21 10:06:13 +10:00
` mir ` ( the MIR ) , or ` mir - cfg ` ( graphviz formatted MIR ) " ),
2020-09-18 20:14:27 -04:00
unsound_mir_opts : bool = ( false , parse_bool , [ TRACKED ] ,
" enable unsound and buggy MIR optimizations (default: no) " ) ,
2022-07-06 07:44:47 -05:00
/// This name is kind of confusing: Most unstable options enable something themselves, while
/// this just allows "normal" options to be feature-gated.
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::unstable_options` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
unstable_options : bool = ( false , parse_bool , [ UNTRACKED ] ,
" adds unstable command line options to rustc interface (default: no) " ) ,
2020-04-16 19:40:11 -07:00
use_ctors_section : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" use legacy .ctors section for initializers rather than .init_array " ) ,
2023-11-09 16:46:32 +08:00
use_sync_unwind : Option < bool > = ( None , parse_opt_bool , [ TRACKED ] ,
" Generate sync unwind tables instead of async unwind tables (default: no) " ) ,
2020-05-24 00:55:44 +02:00
validate_mir : bool = ( false , parse_bool , [ UNTRACKED ] ,
" validate MIR after each transformation " ) ,
2023-12-19 12:39:58 -05:00
#[ rustc_lint_opt_deny_field_access( " use `Session::verbose_internals` instead of this field " ) ]
2024-01-19 18:09:54 -05:00
verbose_internals : bool = ( false , parse_bool , [ TRACKED_NO_CRATE_HASH ] ,
2020-04-21 10:06:13 +10:00
" in general, enable more debug printouts (default: no) " ) ,
2022-08-09 09:56:13 -04:00
#[ rustc_lint_opt_deny_field_access( " use `Session::verify_llvm_ir` instead of this field " ) ]
2020-04-21 10:06:13 +10:00
verify_llvm_ir : bool = ( false , parse_bool , [ TRACKED ] ,
" verify LLVM IR (default: no) " ) ,
2022-04-21 13:29:45 +01:00
virtual_function_elimination : bool = ( false , parse_bool , [ TRACKED ] ,
" enables dead virtual function elimination optimization. \
Requires ` - Clto [ = [ fat , yes ] ] ` " ),
2020-12-12 21:38:23 -06:00
wasi_exec_model : Option < WasiExecModel > = ( None , parse_wasi_exec_model , [ TRACKED ] ,
" whether to build a wasi command or reactor " ) ,
2024-02-27 23:06:44 +01:00
wasm_c_abi : WasmCAbi = ( WasmCAbi ::Legacy , parse_wasm_c_abi , [ TRACKED ] ,
" use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy) " ) ,
2023-07-20 16:47:42 +01:00
write_long_types_to_disk : bool = ( true , parse_bool , [ UNTRACKED ] ,
" whether long type names should be written to files instead of being printed in errors " ) ,
2022-10-05 21:46:21 +02:00
// tidy-alphabetical-end
2020-04-21 10:06:13 +10:00
// If you add a new option, please update:
2020-12-12 21:38:23 -06:00
// - compiler/rustc_interface/src/tests.rs
2023-07-21 08:52:12 +10:00
// - src/doc/unstable-book/src/compiler-flags
2020-12-12 21:38:23 -06:00
}