2022-08-09 13:56:13 +00:00
|
|
|
#![allow(rustc::bad_opt_access)]
|
Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main
interner is running. They each use a short-lived interner and convert
all interned symbols to strings in their output data structures. Once
the main interner starts up, these data structures get converted into
new data structures that are identical except with the strings converted
to symbols.
All is not obvious from the current code, which is a mess, particularly
with inconsistent naming that obscures the parallel string/symbol data
structures. This commit clean things up a lot.
- The existing `CheckCfg` type is generic, allowing both
`CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really
useful, but it defaults to `String`. The commit removes the default so
we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly,
which makes things clearer.
- Introduces `Cfg`, which is generic over `String` and `Symbol`, similar
to `CheckCfg`.
- Renames some things.
- `parse_cfgspecs` -> `parse_cfg`
- `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather
than the underlying `FxHashSet` type.
- `CrateConfig` -> `Cfg<Symbol>`.
- `CrateCheckConfig` -> `CheckCfg<Symbol>`
- Adds some comments explaining the string-to-symbol conversions.
- `to_crate_check_config`, which converts `CheckCfg<String>` to
`CheckCfg<Symbol>`, is inlined and removed and combined with the
overly-general `CheckCfg::map_data` to produce
`CheckCfg::<String>::intern`.
- `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>`
conversion, so callers don't need to, which removes the need for
`to_crate_config`.
The diff for two of the fields in `Config` is a good example of the
improved clarity:
```
- pub crate_cfg: FxHashSet<(String, Option<String>)>,
- pub crate_check_cfg: CheckCfg,
+ pub crate_cfg: Cfg<String>,
+ pub crate_check_cfg: CheckCfg<String>,
```
Compare that with the diff for the corresponding fields in `ParseSess`,
and the relationship to `Config` is much clearer than before:
```
- pub config: CrateConfig,
- pub check_config: CrateCheckConfig,
+ pub config: Cfg<Symbol>,
+ pub check_config: CheckCfg<Symbol>,
```
2023-10-27 04:58:02 +00:00
|
|
|
use crate::interface::parse_cfg;
|
2023-02-06 05:32:34 +00:00
|
|
|
use rustc_data_structures::profiling::TimePassesFormat;
|
2019-10-11 21:48:16 +00:00
|
|
|
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
|
2020-06-14 00:00:00 +00:00
|
|
|
use rustc_session::config::{
|
2023-10-30 07:29:23 +00:00
|
|
|
build_configuration, build_session_options, rustc_optgroups, BranchProtection, CFGuard, Cfg,
|
2023-11-07 00:55:05 +00:00
|
|
|
DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry, ExternLocation, Externs,
|
|
|
|
InliningThreshold, Input, InstrumentCoverage, InstrumentXRay, LinkSelfContained,
|
|
|
|
LinkerPluginLto, LocationDetail, LtoCli, MirSpanview, OomStrategy, Options, OutFileName,
|
|
|
|
OutputType, OutputTypes, PAuthKey, PacRet, Passes, Polonius, ProcMacroExecutionStrategy, Strip,
|
|
|
|
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, WasiExecModel,
|
2020-06-14 00:00:00 +00:00
|
|
|
};
|
2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::lint::Level;
|
|
|
|
use rustc_session::search_paths::SearchPath;
|
2021-03-25 04:45:09 +00:00
|
|
|
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
|
2023-10-30 07:29:23 +00:00
|
|
|
use rustc_session::{build_session, getopts, CompilerIO, EarlyErrorHandler, Session};
|
2020-01-01 18:40:49 +00:00
|
|
|
use rustc_span::edition::{Edition, DEFAULT_EDITION};
|
2020-01-01 18:30:57 +00:00
|
|
|
use rustc_span::symbol::sym;
|
2023-10-30 03:05:06 +00:00
|
|
|
use rustc_span::{FileName, SourceFileHashAlgorithm};
|
2022-08-14 21:31:31 +00:00
|
|
|
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel};
|
|
|
|
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
|
2019-06-05 18:16:41 +00:00
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
2021-02-18 11:25:45 +00:00
|
|
|
use std::num::NonZeroUsize;
|
2021-01-26 21:27:42 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2023-10-16 20:11:57 +00:00
|
|
|
use std::sync::Arc;
|
2019-10-11 21:30:58 +00:00
|
|
|
|
2023-10-30 03:05:06 +00:00
|
|
|
fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) {
|
2019-10-10 08:26:10 +00:00
|
|
|
let registry = registry::Registry::new(&[]);
|
2023-10-27 04:40:21 +00:00
|
|
|
let sessopts = build_session_options(handler, &matches);
|
Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main
interner is running. They each use a short-lived interner and convert
all interned symbols to strings in their output data structures. Once
the main interner starts up, these data structures get converted into
new data structures that are identical except with the strings converted
to symbols.
All is not obvious from the current code, which is a mess, particularly
with inconsistent naming that obscures the parallel string/symbol data
structures. This commit clean things up a lot.
- The existing `CheckCfg` type is generic, allowing both
`CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really
useful, but it defaults to `String`. The commit removes the default so
we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly,
which makes things clearer.
- Introduces `Cfg`, which is generic over `String` and `Symbol`, similar
to `CheckCfg`.
- Renames some things.
- `parse_cfgspecs` -> `parse_cfg`
- `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather
than the underlying `FxHashSet` type.
- `CrateConfig` -> `Cfg<Symbol>`.
- `CrateCheckConfig` -> `CheckCfg<Symbol>`
- Adds some comments explaining the string-to-symbol conversions.
- `to_crate_check_config`, which converts `CheckCfg<String>` to
`CheckCfg<Symbol>`, is inlined and removed and combined with the
overly-general `CheckCfg::map_data` to produce
`CheckCfg::<String>::intern`.
- `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>`
conversion, so callers don't need to, which removes the need for
`to_crate_config`.
The diff for two of the fields in `Config` is a good example of the
improved clarity:
```
- pub crate_cfg: FxHashSet<(String, Option<String>)>,
- pub crate_check_cfg: CheckCfg,
+ pub crate_cfg: Cfg<String>,
+ pub crate_check_cfg: CheckCfg<String>,
```
Compare that with the diff for the corresponding fields in `ParseSess`,
and the relationship to `Config` is much clearer than before:
```
- pub config: CrateConfig,
- pub check_config: CrateCheckConfig,
+ pub config: Cfg<Symbol>,
+ pub check_config: CheckCfg<Symbol>,
```
2023-10-27 04:58:02 +00:00
|
|
|
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));
|
2022-12-07 09:24:00 +00:00
|
|
|
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
|
|
|
|
let io = CompilerIO {
|
|
|
|
input: Input::Str { name: FileName::Custom(String::new()), input: String::new() },
|
|
|
|
output_dir: None,
|
|
|
|
output_file: None,
|
|
|
|
temps_dir,
|
|
|
|
};
|
2023-06-22 21:56:09 +00:00
|
|
|
let sess = build_session(
|
|
|
|
handler,
|
|
|
|
sessopts,
|
|
|
|
io,
|
|
|
|
None,
|
|
|
|
registry,
|
|
|
|
vec![],
|
|
|
|
Default::default(),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
"",
|
2023-03-03 22:25:18 +00:00
|
|
|
None,
|
2023-10-16 20:11:57 +00:00
|
|
|
Arc::default(),
|
2023-07-03 11:11:27 +00:00
|
|
|
Default::default(),
|
2023-06-22 21:56:09 +00:00
|
|
|
);
|
2019-10-10 08:26:10 +00:00
|
|
|
(sess, cfg)
|
2019-10-11 21:30:58 +00:00
|
|
|
}
|
2019-06-05 18:16:41 +00:00
|
|
|
|
2019-10-11 21:48:16 +00:00
|
|
|
fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
|
|
|
|
where
|
|
|
|
S: Into<String>,
|
2019-12-05 22:43:53 +00:00
|
|
|
I: IntoIterator<Item = S>,
|
2019-10-11 21:48:16 +00:00
|
|
|
{
|
2021-01-26 21:27:42 +00:00
|
|
|
let locations: BTreeSet<CanonicalizedPath> =
|
|
|
|
locations.into_iter().map(|s| CanonicalizedPath::new(Path::new(&s.into()))).collect();
|
2019-10-11 21:48:16 +00:00
|
|
|
|
|
|
|
ExternEntry {
|
2019-12-05 22:43:53 +00:00
|
|
|
location: ExternLocation::ExactPaths(locations),
|
|
|
|
is_private_dep: false,
|
|
|
|
add_prelude: true,
|
2022-04-14 22:09:00 +00:00
|
|
|
nounused_dep: false,
|
2023-03-14 03:55:43 +00:00
|
|
|
force: false,
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn optgroups() -> getopts::Options {
|
|
|
|
let mut opts = getopts::Options::new();
|
2019-10-11 21:48:16 +00:00
|
|
|
for group in rustc_optgroups() {
|
2019-06-05 18:16:41 +00:00
|
|
|
(group.apply)(&mut opts);
|
|
|
|
}
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
|
|
|
|
BTreeMap::from_iter(entries.into_iter())
|
|
|
|
}
|
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
fn assert_same_clone(x: &Options) {
|
|
|
|
assert_eq!(x.dep_tracking_hash(true), x.clone().dep_tracking_hash(true));
|
|
|
|
assert_eq!(x.dep_tracking_hash(false), x.clone().dep_tracking_hash(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn assert_same_hash(x: &Options, y: &Options) {
|
|
|
|
assert_eq!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
|
|
|
|
assert_eq!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
|
|
|
|
// Check clone
|
|
|
|
assert_same_clone(x);
|
|
|
|
assert_same_clone(y);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn assert_different_hash(x: &Options, y: &Options) {
|
|
|
|
assert_ne!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
|
|
|
|
assert_ne!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
|
|
|
|
// Check clone
|
|
|
|
assert_same_clone(x);
|
|
|
|
assert_same_clone(y);
|
|
|
|
}
|
|
|
|
|
2021-06-10 21:01:21 +00:00
|
|
|
fn assert_non_crate_hash_different(x: &Options, y: &Options) {
|
|
|
|
assert_eq!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
|
|
|
|
assert_ne!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
|
|
|
|
// Check clone
|
|
|
|
assert_same_clone(x);
|
|
|
|
assert_same_clone(y);
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:16:41 +00:00
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test() {
|
2021-05-05 19:31:25 +00:00
|
|
|
rustc_span::create_default_session_globals_then(|| {
|
2019-10-10 08:26:10 +00:00
|
|
|
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
let (sess, cfg) = mk_session(&mut handler, matches);
|
Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main
interner is running. They each use a short-lived interner and convert
all interned symbols to strings in their output data structures. Once
the main interner starts up, these data structures get converted into
new data structures that are identical except with the strings converted
to symbols.
All is not obvious from the current code, which is a mess, particularly
with inconsistent naming that obscures the parallel string/symbol data
structures. This commit clean things up a lot.
- The existing `CheckCfg` type is generic, allowing both
`CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really
useful, but it defaults to `String`. The commit removes the default so
we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly,
which makes things clearer.
- Introduces `Cfg`, which is generic over `String` and `Symbol`, similar
to `CheckCfg`.
- Renames some things.
- `parse_cfgspecs` -> `parse_cfg`
- `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather
than the underlying `FxHashSet` type.
- `CrateConfig` -> `Cfg<Symbol>`.
- `CrateCheckConfig` -> `CheckCfg<Symbol>`
- Adds some comments explaining the string-to-symbol conversions.
- `to_crate_check_config`, which converts `CheckCfg<String>` to
`CheckCfg<Symbol>`, is inlined and removed and combined with the
overly-general `CheckCfg::map_data` to produce
`CheckCfg::<String>::intern`.
- `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>`
conversion, so callers don't need to, which removes the need for
`to_crate_config`.
The diff for two of the fields in `Config` is a good example of the
improved clarity:
```
- pub crate_cfg: FxHashSet<(String, Option<String>)>,
- pub crate_check_cfg: CheckCfg,
+ pub crate_cfg: Cfg<String>,
+ pub crate_check_cfg: CheckCfg<String>,
```
Compare that with the diff for the corresponding fields in `ParseSess`,
and the relationship to `Config` is much clearer than before:
```
- pub config: CrateConfig,
- pub check_config: CrateCheckConfig,
+ pub config: Cfg<Symbol>,
+ pub check_config: CheckCfg<Symbol>,
```
2023-10-27 04:58:02 +00:00
|
|
|
let cfg = build_configuration(&sess, cfg);
|
2019-06-05 18:16:41 +00:00
|
|
|
assert!(cfg.contains(&(sym::test, None)));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-10 08:26:10 +00:00
|
|
|
// When the user supplies --test and --cfg test, don't implicitly add another --cfg test
|
2019-06-05 18:16:41 +00:00
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
2021-05-05 19:31:25 +00:00
|
|
|
rustc_span::create_default_session_globals_then(|| {
|
2019-10-10 08:26:10 +00:00
|
|
|
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
let (sess, cfg) = mk_session(&mut handler, matches);
|
Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main
interner is running. They each use a short-lived interner and convert
all interned symbols to strings in their output data structures. Once
the main interner starts up, these data structures get converted into
new data structures that are identical except with the strings converted
to symbols.
All is not obvious from the current code, which is a mess, particularly
with inconsistent naming that obscures the parallel string/symbol data
structures. This commit clean things up a lot.
- The existing `CheckCfg` type is generic, allowing both
`CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really
useful, but it defaults to `String`. The commit removes the default so
we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly,
which makes things clearer.
- Introduces `Cfg`, which is generic over `String` and `Symbol`, similar
to `CheckCfg`.
- Renames some things.
- `parse_cfgspecs` -> `parse_cfg`
- `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather
than the underlying `FxHashSet` type.
- `CrateConfig` -> `Cfg<Symbol>`.
- `CrateCheckConfig` -> `CheckCfg<Symbol>`
- Adds some comments explaining the string-to-symbol conversions.
- `to_crate_check_config`, which converts `CheckCfg<String>` to
`CheckCfg<Symbol>`, is inlined and removed and combined with the
overly-general `CheckCfg::map_data` to produce
`CheckCfg::<String>::intern`.
- `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>`
conversion, so callers don't need to, which removes the need for
`to_crate_config`.
The diff for two of the fields in `Config` is a good example of the
improved clarity:
```
- pub crate_cfg: FxHashSet<(String, Option<String>)>,
- pub crate_check_cfg: CheckCfg,
+ pub crate_cfg: Cfg<String>,
+ pub crate_check_cfg: CheckCfg<String>,
```
Compare that with the diff for the corresponding fields in `ParseSess`,
and the relationship to `Config` is much clearer than before:
```
- pub config: CrateConfig,
- pub check_config: CrateCheckConfig,
+ pub config: Cfg<Symbol>,
+ pub check_config: CheckCfg<Symbol>,
```
2023-10-27 04:58:02 +00:00
|
|
|
let cfg = build_configuration(&sess, cfg);
|
2019-06-05 18:16:41 +00:00
|
|
|
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
|
|
|
|
assert!(test_items.next().is_some());
|
|
|
|
assert!(test_items.next().is_none());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_print_warnings() {
|
2021-05-05 19:31:25 +00:00
|
|
|
rustc_span::create_default_session_globals_then(|| {
|
2019-06-05 18:16:41 +00:00
|
|
|
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
let (sess, _) = mk_session(&mut handler, matches);
|
2019-09-07 16:09:52 +00:00
|
|
|
assert!(!sess.diagnostic().can_emit_warnings());
|
2019-06-05 18:16:41 +00:00
|
|
|
});
|
|
|
|
|
2021-05-05 19:31:25 +00:00
|
|
|
rustc_span::create_default_session_globals_then(|| {
|
2019-06-05 18:16:41 +00:00
|
|
|
let matches =
|
|
|
|
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
let (sess, _) = mk_session(&mut handler, matches);
|
2019-09-07 16:09:52 +00:00
|
|
|
assert!(sess.diagnostic().can_emit_warnings());
|
2019-06-05 18:16:41 +00:00
|
|
|
});
|
|
|
|
|
2021-05-05 19:31:25 +00:00
|
|
|
rustc_span::create_default_session_globals_then(|| {
|
2019-06-05 18:16:41 +00:00
|
|
|
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
let (sess, _) = mk_session(&mut handler, matches);
|
2019-09-07 16:09:52 +00:00
|
|
|
assert!(sess.diagnostic().can_emit_warnings());
|
2019-06-05 18:16:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_output_types_tracking_hash_different_paths() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
|
2023-02-26 20:27:27 +00:00
|
|
|
v1.output_types = OutputTypes::new(&[(
|
|
|
|
OutputType::Exe,
|
|
|
|
Some(OutFileName::Real(PathBuf::from("./some/thing"))),
|
|
|
|
)]);
|
|
|
|
v2.output_types = OutputTypes::new(&[(
|
|
|
|
OutputType::Exe,
|
|
|
|
Some(OutFileName::Real(PathBuf::from("/some/thing"))),
|
|
|
|
)]);
|
2019-06-05 18:16:41 +00:00
|
|
|
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
|
|
|
|
2021-06-20 00:22:14 +00:00
|
|
|
assert_non_crate_hash_different(&v1, &v2);
|
|
|
|
assert_non_crate_hash_different(&v1, &v3);
|
|
|
|
assert_non_crate_hash_different(&v2, &v3);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_output_types_tracking_hash_different_construction_order() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
|
|
|
|
v1.output_types = OutputTypes::new(&[
|
2023-02-26 20:27:27 +00:00
|
|
|
(OutputType::Exe, Some(OutFileName::Real(PathBuf::from("./some/thing")))),
|
|
|
|
(OutputType::Bitcode, Some(OutFileName::Real(PathBuf::from("./some/thing.bc")))),
|
2019-06-05 18:16:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
v2.output_types = OutputTypes::new(&[
|
2023-02-26 20:27:27 +00:00
|
|
|
(OutputType::Bitcode, Some(OutFileName::Real(PathBuf::from("./some/thing.bc")))),
|
|
|
|
(OutputType::Exe, Some(OutFileName::Real(PathBuf::from("./some/thing")))),
|
2019-06-05 18:16:41 +00:00
|
|
|
]);
|
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_same_hash(&v1, &v2);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_externs_tracking_hash_different_construction_order() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
|
|
|
|
v1.externs = Externs::new(mk_map(vec![
|
2019-12-05 22:43:53 +00:00
|
|
|
(String::from("a"), new_public_extern_entry(vec!["b", "c"])),
|
|
|
|
(String::from("d"), new_public_extern_entry(vec!["e", "f"])),
|
2019-06-05 18:16:41 +00:00
|
|
|
]));
|
|
|
|
|
|
|
|
v2.externs = Externs::new(mk_map(vec![
|
2019-12-05 22:43:53 +00:00
|
|
|
(String::from("d"), new_public_extern_entry(vec!["e", "f"])),
|
|
|
|
(String::from("a"), new_public_extern_entry(vec!["b", "c"])),
|
2019-06-05 18:16:41 +00:00
|
|
|
]));
|
|
|
|
|
|
|
|
v3.externs = Externs::new(mk_map(vec![
|
2019-12-05 22:43:53 +00:00
|
|
|
(String::from("a"), new_public_extern_entry(vec!["b", "c"])),
|
|
|
|
(String::from("d"), new_public_extern_entry(vec!["f", "e"])),
|
2019-06-05 18:16:41 +00:00
|
|
|
]));
|
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_same_hash(&v1, &v2);
|
|
|
|
assert_same_hash(&v1, &v3);
|
|
|
|
assert_same_hash(&v2, &v3);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lints_tracking_hash_different_values() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
|
|
|
|
v1.lint_opts = vec![
|
2020-01-10 05:53:07 +00:00
|
|
|
(String::from("a"), Level::Allow),
|
|
|
|
(String::from("b"), Level::Warn),
|
|
|
|
(String::from("c"), Level::Deny),
|
|
|
|
(String::from("d"), Level::Forbid),
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
v2.lint_opts = vec![
|
2020-01-10 05:53:07 +00:00
|
|
|
(String::from("a"), Level::Allow),
|
|
|
|
(String::from("b"), Level::Warn),
|
|
|
|
(String::from("X"), Level::Deny),
|
|
|
|
(String::from("d"), Level::Forbid),
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
v3.lint_opts = vec![
|
2020-01-10 05:53:07 +00:00
|
|
|
(String::from("a"), Level::Allow),
|
|
|
|
(String::from("b"), Level::Warn),
|
|
|
|
(String::from("c"), Level::Forbid),
|
|
|
|
(String::from("d"), Level::Deny),
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
2021-07-14 23:39:17 +00:00
|
|
|
assert_non_crate_hash_different(&v1, &v2);
|
|
|
|
assert_non_crate_hash_different(&v1, &v3);
|
|
|
|
assert_non_crate_hash_different(&v2, &v3);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lints_tracking_hash_different_construction_order() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
|
|
|
|
v1.lint_opts = vec![
|
2020-01-10 05:53:07 +00:00
|
|
|
(String::from("a"), Level::Allow),
|
|
|
|
(String::from("b"), Level::Warn),
|
|
|
|
(String::from("c"), Level::Deny),
|
|
|
|
(String::from("d"), Level::Forbid),
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
v2.lint_opts = vec![
|
2020-01-10 05:53:07 +00:00
|
|
|
(String::from("a"), Level::Allow),
|
|
|
|
(String::from("c"), Level::Deny),
|
|
|
|
(String::from("b"), Level::Warn),
|
|
|
|
(String::from("d"), Level::Forbid),
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
2021-05-26 00:43:02 +00:00
|
|
|
// The hash should be order-dependent
|
2021-07-14 23:39:17 +00:00
|
|
|
assert_non_crate_hash_different(&v1, &v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lint_cap_hash_different() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let v3 = Options::default();
|
|
|
|
|
|
|
|
v1.lint_cap = Some(Level::Forbid);
|
|
|
|
v2.lint_cap = Some(Level::Allow);
|
|
|
|
|
|
|
|
assert_non_crate_hash_different(&v1, &v2);
|
|
|
|
assert_non_crate_hash_different(&v1, &v3);
|
|
|
|
assert_non_crate_hash_different(&v2, &v3);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_search_paths_tracking_hash_different_order() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
let mut v4 = Options::default();
|
|
|
|
|
2023-06-22 21:56:09 +00:00
|
|
|
let handler = EarlyErrorHandler::new(JSON);
|
2019-10-11 21:48:16 +00:00
|
|
|
const JSON: ErrorOutputType = ErrorOutputType::Json {
|
2019-06-05 18:16:41 +00:00
|
|
|
pretty: false,
|
2019-10-11 21:48:16 +00:00
|
|
|
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
|
2019-06-05 18:16:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Reference
|
2023-06-22 21:56:09 +00:00
|
|
|
v1.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
|
|
|
|
v1.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
|
|
|
|
v1.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
|
|
|
|
v1.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
|
|
|
|
v1.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
|
|
|
|
|
|
|
|
v2.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
|
|
|
|
v2.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
|
|
|
|
v2.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
|
|
|
|
v2.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
|
|
|
|
v2.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
|
|
|
|
|
|
|
|
v3.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
|
|
|
|
v3.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
|
|
|
|
v3.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
|
|
|
|
v3.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
|
|
|
|
v3.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
|
|
|
|
|
|
|
|
v4.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
|
|
|
|
v4.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
|
|
|
|
v4.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
|
|
|
|
v4.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
|
|
|
|
v4.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
|
2019-06-05 18:16:41 +00:00
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_same_hash(&v1, &v2);
|
|
|
|
assert_same_hash(&v1, &v3);
|
|
|
|
assert_same_hash(&v1, &v4);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_native_libs_tracking_hash_different_values() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
let mut v4 = Options::default();
|
2021-03-25 04:45:09 +00:00
|
|
|
let mut v5 = Options::default();
|
2019-06-05 18:16:41 +00:00
|
|
|
|
|
|
|
// Reference
|
|
|
|
v1.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Change label
|
|
|
|
v2.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("X"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Change kind
|
|
|
|
v3.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Change new-name
|
|
|
|
v4.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: Some(String::from("X")),
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
// Change verbatim
|
|
|
|
v5.libs = vec![
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: Some(true),
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_different_hash(&v1, &v2);
|
|
|
|
assert_different_hash(&v1, &v3);
|
|
|
|
assert_different_hash(&v1, &v4);
|
2021-03-25 04:45:09 +00:00
|
|
|
assert_different_hash(&v1, &v5);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_native_libs_tracking_hash_different_order() {
|
|
|
|
let mut v1 = Options::default();
|
|
|
|
let mut v2 = Options::default();
|
|
|
|
let mut v3 = Options::default();
|
|
|
|
|
|
|
|
// Reference
|
|
|
|
v1.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
v2.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
v3.libs = vec![
|
2021-03-25 04:45:09 +00:00
|
|
|
NativeLib {
|
|
|
|
name: String::from("c"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Unspecified,
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("a"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Static { bundle: None, whole_archive: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
|
|
|
NativeLib {
|
|
|
|
name: String::from("b"),
|
|
|
|
new_name: None,
|
|
|
|
kind: NativeLibKind::Framework { as_needed: None },
|
|
|
|
verbatim: None,
|
|
|
|
},
|
2019-06-05 18:16:41 +00:00
|
|
|
];
|
|
|
|
|
2021-05-26 00:43:02 +00:00
|
|
|
// The hash should be order-dependent
|
|
|
|
assert_different_hash(&v1, &v2);
|
|
|
|
assert_different_hash(&v1, &v3);
|
|
|
|
assert_different_hash(&v2, &v3);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_codegen_options_tracking_hash() {
|
|
|
|
let reference = Options::default();
|
|
|
|
let mut opts = Options::default();
|
|
|
|
|
2020-04-21 05:55:02 +00:00
|
|
|
macro_rules! untracked {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
2021-04-16 03:06:32 +00:00
|
|
|
assert_ne!(opts.cg.$name, $non_default_value);
|
2020-04-21 05:55:02 +00:00
|
|
|
opts.cg.$name = $non_default_value;
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_same_hash(&reference, &opts);
|
2020-04-21 05:55:02 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:06:13 +00:00
|
|
|
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-start
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(ar, String::from("abc"));
|
|
|
|
untracked!(codegen_units, Some(42));
|
|
|
|
untracked!(default_linker_libraries, true);
|
2023-03-27 17:42:22 +00:00
|
|
|
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(extra_filename, String::from("extra-filename"));
|
|
|
|
untracked!(incremental, Some(String::from("abc")));
|
2020-04-21 03:25:07 +00:00
|
|
|
// `link_arg` is omitted because it just forwards to `link_args`.
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
|
2023-06-21 21:46:36 +00:00
|
|
|
untracked!(link_self_contained, LinkSelfContained::on());
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(linker, Some(PathBuf::from("linker")));
|
2022-08-14 21:31:31 +00:00
|
|
|
untracked!(linker_flavor, Some(LinkerFlavorCli::Gcc));
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(no_stack_check, true);
|
|
|
|
untracked!(remark, Passes::Some(vec![String::from("pass1"), String::from("pass2")]));
|
|
|
|
untracked!(rpath, true);
|
|
|
|
untracked!(save_temps, true);
|
2021-10-21 11:19:46 +00:00
|
|
|
untracked!(strip, Strip::Debuginfo);
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-end
|
2020-04-21 05:55:02 +00:00
|
|
|
|
|
|
|
macro_rules! tracked {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
|
|
|
opts = reference.clone();
|
2021-04-16 03:06:32 +00:00
|
|
|
assert_ne!(opts.cg.$name, $non_default_value);
|
2020-04-21 05:55:02 +00:00
|
|
|
opts.cg.$name = $non_default_value;
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_different_hash(&reference, &opts);
|
2020-04-21 05:55:02 +00:00
|
|
|
};
|
|
|
|
}
|
2019-06-05 18:16:41 +00:00
|
|
|
|
2020-04-21 00:06:13 +00:00
|
|
|
// Make sure that changing a [TRACKED] option changes the hash.
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-start
|
2020-05-07 00:34:27 +00:00
|
|
|
tracked!(code_model, Some(CodeModel::Large));
|
2020-07-14 14:27:42 +00:00
|
|
|
tracked!(control_flow_guard, CFGuard::Checks);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(debug_assertions, Some(true));
|
2021-04-06 20:00:35 +00:00
|
|
|
tracked!(debuginfo, DebugInfo::Limited);
|
2020-04-30 17:53:16 +00:00
|
|
|
tracked!(embed_bitcode, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(force_frame_pointers, Some(false));
|
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 11:08:35 +00:00
|
|
|
tracked!(force_unwind_tables, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(inline_threshold, Some(0xf007ba11));
|
2023-10-25 03:36:13 +00:00
|
|
|
tracked!(instrument_coverage, InstrumentCoverage::All);
|
2021-04-15 19:05:26 +00:00
|
|
|
tracked!(link_dead_code, Some(true));
|
2022-10-05 19:46:21 +00:00
|
|
|
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
|
|
|
|
tracked!(lto, LtoCli::Fat);
|
|
|
|
tracked!(metadata, vec![String::from("A"), String::from("B")]);
|
|
|
|
tracked!(no_prepopulate_passes, true);
|
|
|
|
tracked!(no_redzone, Some(true));
|
|
|
|
tracked!(no_vectorize_loops, true);
|
|
|
|
tracked!(no_vectorize_slp, true);
|
|
|
|
tracked!(opt_level, "3".to_string());
|
|
|
|
tracked!(overflow_checks, Some(true));
|
|
|
|
tracked!(panic, Some(PanicStrategy::Abort));
|
|
|
|
tracked!(passes, vec![String::from("1"), String::from("2")]);
|
|
|
|
tracked!(prefer_dynamic, true);
|
|
|
|
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
|
|
|
|
tracked!(profile_use, Some(PathBuf::from("abc")));
|
2020-04-22 21:46:45 +00:00
|
|
|
tracked!(relocation_model, Some(RelocModel::Pic));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(soft_float, true);
|
2020-11-30 16:39:08 +00:00
|
|
|
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
|
2021-10-21 12:02:59 +00:00
|
|
|
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(target_cpu, Some(String::from("abc")));
|
|
|
|
tracked!(target_feature, String::from("all the features, all of them"));
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-end
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 23:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_top_level_options_tracked_no_crate() {
|
|
|
|
let reference = Options::default();
|
|
|
|
let mut opts;
|
|
|
|
|
|
|
|
macro_rules! tracked {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
|
|
|
opts = reference.clone();
|
|
|
|
assert_ne!(opts.$name, $non_default_value);
|
|
|
|
opts.$name = $non_default_value;
|
|
|
|
// The crate hash should be the same
|
|
|
|
assert_eq!(reference.dep_tracking_hash(true), opts.dep_tracking_hash(true));
|
|
|
|
// The incremental hash should be different
|
|
|
|
assert_ne!(reference.dep_tracking_hash(false), opts.dep_tracking_hash(false));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-start
|
2021-04-27 16:25:12 +00:00
|
|
|
tracked!(
|
|
|
|
real_rust_source_base_dir,
|
|
|
|
Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
|
|
|
|
);
|
2022-10-05 19:46:21 +00:00
|
|
|
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
|
|
|
|
// tidy-alphabetical-end
|
2021-04-15 23:25:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:16:41 +00:00
|
|
|
#[test]
|
2022-07-06 12:44:47 +00:00
|
|
|
fn test_unstable_options_tracking_hash() {
|
2019-06-05 18:16:41 +00:00
|
|
|
let reference = Options::default();
|
|
|
|
let mut opts = Options::default();
|
|
|
|
|
2020-04-21 05:55:02 +00:00
|
|
|
macro_rules! untracked {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
2022-07-06 12:44:47 +00:00
|
|
|
assert_ne!(opts.unstable_opts.$name, $non_default_value);
|
|
|
|
opts.unstable_opts.$name = $non_default_value;
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_same_hash(&reference, &opts);
|
2020-04-21 05:55:02 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:06:13 +00:00
|
|
|
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-start
|
2021-10-31 22:05:48 +00:00
|
|
|
untracked!(assert_incr_state, Some(String::from("loaded")));
|
2021-04-16 03:06:32 +00:00
|
|
|
untracked!(deduplicate_diagnostics, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(dont_buffer_diagnostics, true);
|
|
|
|
untracked!(dump_dep_graph, true);
|
|
|
|
untracked!(dump_mir, Some(String::from("abc")));
|
|
|
|
untracked!(dump_mir_dataflow, true);
|
|
|
|
untracked!(dump_mir_dir, String::from("abc"));
|
|
|
|
untracked!(dump_mir_exclude_pass_number, true);
|
|
|
|
untracked!(dump_mir_graphviz, true);
|
2022-12-29 21:08:09 +00:00
|
|
|
untracked!(dump_mir_spanview, Some(MirSpanview::Statement));
|
|
|
|
untracked!(dump_mono_stats, SwitchWithOptPath::Enabled(Some("mono-items-dir/".into())));
|
|
|
|
untracked!(dump_mono_stats_format, DumpMonoStatsFormat::Json);
|
2022-09-29 14:31:03 +00:00
|
|
|
untracked!(dylib_lto, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(emit_stack_sizes, true);
|
2021-06-20 00:06:46 +00:00
|
|
|
untracked!(future_incompat_test, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(hir_stats, true);
|
|
|
|
untracked!(identify_regions, true);
|
|
|
|
untracked!(incremental_info, true);
|
|
|
|
untracked!(incremental_verify_ich, true);
|
|
|
|
untracked!(input_stats, true);
|
|
|
|
untracked!(keep_hygiene_data, true);
|
|
|
|
untracked!(link_native_libraries, false);
|
|
|
|
untracked!(llvm_time_trace, true);
|
2023-09-10 14:43:11 +00:00
|
|
|
untracked!(ls, vec!["all".to_owned()]);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(macro_backtrace, true);
|
|
|
|
untracked!(meta_stats, true);
|
2023-06-06 13:47:00 +00:00
|
|
|
untracked!(mir_include_spans, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(nll_facts, true);
|
|
|
|
untracked!(no_analysis, true);
|
|
|
|
untracked!(no_leak_check, true);
|
|
|
|
untracked!(no_parallel_llvm, true);
|
|
|
|
untracked!(parse_only, true);
|
|
|
|
untracked!(perf_stats, true);
|
2020-04-21 03:25:07 +00:00
|
|
|
// `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
|
2023-07-16 15:37:52 +00:00
|
|
|
untracked!(print_codegen_stats, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(print_llvm_passes, true);
|
|
|
|
untracked!(print_mono_items, Some(String::from("abc")));
|
|
|
|
untracked!(print_type_sizes, true);
|
2020-08-31 02:17:24 +00:00
|
|
|
untracked!(proc_macro_backtrace, true);
|
2022-06-18 18:15:03 +00:00
|
|
|
untracked!(proc_macro_execution_strategy, ProcMacroExecutionStrategy::CrossThread);
|
2022-10-05 19:46:21 +00:00
|
|
|
untracked!(profile_closures, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(query_dep_graph, true);
|
|
|
|
untracked!(self_profile, SwitchWithOptPath::Enabled(None));
|
|
|
|
untracked!(self_profile_events, Some(vec![String::new()]));
|
2020-05-31 20:20:50 +00:00
|
|
|
untracked!(span_debug, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(span_free_formats, true);
|
2021-11-06 23:14:54 +00:00
|
|
|
untracked!(temps_dir, Some(String::from("abc")));
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(threads, 99);
|
|
|
|
untracked!(time_llvm_passes, true);
|
|
|
|
untracked!(time_passes, true);
|
2023-02-06 05:32:34 +00:00
|
|
|
untracked!(time_passes_format, TimePassesFormat::Json);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(trace_macros, true);
|
2022-10-26 11:42:41 +00:00
|
|
|
untracked!(track_diagnostics, true);
|
2020-09-02 07:40:56 +00:00
|
|
|
untracked!(trim_diagnostic_paths, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(ui_testing, true);
|
|
|
|
untracked!(unpretty, Some("expanded".to_string()));
|
|
|
|
untracked!(unstable_options, true);
|
2020-05-23 22:55:44 +00:00
|
|
|
untracked!(validate_mir, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
untracked!(verbose, true);
|
2023-07-25 11:08:44 +00:00
|
|
|
untracked!(write_long_types_to_disk, false);
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-end
|
2020-04-21 05:55:02 +00:00
|
|
|
|
|
|
|
macro_rules! tracked {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
|
|
|
opts = reference.clone();
|
2022-07-06 12:44:47 +00:00
|
|
|
assert_ne!(opts.unstable_opts.$name, $non_default_value);
|
|
|
|
opts.unstable_opts.$name = $non_default_value;
|
2021-04-15 23:25:01 +00:00
|
|
|
assert_different_hash(&reference, &opts);
|
2020-04-21 05:55:02 +00:00
|
|
|
};
|
|
|
|
}
|
2019-06-05 18:16:41 +00:00
|
|
|
|
2020-04-21 00:06:13 +00:00
|
|
|
// Make sure that changing a [TRACKED] option changes the hash.
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-start
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(allow_features, Some(vec![String::from("lang_items")]));
|
|
|
|
tracked!(always_encode_mir, true);
|
|
|
|
tracked!(asm_comments, true);
|
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 19:37:49 +00:00
|
|
|
tracked!(assume_incomplete_release, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(binary_dep_depinfo, true);
|
2023-01-06 00:00:00 +00:00
|
|
|
tracked!(box_noalias, false);
|
2021-12-01 15:56:59 +00:00
|
|
|
tracked!(
|
|
|
|
branch_protection,
|
2022-01-31 19:47:07 +00:00
|
|
|
Some(BranchProtection {
|
|
|
|
bti: true,
|
|
|
|
pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
|
|
|
|
})
|
2021-12-01 15:56:59 +00:00
|
|
|
);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(codegen_backend, Some("abc".to_string()));
|
|
|
|
tracked!(crate_attr, vec!["abc".to_string()]);
|
2023-11-07 00:55:05 +00:00
|
|
|
tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
|
2021-05-07 07:41:37 +00:00
|
|
|
tracked!(debug_info_for_profiling, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(debug_macros, true);
|
|
|
|
tracked!(dep_info_omit_d_target, true);
|
|
|
|
tracked!(dual_proc_macros, true);
|
2022-06-20 23:26:51 +00:00
|
|
|
tracked!(dwarf_version, Some(5));
|
2022-06-08 14:30:16 +00:00
|
|
|
tracked!(emit_thin_lto, false);
|
2022-10-05 19:46:21 +00:00
|
|
|
tracked!(export_executable_symbols, true);
|
2020-11-23 00:00:00 +00:00
|
|
|
tracked!(fewer_names, Some(true));
|
2023-04-17 12:13:37 +00:00
|
|
|
tracked!(flatten_format_args, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(force_unstable_if_unmarked, true);
|
|
|
|
tracked!(fuel, Some(("abc".to_string(), 99)));
|
2020-10-26 19:55:07 +00:00
|
|
|
tracked!(function_sections, Some(false));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(human_readable_cgu_names, true);
|
2022-10-31 16:39:45 +00:00
|
|
|
tracked!(incremental_ignore_spans, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(inline_in_all_cgus, Some(true));
|
2021-02-21 00:00:00 +00:00
|
|
|
tracked!(inline_mir, Some(true));
|
2021-02-21 00:00:00 +00:00
|
|
|
tracked!(inline_mir_hint_threshold, Some(123));
|
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 19:37:49 +00:00
|
|
|
tracked!(inline_mir_threshold, Some(123));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(instrument_mcount, true);
|
2022-09-24 11:02:44 +00:00
|
|
|
tracked!(instrument_xray, Some(InstrumentXRay::default()));
|
2023-02-04 23:07:41 +00:00
|
|
|
tracked!(link_directives, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(link_only, true);
|
2021-06-13 16:23:01 +00:00
|
|
|
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
|
2021-10-15 15:58:28 +00:00
|
|
|
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
|
2022-12-05 05:07:55 +00:00
|
|
|
tracked!(maximal_hir_to_mir_coverage, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(merge_functions, Some(MergeFunctions::Disabled));
|
|
|
|
tracked!(mir_emit_retag, true);
|
2022-04-11 19:17:52 +00:00
|
|
|
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
|
2023-03-18 16:11:48 +00:00
|
|
|
tracked!(mir_keep_place_mention, true);
|
2021-03-04 14:13:39 +00:00
|
|
|
tracked!(mir_opt_level, Some(4));
|
2021-06-19 00:00:00 +00:00
|
|
|
tracked!(move_size_limit, Some(4096));
|
2023-01-06 00:00:00 +00:00
|
|
|
tracked!(mutable_noalias, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(no_generate_arange_section, true);
|
2022-12-17 01:50:08 +00:00
|
|
|
tracked!(no_jump_tables, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(no_link, true);
|
2021-08-04 09:43:44 +00:00
|
|
|
tracked!(no_profiler_runtime, true);
|
2023-08-17 11:07:22 +00:00
|
|
|
tracked!(no_trait_vptr, true);
|
2022-10-05 19:46:21 +00:00
|
|
|
tracked!(no_unique_section_names, true);
|
2023-04-24 22:08:33 +00:00
|
|
|
tracked!(oom, OomStrategy::Panic);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(osx_rpath_install_name, true);
|
2022-08-24 10:10:40 +00:00
|
|
|
tracked!(packed_bundled_libs, true);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(panic_abort_tests, true);
|
2021-09-06 10:21:47 +00:00
|
|
|
tracked!(panic_in_drop, PanicStrategy::Abort);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(plt, Some(true));
|
2023-06-30 11:55:38 +00:00
|
|
|
tracked!(polonius, Polonius::Legacy);
|
2020-10-01 18:31:43 +00:00
|
|
|
tracked!(precise_enum_drop_elaboration, false);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(print_fuel, Some("abc".to_string()));
|
|
|
|
tracked!(profile, true);
|
2020-05-26 17:41:40 +00:00
|
|
|
tracked!(profile_emit, Some(PathBuf::from("abc")));
|
2021-05-07 07:41:37 +00:00
|
|
|
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
|
2022-10-05 19:46:21 +00:00
|
|
|
tracked!(profiler_runtime, "abc".to_string());
|
2023-08-27 09:22:20 +00:00
|
|
|
tracked!(relax_elf_relocations, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(relro_level, Some(RelroLevel::Full));
|
2021-07-22 18:52:45 +00:00
|
|
|
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(report_delayed_bugs, true);
|
2020-06-14 00:00:00 +00:00
|
|
|
tracked!(sanitizer, SanitizerSet::ADDRESS);
|
2022-12-13 06:42:44 +00:00
|
|
|
tracked!(sanitizer_cfi_canonical_jump_tables, None);
|
|
|
|
tracked!(sanitizer_cfi_generalize_pointers, Some(true));
|
|
|
|
tracked!(sanitizer_cfi_normalize_integers, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(sanitizer_memory_track_origins, 2);
|
2020-06-14 00:00:00 +00:00
|
|
|
tracked!(sanitizer_recover, SanitizerSet::ADDRESS);
|
2020-04-18 01:42:22 +00:00
|
|
|
tracked!(saturating_float_casts, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(share_generics, Some(true));
|
|
|
|
tracked!(show_span, Some(String::from("abc")));
|
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 19:37:49 +00:00
|
|
|
tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));
|
2022-12-13 06:42:44 +00:00
|
|
|
tracked!(split_lto_unit, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1));
|
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 19:37:49 +00:00
|
|
|
tracked!(stack_protector, StackProtector::All);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(teach, true);
|
|
|
|
tracked!(thinlto, Some(true));
|
2021-03-14 19:10:22 +00:00
|
|
|
tracked!(thir_unsafeck, true);
|
2022-12-29 23:14:29 +00:00
|
|
|
tracked!(tiny_const_eval_limit, true);
|
2020-04-25 18:45:21 +00:00
|
|
|
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
|
2023-07-03 15:19:08 +00:00
|
|
|
tracked!(trait_solver, TraitSolver::NextCoherence);
|
2022-06-06 09:54:01 +00:00
|
|
|
tracked!(translate_remapped_path_to_local_path, false);
|
2020-11-23 23:55:10 +00:00
|
|
|
tracked!(trap_unreachable, Some(false));
|
2021-02-18 11:25:45 +00:00
|
|
|
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
|
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 19:37:49 +00:00
|
|
|
tracked!(tune_cpu, Some(String::from("abc")));
|
2022-02-19 06:17:31 +00:00
|
|
|
tracked!(uninit_const_chunk_threshold, 123);
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(unleash_the_miri_inside_of_you, true);
|
2020-04-17 02:40:11 +00:00
|
|
|
tracked!(use_ctors_section, Some(true));
|
2020-04-21 05:55:02 +00:00
|
|
|
tracked!(verify_llvm_ir, true);
|
2022-04-21 12:29:45 +00:00
|
|
|
tracked!(virtual_function_elimination, true);
|
2020-12-13 03:38:23 +00:00
|
|
|
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
|
2022-10-05 19:46:21 +00:00
|
|
|
// tidy-alphabetical-end
|
2021-06-09 23:51:58 +00:00
|
|
|
|
|
|
|
macro_rules! tracked_no_crate_hash {
|
|
|
|
($name: ident, $non_default_value: expr) => {
|
|
|
|
opts = reference.clone();
|
2022-07-06 12:44:47 +00:00
|
|
|
assert_ne!(opts.unstable_opts.$name, $non_default_value);
|
|
|
|
opts.unstable_opts.$name = $non_default_value;
|
2021-06-09 23:51:58 +00:00
|
|
|
assert_non_crate_hash_different(&reference, &opts);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
tracked_no_crate_hash!(no_codegen, true);
|
2019-06-05 18:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_edition_parsing() {
|
|
|
|
// test default edition
|
|
|
|
let options = Options::default();
|
|
|
|
assert!(options.edition == DEFAULT_EDITION);
|
|
|
|
|
2023-06-22 21:56:09 +00:00
|
|
|
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
|
|
|
|
2019-06-05 18:16:41 +00:00
|
|
|
let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
|
2023-10-27 04:40:21 +00:00
|
|
|
let sessopts = build_session_options(&mut handler, &matches);
|
2019-06-05 18:16:41 +00:00
|
|
|
assert!(sessopts.edition == Edition::Edition2018)
|
|
|
|
}
|