Skip to content

Add support for -Cforce-frame-poiners=non-leaf #125127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -270,7 +271,10 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs

let preserve_frame_pointer = sess.target.options.frame_pointer
!= rustc_target::spec::FramePointer::MayOmit
|| matches!(sess.opts.cg.force_frame_pointers, Some(true));
|| matches!(
sess.opts.cg.force_frame_pointers,
Some(FramePointer::Always | FramePointer::NonLeaf)
);
flags_builder
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
.unwrap();
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
let opts = &cx.sess().opts;
// "mcount" function relies on stack pointer.
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior. The code did not previously override the value of fp if force_frame_pointers was Some(false).

(_, None) => {}
}
let attr_value = match fp {
FramePointer::Always => "all",
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -2970,6 +2971,7 @@ pub(crate) mod dep_tracking {
RelocModel,
CodeModel,
TlsModel,
FramePointer,
InstrumentCoverage,
CoverageOptions,
InstrumentXRay,
Expand Down
23 changes: 21 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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`";
Expand Down Expand Up @@ -1415,6 +1417,23 @@ mod parse {
true
}

pub(crate) fn parse_force_frame_pointers(
slot: &mut Option<FramePointer>,
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>,
Expand Down Expand Up @@ -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<bool> = (None, parse_opt_bool, [TRACKED],
force_frame_pointers: Option<FramePointer> = (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<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
Loading