From f27ed880531867fa548c9780144558cecb6fbe71 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 15 May 2024 21:51:32 -0700 Subject: [PATCH 1/4] codegen: test frame pointer attr prefers CLI opt This test only makes sense if you send it back in time and run it with a now-old Rust commit, e.g. 50e0cc59ffcacda5b48f4edb95e5a5c353624fb0 However, if you do go back that far in time, you will see it pass. --- tests/codegen/frame-pointer-cli-control.rs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codegen/frame-pointer-cli-control.rs diff --git a/tests/codegen/frame-pointer-cli-control.rs b/tests/codegen/frame-pointer-cli-control.rs new file mode 100644 index 0000000000000..12282eea8f48b --- /dev/null +++ b/tests/codegen/frame-pointer-cli-control.rs @@ -0,0 +1,35 @@ +// compile-flags: --crate-type=rlib -Copt-level=0 +// revisions: force-on aarch64-apple aarch64-apple-off +// [force-on] compile-flags: -Cforce-frame-pointers=on +// [aarch64-apple] needs-llvm-components: aarch64 +// [aarch64-apple] compile-flags: --target=aarch64-apple-darwin +// [aarch64-apple-off] needs-llvm-components: aarch64 +// [aarch64-apple-off] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=off +/* +Tests that the frame pointers can be controlled by the CLI. We find aarch64-apple-darwin useful +because of its icy-clear policy regarding frame pointers (software SHALL be compiled with them), +e.g. https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms says: + +* The frame pointer register (x29) must always address a valid frame record. Some functions — + such as leaf functions or tail calls — may opt not to create an entry in this list. + As a result, stack traces are always meaningful, even without debug information. +*/ +#![feature(no_core, lang_items)] +#![no_core] +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} +impl Copy for u32 {} + +// CHECK: define i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] { +#[no_mangle] +pub fn peach(x: u32) -> u32 { + x +} + +// CHECK: attributes [[PEACH_ATTRS]] = { +// force-on-SAME: {{.*}}"frame-pointer"="all" +// aarch64-apple-SAME: {{.*}}"frame-pointer"="all" +// aarch64-apple-off-NOT: {{.*}}"frame-pointer"{{.*}} +// CHECK-SAME: } From a6b62d893f620e81cc04a39acd67e6f638d29358 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 15 May 2024 21:57:01 -0700 Subject: [PATCH 2/4] codegen: modernize frame-pointer-cli-control.rs Update this time-traveler on the changes in compiletest and target specs that they missed over the pass ~3 years by being caught in a time rift. The aarch64-apple rev splits into itself and aarch64-apple-on, because rustc obtained support for non-leaf frame-pointers ever since 9b67cba implemented them and used them in aarch64-apple-darwin's spec. Note that the aarch64-apple-off revision fails, despite modernization. This is because 9b67cba also changed the behavior of rustc to defer to the spec over the command-line interface. --- tests/codegen/frame-pointer-cli-control.rs | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/codegen/frame-pointer-cli-control.rs b/tests/codegen/frame-pointer-cli-control.rs index 12282eea8f48b..2ce9fa22ddb09 100644 --- a/tests/codegen/frame-pointer-cli-control.rs +++ b/tests/codegen/frame-pointer-cli-control.rs @@ -1,10 +1,13 @@ -// compile-flags: --crate-type=rlib -Copt-level=0 -// revisions: force-on aarch64-apple aarch64-apple-off -// [force-on] compile-flags: -Cforce-frame-pointers=on -// [aarch64-apple] needs-llvm-components: aarch64 -// [aarch64-apple] compile-flags: --target=aarch64-apple-darwin -// [aarch64-apple-off] needs-llvm-components: aarch64 -// [aarch64-apple-off] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=off +//@ add-core-stubs +//@ compile-flags: --crate-type=rlib -Copt-level=0 +//@ revisions: force-on aarch64-apple aarch64-apple-on aarch64-apple-off +//@ [force-on] compile-flags: -Cforce-frame-pointers=on +//@ [aarch64-apple] needs-llvm-components: aarch64 +//@ [aarch64-apple] compile-flags: --target=aarch64-apple-darwin +//@ [aarch64-apple-on] needs-llvm-components: aarch64 +//@ [aarch64-apple-on] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=on +//@ [aarch64-apple-off] needs-llvm-components: aarch64 +//@ [aarch64-apple-off] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=off /* Tests that the frame pointers can be controlled by the CLI. We find aarch64-apple-darwin useful because of its icy-clear policy regarding frame pointers (software SHALL be compiled with them), @@ -16,11 +19,8 @@ e.g. https://developer.apple.com/documentation/xcode/writing-arm64-code-for-appl */ #![feature(no_core, lang_items)] #![no_core] -#[lang = "sized"] -trait Sized {} -#[lang = "copy"] -trait Copy {} -impl Copy for u32 {} + +extern crate minicore; // CHECK: define i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] { #[no_mangle] @@ -30,6 +30,7 @@ pub fn peach(x: u32) -> u32 { // CHECK: attributes [[PEACH_ATTRS]] = { // force-on-SAME: {{.*}}"frame-pointer"="all" -// aarch64-apple-SAME: {{.*}}"frame-pointer"="all" +// aarch64-apple-SAME: {{.*}}"frame-pointer"="non-leaf" +// aarch64-apple-on-SAME: {{.*}}"frame-pointer"="all" // aarch64-apple-off-NOT: {{.*}}"frame-pointer"{{.*}} // CHECK-SAME: } From e57b4b19e8ba0ba680461da46c8e2d42886c634a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 15 May 2024 23:47:48 -0700 Subject: [PATCH 3/4] encode compiler team acceptance of `-Cforce-frame-pointers` change --- tests/codegen/frame-pointer-cli-control.rs | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/codegen/frame-pointer-cli-control.rs b/tests/codegen/frame-pointer-cli-control.rs index 2ce9fa22ddb09..d1f2e2b685f72 100644 --- a/tests/codegen/frame-pointer-cli-control.rs +++ b/tests/codegen/frame-pointer-cli-control.rs @@ -8,14 +8,37 @@ //@ [aarch64-apple-on] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=on //@ [aarch64-apple-off] needs-llvm-components: aarch64 //@ [aarch64-apple-off] compile-flags: --target=aarch64-apple-darwin -Cforce-frame-pointers=off -/* -Tests that the frame pointers can be controlled by the CLI. We find aarch64-apple-darwin useful -because of its icy-clear policy regarding frame pointers (software SHALL be compiled with them), -e.g. https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms says: +/*! + +Tests the extent to which frame pointers can be controlled by the CLI. +The behavior of our frame pointer options, at present, is an irreversible ratchet, where +a "weaker" option that allows omitting frame pointers may be overridden by the target demanding +that all code (or all non-leaf code, more often) must be compiled with frame pointers. +This was discussed on 2025-05-22 in the T-compiler meeting and accepted as an intentional change, +ratifying the prior decisions by compiler contributors and reviewers as correct, +though it was also acknowledged that the flag allows somewhat confusing inputs. + +We find aarch64-apple-darwin useful because of its icy-clear policy regarding frame pointers, +e.g. says: * The frame pointer register (x29) must always address a valid frame record. Some functions — such as leaf functions or tail calls — may opt not to create an entry in this list. As a result, stack traces are always meaningful, even without debug information. + +Many Rust fn, if externally visible, may be expected to follow target ABI by tools or asm code! +This can make it a problem to generate ABI-incorrect code, which may mean "with frame pointers". +For this and other reasons, `-Cforce-frame-pointers=off` cannot override the target definition. +This can cause some confusion because it is "reverse polarity" relative to C compilers, which have +commands like `-fomit-frame-pointer`, `-fomit-leaf-frame-pointer`, or `-fno-omit-frame-pointer`! + +Specific cases where platforms or tools rely on frame pointers for sound or correct unwinding: +- illumos: +- aarch64-windows: +- aarch64-linux: +- dtrace (freebsd and openbsd): +- openbsd: +- i686-msvc +- i686-mingw: */ #![feature(no_core, lang_items)] #![no_core] @@ -32,5 +55,7 @@ pub fn peach(x: u32) -> u32 { // force-on-SAME: {{.*}}"frame-pointer"="all" // aarch64-apple-SAME: {{.*}}"frame-pointer"="non-leaf" // aarch64-apple-on-SAME: {{.*}}"frame-pointer"="all" -// aarch64-apple-off-NOT: {{.*}}"frame-pointer"{{.*}} +// +// yes, we are testing this doesn't do anything: +// aarch64-apple-off-SAME: {{.*}}"frame-pointer"="non-leaf" // CHECK-SAME: } From 5a449fb40bd481652b98dd5299e1dfe91cf71ef2 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 16 Jun 2025 23:21:23 -0700 Subject: [PATCH 4/4] tests: remove define so dso_local attr does not disrupt test --- tests/codegen/frame-pointer-cli-control.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/frame-pointer-cli-control.rs b/tests/codegen/frame-pointer-cli-control.rs index d1f2e2b685f72..a65dd132763de 100644 --- a/tests/codegen/frame-pointer-cli-control.rs +++ b/tests/codegen/frame-pointer-cli-control.rs @@ -45,7 +45,7 @@ Specific cases where platforms or tools rely on frame pointers for sound or corr extern crate minicore; -// CHECK: define i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] { +// CHECK: i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] { #[no_mangle] pub fn peach(x: u32) -> u32 { x