Skip to content

Commit c3d7fb3

Browse files
committed
Auto merge of #124733 - workingjubilee:cant-beleaf-we-dont-have-this, r=saethlin
Support `-Cforce-frame-pointers=non-leaf` Why don't we already support this...? Suggested impl for rust-lang/compiler-team#744
2 parents 05468cf + 761ba5b commit c3d7fb3

File tree

8 files changed

+69
-20
lines changed

8 files changed

+69
-20
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
271271
flags_builder.set("enable_verifier", enable_verifier).unwrap();
272272
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
273273

274-
let preserve_frame_pointer = sess.target.options.frame_pointer
275-
!= rustc_target::spec::FramePointer::MayOmit
276-
|| matches!(sess.opts.cg.force_frame_pointers, Some(true));
274+
let mut frame_ptr = sess.target.options.frame_pointer.clone();
275+
frame_ptr.ratchet(sess.opts.cg.force_frame_pointers);
276+
let preserve_frame_pointer = frame_ptr != rustc_target::spec::FramePointer::MayOmit;
277277
flags_builder
278278
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
279279
.unwrap();

compiler/rustc_codegen_llvm/src/attributes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +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+
if opts.unstable_opts.instrument_mcount {
112+
fp.ratchet(FramePointer::Always);
113113
}
114+
fp.ratchet(opts.cg.force_frame_pointers);
114115
let attr_value = match fp {
115116
FramePointer::Always => "all",
116117
FramePointer::NonLeaf => "non-leaf",

compiler/rustc_interface/src/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ 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, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel, WasmCAbi,
2425
};
25-
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
2626
use std::collections::{BTreeMap, BTreeSet};
2727
use std::num::NonZero;
2828
use std::path::{Path, PathBuf};
@@ -605,7 +605,7 @@ fn test_codegen_options_tracking_hash() {
605605
tracked!(debug_assertions, Some(true));
606606
tracked!(debuginfo, DebugInfo::Limited);
607607
tracked!(embed_bitcode, false);
608-
tracked!(force_frame_pointers, Some(false));
608+
tracked!(force_frame_pointers, FramePointer::Always);
609609
tracked!(force_unwind_tables, Some(true));
610610
tracked!(inline_threshold, Some(0xf007ba11));
611611
tracked!(instrument_coverage, InstrumentCoverage::Yes);

compiler/rustc_session/src/config.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1919
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
2020
use rustc_span::source_map::FilePathMapping;
2121
use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm};
22-
use rustc_target::spec::{LinkSelfContainedComponents, LinkerFeatures};
22+
use rustc_target::spec::{FramePointer, LinkSelfContainedComponents, LinkerFeatures};
2323
use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple};
2424
use std::collections::btree_map::{
2525
Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter,
@@ -2524,6 +2524,15 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
25242524
}
25252525
}
25262526

2527+
if !nightly_options::is_unstable_enabled(matches)
2528+
&& cg.force_frame_pointers == FramePointer::NonLeaf
2529+
{
2530+
early_dcx.early_fatal(
2531+
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
2532+
and a nightly compiler",
2533+
)
2534+
}
2535+
25272536
// For testing purposes, until we have more feedback about these options: ensure `-Z
25282537
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
25292538
// linker-flavor` options.
@@ -2966,10 +2975,8 @@ pub(crate) mod dep_tracking {
29662975
use rustc_span::edition::Edition;
29672976
use rustc_span::RealFileName;
29682977
use rustc_target::spec::{
2969-
CodeModel, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
2970-
};
2971-
use rustc_target::spec::{
2972-
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
2978+
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
2979+
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, WasmCAbi,
29732980
};
29742981
use std::collections::BTreeMap;
29752982
use std::hash::{DefaultHasher, Hash};
@@ -3023,6 +3030,7 @@ pub(crate) mod dep_tracking {
30233030
lint::Level,
30243031
WasiExecModel,
30253032
u32,
3033+
FramePointer,
30263034
RelocModel,
30273035
CodeModel,
30283036
TlsModel,

compiler/rustc_session/src/options.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use rustc_span::edition::Edition;
1212
use rustc_span::RealFileName;
1313
use rustc_span::SourceFileHashAlgorithm;
1414
use rustc_target::spec::{
15-
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, SanitizerSet, WasmCAbi,
16-
};
17-
use rustc_target::spec::{
18-
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
15+
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
16+
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
17+
WasmCAbi,
1918
};
2019
use std::collections::BTreeMap;
2120
use std::hash::{DefaultHasher, Hasher};
@@ -374,6 +373,7 @@ mod desc {
374373
pub const parse_opt_comma_list: &str = parse_comma_list;
375374
pub const parse_number: &str = "a number";
376375
pub const parse_opt_number: &str = parse_number;
376+
pub const parse_frame_pointer: &str = "one of `true`/`yes`/`on`, `false`/`no`/`off`, or (with -Zunstable-options) `non-leaf` or `always`";
377377
pub const parse_threads: &str = parse_number;
378378
pub const parse_time_passes_format: &str = "`text` (default) or `json`";
379379
pub const parse_passes: &str = "a space-separated list of passes, or `all`";
@@ -672,6 +672,18 @@ mod parse {
672672
}
673673
}
674674

675+
pub(crate) fn parse_frame_pointer(slot: &mut FramePointer, v: Option<&str>) -> bool {
676+
let mut yes = false;
677+
match v {
678+
_ if parse_bool(&mut yes, v) && yes => slot.ratchet(FramePointer::Always),
679+
_ if parse_bool(&mut yes, v) => slot.ratchet(FramePointer::MayOmit),
680+
Some("always") => slot.ratchet(FramePointer::Always),
681+
Some("non-leaf") => slot.ratchet(FramePointer::NonLeaf),
682+
_ => return false,
683+
};
684+
true
685+
}
686+
675687
pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
676688
match v {
677689
Some("all") => {
@@ -1479,7 +1491,7 @@ options! {
14791491
"emit bitcode in rlibs (default: yes)"),
14801492
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
14811493
"extra data to put in each output filename"),
1482-
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
1494+
force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED],
14831495
"force use of the frame pointers"),
14841496
#[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
14851497
force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],

compiler/rustc_target/src/spec/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,20 @@ pub enum FramePointer {
14131413
MayOmit,
14141414
}
14151415

1416+
impl FramePointer {
1417+
/// It is intended that the "force frame pointer" transition is "one way"
1418+
/// so this convenience assures such if used
1419+
#[inline]
1420+
pub fn ratchet(&mut self, rhs: FramePointer) -> FramePointer {
1421+
*self = match (*self, rhs) {
1422+
(FramePointer::Always, _) | (_, FramePointer::Always) => FramePointer::Always,
1423+
(FramePointer::NonLeaf, _) | (_, FramePointer::NonLeaf) => FramePointer::NonLeaf,
1424+
_ => FramePointer::MayOmit,
1425+
};
1426+
*self
1427+
}
1428+
}
1429+
14161430
impl FromStr for FramePointer {
14171431
type Err = ();
14181432
fn from_str(s: &str) -> Result<Self, ()> {

src/tools/compiletest/src/header.rs

+2
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
779779
"ignore-haiku",
780780
"ignore-horizon",
781781
"ignore-i686-pc-windows-msvc",
782+
"ignore-illumos",
782783
"ignore-ios",
783784
"ignore-linux",
784785
"ignore-lldb",
@@ -843,6 +844,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
843844
"ignore-x32",
844845
"ignore-x86",
845846
"ignore-x86_64",
847+
"ignore-x86_64-apple-darwin",
846848
"ignore-x86_64-unknown-linux-gnu",
847849
"incremental",
848850
"known-bug",

tests/codegen/force-frame-pointers.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
//@ compile-flags: -C no-prepopulate-passes -C force-frame-pointers=y -Copt-level=0
1+
//@ revisions: Always NonLeaf
2+
//@ [Always] compile-flags: -Cforce-frame-pointers=yes
3+
//@ [NonLeaf] compile-flags: -Cforce-frame-pointers=non-leaf
4+
//@ compile-flags: -Zunstable-options
5+
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
6+
//@ [NonLeaf] ignore-illumos
7+
//@ [NonLeaf] ignore-openbsd
8+
//@ [NonLeaf] ignore-x86
9+
//@ [NonLeaf] ignore-x86_64-apple-darwin
10+
//@ [NonLeaf] ignore-windows-gnu
11+
//@ [NonLeaf] ignore-thumb
12+
// result is platform-dependent based on platform's frame pointer settings
213

314
#![crate_type = "lib"]
415

5-
// CHECK: attributes #{{.*}} "frame-pointer"="all"
16+
// Always: attributes #{{.*}} "frame-pointer"="all"
17+
// NonLeaf: attributes #{{.*}} "frame-pointer"="non-leaf"
618
pub fn foo() {}

0 commit comments

Comments
 (0)