diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index 39bbad16b0c00..ab65eb6b6b9cb 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -45,6 +45,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::config::OutputFilenames; use rustc_session::Session; use rustc_span::{sym, Symbol}; +use rustc_target::spec::FramePointer; pub use crate::config::*; use crate::prelude::*; @@ -270,7 +271,10 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr let opts = &cx.sess().opts; // "mcount" function relies on stack pointer. // See . - if opts.unstable_opts.instrument_mcount || matches!(opts.cg.force_frame_pointers, Some(true)) { - fp = FramePointer::Always; + match (opts.unstable_opts.instrument_mcount, opts.cg.force_frame_pointers) { + (true, _) => fp = FramePointer::Always, + (_, Some(fp_opt)) => fp = fp_opt, + (_, None) => {} } let attr_value = match fp { FramePointer::Always => "all", diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 36f9dda7250ca..48e6ac05d7af3 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -20,7 +20,8 @@ use rustc_span::source_map::{RealFileLoader, SourceMapInputs}; use rustc_span::symbol::sym; use rustc_span::{FileName, SourceFileHashAlgorithm}; use rustc_target::spec::{ - CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi, + CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, + RelocModel, WasmCAbi, }; use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel}; use std::collections::{BTreeMap, BTreeSet}; @@ -605,7 +606,7 @@ fn test_codegen_options_tracking_hash() { tracked!(debug_assertions, Some(true)); tracked!(debuginfo, DebugInfo::Limited); tracked!(embed_bitcode, false); - tracked!(force_frame_pointers, Some(false)); + tracked!(force_frame_pointers, Some(FramePointer::MayOmit)); tracked!(force_unwind_tables, Some(true)); tracked!(inline_threshold, Some(0xf007ba11)); tracked!(instrument_coverage, InstrumentCoverage::Yes); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f2bdabbf39428..aee5d5766a1f9 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2913,7 +2913,8 @@ pub(crate) mod dep_tracking { CodeModel, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi, }; use rustc_target::spec::{ - RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, + FramePointer, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, + TlsModel, }; use std::collections::BTreeMap; use std::hash::{DefaultHasher, Hash}; @@ -2970,6 +2971,7 @@ pub(crate) mod dep_tracking { RelocModel, CodeModel, TlsModel, + FramePointer, InstrumentCoverage, CoverageOptions, InstrumentXRay, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 65660286dd73a..01d8e69b32313 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -15,7 +15,7 @@ use rustc_target::spec::{ CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, SanitizerSet, WasmCAbi, }; use rustc_target::spec::{ - RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, + FramePointer, RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, }; use std::collections::BTreeMap; use std::hash::{DefaultHasher, Hasher}; @@ -395,6 +395,8 @@ mod desc { pub const parse_optimization_fuel: &str = "crate=integer"; pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`"; pub const parse_instrument_coverage: &str = parse_bool; + pub const parse_force_frame_pointers: &str = + "`always` (`yes`, `true`, etc), `never` (`no`, `false`, etc) or `non-leaf`"; pub const parse_coverage_options: &str = "`block` | `branch` | `mcdc`"; 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`"; pub const parse_unpretty: &str = "`string` or `string=string`"; @@ -1415,6 +1417,23 @@ mod parse { true } + pub(crate) fn parse_force_frame_pointers( + slot: &mut Option, + v: Option<&str>, + ) -> bool { + let mut always = false; + match v { + Some(v) if parse_bool(&mut always, Some(v)) => { + *slot = Some(if always { FramePointer::Always } else { FramePointer::MayOmit }) + } + Some("always") | None => *slot = Some(FramePointer::Always), + Some("never") => *slot = Some(FramePointer::MayOmit), + Some("non-leaf") => *slot = Some(FramePointer::NonLeaf), + Some(_) => return false, + } + true + } + pub(crate) fn parse_llvm_module_flag( slot: &mut Vec<(String, u32, String)>, v: Option<&str>, @@ -1494,7 +1513,7 @@ options! { "emit bitcode in rlibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED], "extra data to put in each output filename"), - force_frame_pointers: Option = (None, parse_opt_bool, [TRACKED], + force_frame_pointers: Option = (None, parse_force_frame_pointers, [TRACKED], "force use of the frame pointers"), #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")] force_unwind_tables: Option = (None, parse_opt_bool, [TRACKED],