Skip to content

Commit 38ce339

Browse files
committed
Add support for -Cforce-frame-poiners=non-leaf
This brings the command-line option up to parity with the frame-pointers field in the json target specs.
1 parent ac385a5 commit 38ce339

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4545
use rustc_session::config::OutputFilenames;
4646
use rustc_session::Session;
4747
use rustc_span::{sym, Symbol};
48+
use rustc_target::spec::FramePointer;
4849

4950
pub use crate::config::*;
5051
use crate::prelude::*;
@@ -270,7 +271,10 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
270271

271272
let preserve_frame_pointer = sess.target.options.frame_pointer
272273
!= rustc_target::spec::FramePointer::MayOmit
273-
|| matches!(sess.opts.cg.force_frame_pointers, Some(true));
274+
|| matches!(
275+
sess.opts.cg.force_frame_pointers,
276+
Some(FramePointer::Always | FramePointer::NonLeaf)
277+
);
274278
flags_builder
275279
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
276280
.unwrap();

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
108108
let opts = &cx.sess().opts;
109109
// "mcount" function relies on stack pointer.
110110
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
111-
if opts.unstable_opts.instrument_mcount || matches!(opts.cg.force_frame_pointers, Some(true)) {
112-
fp = FramePointer::Always;
111+
match (opts.unstable_opts.instrument_mcount, opts.cg.force_frame_pointers) {
112+
(true, _) => fp = FramePointer::Always,
113+
(_, Some(fp_opt)) => fp = fp_opt,
114+
(_, None) => {}
113115
}
114116
let attr_value = match fp {
115117
FramePointer::Always => "all",

compiler/rustc_interface/src/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
2020
use rustc_span::symbol::sym;
2121
use rustc_span::{FileName, SourceFileHashAlgorithm};
2222
use rustc_target::spec::{
23-
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
23+
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
24+
RelocModel, WasmCAbi,
2425
};
2526
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
2627
use std::collections::{BTreeMap, BTreeSet};
@@ -605,7 +606,7 @@ fn test_codegen_options_tracking_hash() {
605606
tracked!(debug_assertions, Some(true));
606607
tracked!(debuginfo, DebugInfo::Limited);
607608
tracked!(embed_bitcode, false);
608-
tracked!(force_frame_pointers, Some(false));
609+
tracked!(force_frame_pointers, Some(FramePointer::MayOmit));
609610
tracked!(force_unwind_tables, Some(true));
610611
tracked!(inline_threshold, Some(0xf007ba11));
611612
tracked!(instrument_coverage, InstrumentCoverage::Yes);

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,8 @@ pub(crate) mod dep_tracking {
29132913
CodeModel, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
29142914
};
29152915
use rustc_target::spec::{
2916-
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
2916+
FramePointer, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple,
2917+
TlsModel,
29172918
};
29182919
use std::collections::BTreeMap;
29192920
use std::hash::{DefaultHasher, Hash};
@@ -2970,6 +2971,7 @@ pub(crate) mod dep_tracking {
29702971
RelocModel,
29712972
CodeModel,
29722973
TlsModel,
2974+
FramePointer,
29732975
InstrumentCoverage,
29742976
CoverageOptions,
29752977
InstrumentXRay,

compiler/rustc_session/src/options.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::spec::{
1515
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, SanitizerSet, WasmCAbi,
1616
};
1717
use rustc_target::spec::{
18-
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
18+
FramePointer, RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
1919
};
2020
use std::collections::BTreeMap;
2121
use std::hash::{DefaultHasher, Hasher};
@@ -395,6 +395,8 @@ mod desc {
395395
pub const parse_optimization_fuel: &str = "crate=integer";
396396
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
397397
pub const parse_instrument_coverage: &str = parse_bool;
398+
pub const parse_force_frame_pointers: &str =
399+
"`always` (`yes`, `true`, etc), `never` (`no`, `false`, etc) or `non-leaf`";
398400
pub const parse_coverage_options: &str = "`block` | `branch` | `mcdc`";
399401
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`";
400402
pub const parse_unpretty: &str = "`string` or `string=string`";
@@ -1415,6 +1417,21 @@ mod parse {
14151417
true
14161418
}
14171419

1420+
pub(crate) fn parse_force_frame_pointers(
1421+
slot: &mut Option<FramePointer>,
1422+
v: Option<&str>,
1423+
) -> bool {
1424+
match v {
1425+
Some("always" | "yes" | "y" | "on" | "true") | None => {
1426+
*slot = Some(FramePointer::Always)
1427+
}
1428+
Some("never" | "false" | "no" | "n" | "off") => *slot = Some(FramePointer::MayOmit),
1429+
Some("non-leaf") => *slot = Some(FramePointer::NonLeaf),
1430+
Some(_) => return false,
1431+
}
1432+
true
1433+
}
1434+
14181435
pub(crate) fn parse_llvm_module_flag(
14191436
slot: &mut Vec<(String, u32, String)>,
14201437
v: Option<&str>,
@@ -1494,7 +1511,7 @@ options! {
14941511
"emit bitcode in rlibs (default: yes)"),
14951512
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
14961513
"extra data to put in each output filename"),
1497-
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
1514+
force_frame_pointers: Option<FramePointer> = (None, parse_force_frame_pointers, [TRACKED],
14981515
"force use of the frame pointers"),
14991516
#[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
15001517
force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],

0 commit comments

Comments
 (0)