diff options
| author | bors <bors@rust-lang.org> | 2022-03-18 03:01:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-18 03:01:46 +0000 |
| commit | d6f3a4ecb48ead838638e902f2fa4e5f3059779b (patch) | |
| tree | a0ced664fbcf095dac8d3b0a498b9ce8b335cb53 /compiler/rustc_session/src | |
| parent | cd119057160cedea245aa2679add56723f3dc784 (diff) | |
| parent | 0254e318b820d79bb448d4d22d93e345e67b25eb (diff) | |
| download | rust-d6f3a4ecb48ead838638e902f2fa4e5f3059779b.tar.gz rust-d6f3a4ecb48ead838638e902f2fa4e5f3059779b.zip | |
Auto merge of #88098 - Amanieu:oom_panic, r=nagisa
Implement -Z oom=panic This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue #43596). Perf and binary size tests show negligible impact.
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 12 |
2 files changed, 37 insertions, 3 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 1d36ff059de..2357f5ad903 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2842,9 +2842,9 @@ impl PpMode { crate mod dep_tracking { use super::{ BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType, - InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OptLevel, OutputType, - OutputTypes, Passes, SourceFileHashAlgorithm, SwitchWithOptPath, SymbolManglingVersion, - TrimmedDefPaths, + InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel, + OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SwitchWithOptPath, + SymbolManglingVersion, TrimmedDefPaths, }; use crate::lint; use crate::options::WasiExecModel; @@ -2940,6 +2940,7 @@ crate mod dep_tracking { RealFileName, LocationDetail, BranchProtection, + OomStrategy, ); impl<T1, T2> DepTrackingHash for (T1, T2) @@ -3029,3 +3030,24 @@ crate mod dep_tracking { } } } + +/// Default behavior to use in out-of-memory situations. +#[derive(Clone, Copy, PartialEq, Hash, Debug, Encodable, Decodable, HashStable_Generic)] +pub enum OomStrategy { + /// Generate a panic that can be caught by `catch_unwind`. + Panic, + + /// Abort the process immediately. + Abort, +} + +impl OomStrategy { + pub const SYMBOL: &'static str = "__rust_alloc_error_handler_should_panic"; + + pub fn should_panic(self) -> u8 { + match self { + OomStrategy::Panic => 1, + OomStrategy::Abort => 0, + } + } +} diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 14420909f50..0289b962a5a 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -375,6 +375,7 @@ mod desc { pub const parse_passes: &str = "a space-separated list of passes, or `all`"; pub const parse_panic_strategy: &str = "either `unwind` or `abort`"; pub const parse_opt_panic_strategy: &str = parse_panic_strategy; + pub const parse_oom_strategy: &str = "either `panic` or `abort`"; pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`"; pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `hwaddress`, `leak`, `memory`, `memtag`, or `thread`"; pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2"; @@ -620,6 +621,15 @@ mod parse { true } + crate fn parse_oom_strategy(slot: &mut OomStrategy, v: Option<&str>) -> bool { + match v { + Some("panic") => *slot = OomStrategy::Panic, + Some("abort") => *slot = OomStrategy::Abort, + _ => return false, + } + true + } + crate fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool { match v { Some(s) => match s.parse::<RelroLevel>() { @@ -1329,6 +1339,8 @@ options! { "prevent automatic injection of the profiler_builtins crate"), normalize_docs: bool = (false, parse_bool, [TRACKED], "normalize associated items in rustdoc when generating documentation"), + oom: OomStrategy = (OomStrategy::Abort, parse_oom_strategy, [TRACKED], + "panic strategy for out-of-memory handling"), osx_rpath_install_name: bool = (false, parse_bool, [TRACKED], "pass `-install_name @rpath/...` to the macOS linker (default: no)"), panic_abort_tests: bool = (false, parse_bool, [TRACKED], |
