Skip to content

Commit 94b47a3

Browse files
Rollup merge of rust-lang#140774 - workingjubilee:should-force-frame-pointers-favor-the-target-or-cli, r=jieyouxu
Affirm `-Cforce-frame-pointers=off` does not override This PR exists to document that we (that is, the compiler reviewer) implicitly made a decision in rust-lang#86652 that defies the expectations of some programmers. Some programmers believe `-Cforce-frame-pointers=false` should obey the programmer in all cases, forcing the compiler to avoid generating frame pointers, even if the target specification would indicate they must be generated. However, many targets rely on frame pointers for fast or sound unwinding. T-compiler had a weekly triage meeting on 2025-05-22. This topic was put to discussion because some programmers may expect the target-overriding behavior. In that meeting we decided removing frame pointers, at least with regards to the contract of the `-Cforce-frame-pointers` option, is not required, even if `=off` is passed, and that we will not do so if the target would expect them. This follows from the documentation here: https://doc.rust-lang.org/rustc/codegen-options/index.html#force-frame-pointers We may separately pursue trying to clarify the situation more emphatically in our documentation, or warn when people pass the option when it doesn't do anything.
2 parents 244bbfc + e57b4b1 commit 94b47a3

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --crate-type=rlib -Copt-level=0
3+
//@ revisions: force-on aarch64-apple aarch64-apple-on aarch64-apple-off
4+
//@ [force-on] compile-flags: -Cforce-frame-pointers=on
5+
//@ [aarch64-apple] needs-llvm-components: aarch64
6+
//@ [aarch64-apple] compile-flags: --target=aarch64-apple-darwin
7+
//@ [aarch64-apple-on] needs-llvm-components: aarch64
8+
//@ [aarch64-apple-on] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=on
9+
//@ [aarch64-apple-off] needs-llvm-components: aarch64
10+
//@ [aarch64-apple-off] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=off
11+
/*!
12+
13+
Tests the extent to which frame pointers can be controlled by the CLI.
14+
The behavior of our frame pointer options, at present, is an irreversible ratchet, where
15+
a "weaker" option that allows omitting frame pointers may be overridden by the target demanding
16+
that all code (or all non-leaf code, more often) must be compiled with frame pointers.
17+
This was discussed on 2025-05-22 in the T-compiler meeting and accepted as an intentional change,
18+
ratifying the prior decisions by compiler contributors and reviewers as correct,
19+
though it was also acknowledged that the flag allows somewhat confusing inputs.
20+
21+
We find aarch64-apple-darwin useful because of its icy-clear policy regarding frame pointers,
22+
e.g. <https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms> says:
23+
24+
* The frame pointer register (x29) must always address a valid frame record. Some functions —
25+
such as leaf functions or tail calls — may opt not to create an entry in this list.
26+
As a result, stack traces are always meaningful, even without debug information.
27+
28+
Many Rust fn, if externally visible, may be expected to follow target ABI by tools or asm code!
29+
This can make it a problem to generate ABI-incorrect code, which may mean "with frame pointers".
30+
For this and other reasons, `-Cforce-frame-pointers=off` cannot override the target definition.
31+
This can cause some confusion because it is "reverse polarity" relative to C compilers, which have
32+
commands like `-fomit-frame-pointer`, `-fomit-leaf-frame-pointer`, or `-fno-omit-frame-pointer`!
33+
34+
Specific cases where platforms or tools rely on frame pointers for sound or correct unwinding:
35+
- illumos: <https://smartos.org/bugview/OS-7515>
36+
- aarch64-windows: <https://github.com/rust-lang/rust/issues/123686>
37+
- aarch64-linux: <https://github.com/rust-lang/rust/issues/123733>
38+
- dtrace (freebsd and openbsd): <https://github.com/rust-lang/rust/issues/97723>
39+
- openbsd: <https://github.com/rust-lang/rust/issues/43575>
40+
- i686-msvc <https://github.com/rust-lang/backtrace-rs/pull/584#issuecomment-1966177530>
41+
- i686-mingw: <https://github.com/rust-lang/rust/commit/3f1d3948d6d434b34dd47f132c126a6cb6b8a4ab>
42+
*/
43+
#![feature(no_core, lang_items)]
44+
#![no_core]
45+
46+
extern crate minicore;
47+
48+
// CHECK: define i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] {
49+
#[no_mangle]
50+
pub fn peach(x: u32) -> u32 {
51+
x
52+
}
53+
54+
// CHECK: attributes [[PEACH_ATTRS]] = {
55+
// force-on-SAME: {{.*}}"frame-pointer"="all"
56+
// aarch64-apple-SAME: {{.*}}"frame-pointer"="non-leaf"
57+
// aarch64-apple-on-SAME: {{.*}}"frame-pointer"="all"
58+
//
59+
// yes, we are testing this doesn't do anything:
60+
// aarch64-apple-off-SAME: {{.*}}"frame-pointer"="non-leaf"
61+
// CHECK-SAME: }

0 commit comments

Comments
 (0)