mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
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 https://github.com/rust-lang/compiler-team/issues/744
This commit is contained in:
commit
c3d7fb3985
@ -271,9 +271,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
|
|||||||
flags_builder.set("enable_verifier", enable_verifier).unwrap();
|
flags_builder.set("enable_verifier", enable_verifier).unwrap();
|
||||||
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
|
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
|
||||||
|
|
||||||
let preserve_frame_pointer = sess.target.options.frame_pointer
|
let mut frame_ptr = sess.target.options.frame_pointer.clone();
|
||||||
!= rustc_target::spec::FramePointer::MayOmit
|
frame_ptr.ratchet(sess.opts.cg.force_frame_pointers);
|
||||||
|| matches!(sess.opts.cg.force_frame_pointers, Some(true));
|
let preserve_frame_pointer = frame_ptr != rustc_target::spec::FramePointer::MayOmit;
|
||||||
flags_builder
|
flags_builder
|
||||||
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
|
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -108,9 +108,10 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
|
|||||||
let opts = &cx.sess().opts;
|
let opts = &cx.sess().opts;
|
||||||
// "mcount" function relies on stack pointer.
|
// "mcount" function relies on stack pointer.
|
||||||
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
|
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
|
||||||
if opts.unstable_opts.instrument_mcount || matches!(opts.cg.force_frame_pointers, Some(true)) {
|
if opts.unstable_opts.instrument_mcount {
|
||||||
fp = FramePointer::Always;
|
fp.ratchet(FramePointer::Always);
|
||||||
}
|
}
|
||||||
|
fp.ratchet(opts.cg.force_frame_pointers);
|
||||||
let attr_value = match fp {
|
let attr_value = match fp {
|
||||||
FramePointer::Always => "all",
|
FramePointer::Always => "all",
|
||||||
FramePointer::NonLeaf => "non-leaf",
|
FramePointer::NonLeaf => "non-leaf",
|
||||||
|
@ -20,9 +20,9 @@ use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
|
|||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{FileName, SourceFileHashAlgorithm};
|
use rustc_span::{FileName, SourceFileHashAlgorithm};
|
||||||
use rustc_target::spec::{
|
use rustc_target::spec::{
|
||||||
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
|
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
|
||||||
|
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel, WasmCAbi,
|
||||||
};
|
};
|
||||||
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
|
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@ -605,7 +605,7 @@ fn test_codegen_options_tracking_hash() {
|
|||||||
tracked!(debug_assertions, Some(true));
|
tracked!(debug_assertions, Some(true));
|
||||||
tracked!(debuginfo, DebugInfo::Limited);
|
tracked!(debuginfo, DebugInfo::Limited);
|
||||||
tracked!(embed_bitcode, false);
|
tracked!(embed_bitcode, false);
|
||||||
tracked!(force_frame_pointers, Some(false));
|
tracked!(force_frame_pointers, FramePointer::Always);
|
||||||
tracked!(force_unwind_tables, Some(true));
|
tracked!(force_unwind_tables, Some(true));
|
||||||
tracked!(inline_threshold, Some(0xf007ba11));
|
tracked!(inline_threshold, Some(0xf007ba11));
|
||||||
tracked!(instrument_coverage, InstrumentCoverage::Yes);
|
tracked!(instrument_coverage, InstrumentCoverage::Yes);
|
||||||
|
@ -19,7 +19,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
|||||||
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
|
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
|
||||||
use rustc_span::source_map::FilePathMapping;
|
use rustc_span::source_map::FilePathMapping;
|
||||||
use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm};
|
use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm};
|
||||||
use rustc_target::spec::{LinkSelfContainedComponents, LinkerFeatures};
|
use rustc_target::spec::{FramePointer, LinkSelfContainedComponents, LinkerFeatures};
|
||||||
use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple};
|
use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple};
|
||||||
use std::collections::btree_map::{
|
use std::collections::btree_map::{
|
||||||
Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter,
|
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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !nightly_options::is_unstable_enabled(matches)
|
||||||
|
&& cg.force_frame_pointers == FramePointer::NonLeaf
|
||||||
|
{
|
||||||
|
early_dcx.early_fatal(
|
||||||
|
"`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \
|
||||||
|
and a nightly compiler",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// For testing purposes, until we have more feedback about these options: ensure `-Z
|
// For testing purposes, until we have more feedback about these options: ensure `-Z
|
||||||
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
|
// unstable-options` is required when using the unstable `-C link-self-contained` and `-C
|
||||||
// linker-flavor` options.
|
// linker-flavor` options.
|
||||||
@ -2966,10 +2975,8 @@ pub(crate) mod dep_tracking {
|
|||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::RealFileName;
|
use rustc_span::RealFileName;
|
||||||
use rustc_target::spec::{
|
use rustc_target::spec::{
|
||||||
CodeModel, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, WasmCAbi,
|
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
|
||||||
};
|
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, WasmCAbi,
|
||||||
use rustc_target::spec::{
|
|
||||||
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
|
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::hash::{DefaultHasher, Hash};
|
use std::hash::{DefaultHasher, Hash};
|
||||||
@ -3023,6 +3030,7 @@ pub(crate) mod dep_tracking {
|
|||||||
lint::Level,
|
lint::Level,
|
||||||
WasiExecModel,
|
WasiExecModel,
|
||||||
u32,
|
u32,
|
||||||
|
FramePointer,
|
||||||
RelocModel,
|
RelocModel,
|
||||||
CodeModel,
|
CodeModel,
|
||||||
TlsModel,
|
TlsModel,
|
||||||
|
@ -12,10 +12,9 @@ use rustc_span::edition::Edition;
|
|||||||
use rustc_span::RealFileName;
|
use rustc_span::RealFileName;
|
||||||
use rustc_span::SourceFileHashAlgorithm;
|
use rustc_span::SourceFileHashAlgorithm;
|
||||||
use rustc_target::spec::{
|
use rustc_target::spec::{
|
||||||
CodeModel, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, SanitizerSet, WasmCAbi,
|
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
|
||||||
};
|
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
|
||||||
use rustc_target::spec::{
|
WasmCAbi,
|
||||||
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
|
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::hash::{DefaultHasher, Hasher};
|
use std::hash::{DefaultHasher, Hasher};
|
||||||
@ -374,6 +373,7 @@ mod desc {
|
|||||||
pub const parse_opt_comma_list: &str = parse_comma_list;
|
pub const parse_opt_comma_list: &str = parse_comma_list;
|
||||||
pub const parse_number: &str = "a number";
|
pub const parse_number: &str = "a number";
|
||||||
pub const parse_opt_number: &str = parse_number;
|
pub const parse_opt_number: &str = parse_number;
|
||||||
|
pub const parse_frame_pointer: &str = "one of `true`/`yes`/`on`, `false`/`no`/`off`, or (with -Zunstable-options) `non-leaf` or `always`";
|
||||||
pub const parse_threads: &str = parse_number;
|
pub const parse_threads: &str = parse_number;
|
||||||
pub const parse_time_passes_format: &str = "`text` (default) or `json`";
|
pub const parse_time_passes_format: &str = "`text` (default) or `json`";
|
||||||
pub const parse_passes: &str = "a space-separated list of passes, or `all`";
|
pub const parse_passes: &str = "a space-separated list of passes, or `all`";
|
||||||
@ -672,6 +672,18 @@ mod parse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn parse_frame_pointer(slot: &mut FramePointer, v: Option<&str>) -> bool {
|
||||||
|
let mut yes = false;
|
||||||
|
match v {
|
||||||
|
_ if parse_bool(&mut yes, v) && yes => slot.ratchet(FramePointer::Always),
|
||||||
|
_ if parse_bool(&mut yes, v) => slot.ratchet(FramePointer::MayOmit),
|
||||||
|
Some("always") => slot.ratchet(FramePointer::Always),
|
||||||
|
Some("non-leaf") => slot.ratchet(FramePointer::NonLeaf),
|
||||||
|
_ => return false,
|
||||||
|
};
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
|
pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
|
||||||
match v {
|
match v {
|
||||||
Some("all") => {
|
Some("all") => {
|
||||||
@ -1479,7 +1491,7 @@ options! {
|
|||||||
"emit bitcode in rlibs (default: yes)"),
|
"emit bitcode in rlibs (default: yes)"),
|
||||||
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
|
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
|
||||||
"extra data to put in each output filename"),
|
"extra data to put in each output filename"),
|
||||||
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED],
|
||||||
"force use of the frame pointers"),
|
"force use of the frame pointers"),
|
||||||
#[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
|
#[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],
|
force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||||
|
@ -1413,6 +1413,20 @@ pub enum FramePointer {
|
|||||||
MayOmit,
|
MayOmit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FramePointer {
|
||||||
|
/// It is intended that the "force frame pointer" transition is "one way"
|
||||||
|
/// so this convenience assures such if used
|
||||||
|
#[inline]
|
||||||
|
pub fn ratchet(&mut self, rhs: FramePointer) -> FramePointer {
|
||||||
|
*self = match (*self, rhs) {
|
||||||
|
(FramePointer::Always, _) | (_, FramePointer::Always) => FramePointer::Always,
|
||||||
|
(FramePointer::NonLeaf, _) | (_, FramePointer::NonLeaf) => FramePointer::NonLeaf,
|
||||||
|
_ => FramePointer::MayOmit,
|
||||||
|
};
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for FramePointer {
|
impl FromStr for FramePointer {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
|
@ -779,6 +779,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
|
|||||||
"ignore-haiku",
|
"ignore-haiku",
|
||||||
"ignore-horizon",
|
"ignore-horizon",
|
||||||
"ignore-i686-pc-windows-msvc",
|
"ignore-i686-pc-windows-msvc",
|
||||||
|
"ignore-illumos",
|
||||||
"ignore-ios",
|
"ignore-ios",
|
||||||
"ignore-linux",
|
"ignore-linux",
|
||||||
"ignore-lldb",
|
"ignore-lldb",
|
||||||
@ -843,6 +844,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
|
|||||||
"ignore-x32",
|
"ignore-x32",
|
||||||
"ignore-x86",
|
"ignore-x86",
|
||||||
"ignore-x86_64",
|
"ignore-x86_64",
|
||||||
|
"ignore-x86_64-apple-darwin",
|
||||||
"ignore-x86_64-unknown-linux-gnu",
|
"ignore-x86_64-unknown-linux-gnu",
|
||||||
"incremental",
|
"incremental",
|
||||||
"known-bug",
|
"known-bug",
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
//@ compile-flags: -C no-prepopulate-passes -C force-frame-pointers=y -Copt-level=0
|
//@ revisions: Always NonLeaf
|
||||||
|
//@ [Always] compile-flags: -Cforce-frame-pointers=yes
|
||||||
|
//@ [NonLeaf] compile-flags: -Cforce-frame-pointers=non-leaf
|
||||||
|
//@ compile-flags: -Zunstable-options
|
||||||
|
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
|
||||||
|
//@ [NonLeaf] ignore-illumos
|
||||||
|
//@ [NonLeaf] ignore-openbsd
|
||||||
|
//@ [NonLeaf] ignore-x86
|
||||||
|
//@ [NonLeaf] ignore-x86_64-apple-darwin
|
||||||
|
//@ [NonLeaf] ignore-windows-gnu
|
||||||
|
//@ [NonLeaf] ignore-thumb
|
||||||
|
// result is platform-dependent based on platform's frame pointer settings
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
// CHECK: attributes #{{.*}} "frame-pointer"="all"
|
// Always: attributes #{{.*}} "frame-pointer"="all"
|
||||||
|
// NonLeaf: attributes #{{.*}} "frame-pointer"="non-leaf"
|
||||||
pub fn foo() {}
|
pub fn foo() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user