Repository navigation
s390x: Fix a regression related to backchain feature - #129940
Merged
Merged
Conversation
... can not be correctly gated using #[cfg] macro
Contributor
Author
|
@rustbot label O-SystemZ A-LLVM A-target-feature C-bug |
RalfJung
reviewed
Sep 3, 2024
RalfJung
reviewed
Sep 3, 2024
RalfJung
reviewed
Sep 3, 2024
liushuyu
force-pushed
the
s390x-target-features
branch
from
September 3, 2024 21:02
b6ad204 to
e318af1
Compare
RalfJung
reviewed
Sep 4, 2024
liushuyu
force-pushed
the
s390x-target-features
branch
from
September 4, 2024 14:11
e318af1 to
6e4c5c1
Compare
Member
|
Thanks :)
@bors r+ rollup
|
Contributor
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Sep 5, 2024
…RalfJung s390x: Fix a regression related to backchain feature In rust-lang#127506, we introduced a new IBM Z-specific target feature, `backchain`. This particular `target-feature` was available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features. This led to an unfortunate regression where `cfg!(target-feature = "backchain")` will always return true. This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again. Fixes rust-lang#129927. r? `@RalfJung`
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Sep 5, 2024
…RalfJung s390x: Fix a regression related to backchain feature In rust-lang#127506, we introduced a new IBM Z-specific target feature, `backchain`. This particular `target-feature` was available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features. This led to an unfortunate regression where `cfg!(target-feature = "backchain")` will always return true. This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again. Fixes rust-lang#129927. r? ``@RalfJung``
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 5, 2024
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) - rust-lang#129653 (clarify that addr_of creates read-only pointers) - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - rust-lang#129939 (explain why Rvalue::Len still exists) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc) - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test) - rust-lang#129944 (Add compat note for trait solver change) - rust-lang#129947 (Add digit separators in `Duration` examples) - rust-lang#129955 (Temporarily remove fmease from the review rotation) - rust-lang#129957 (forward linker option to lint-docs) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 5, 2024
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) - rust-lang#129653 (clarify that addr_of creates read-only pointers) - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - rust-lang#129939 (explain why Rvalue::Len still exists) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc) - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test) - rust-lang#129944 (Add compat note for trait solver change) - rust-lang#129947 (Add digit separators in `Duration` examples) - rust-lang#129955 (Temporarily remove fmease from the review rotation) - rust-lang#129957 (forward linker option to lint-docs) r? `@ghost` `@rustbot` modify labels: rollup
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Sep 5, 2024
…RalfJung s390x: Fix a regression related to backchain feature In rust-lang#127506, we introduced a new IBM Z-specific target feature, `backchain`. This particular `target-feature` was available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features. This led to an unfortunate regression where `cfg!(target-feature = "backchain")` will always return true. This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again. Fixes rust-lang#129927. r? `@RalfJung`
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 5, 2024
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined) - rust-lang#129653 (clarify that addr_of creates read-only pointers) - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - rust-lang#129939 (explain why Rvalue::Len still exists) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc) - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test) - rust-lang#129944 (Add compat note for trait solver change) - rust-lang#129947 (Add digit separators in `Duration` examples) - rust-lang#129955 (Temporarily remove fmease from the review rotation) - rust-lang#129957 (forward linker option to lint-docs) Failed merges: - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 5, 2024
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined) - rust-lang#129653 (clarify that addr_of creates read-only pointers) - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - rust-lang#129939 (explain why Rvalue::Len still exists) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc) - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test) - rust-lang#129944 (Add compat note for trait solver change) - rust-lang#129947 (Add digit separators in `Duration` examples) - rust-lang#129955 (Temporarily remove fmease from the review rotation) - rust-lang#129957 (forward linker option to lint-docs) Failed merges: - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 5, 2024
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined) - rust-lang#129653 (clarify that addr_of creates read-only pointers) - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - rust-lang#129939 (explain why Rvalue::Len still exists) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc) - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test) - rust-lang#129944 (Add compat note for trait solver change) - rust-lang#129947 (Add digit separators in `Duration` examples) - rust-lang#129955 (Temporarily remove fmease from the review rotation) - rust-lang#129957 (forward linker option to lint-docs) Failed merges: - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) r? `@ghost` `@rustbot` modify labels: rollup
Member
|
@bors r- |
Contributor
Author
I can't reproduce it on my local device (Linux). Unfortunately, I don't own an Apple device to test the issue |
Member
|
mmh, lets see if this can land on its own then @bors r=RalfJung rollup=iffy |
Contributor
Member
|
Sounds unlikely that this PR would lead to an LLVM crash... I guess we'll see. |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 7, 2024
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#128871 (bypass linker configuration and cross target check for specific commands) - rust-lang#129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging) - rust-lang#129614 (Adjust doc comment of Condvar::wait_while) - rust-lang#129840 (Implement suggestions for `elided_named_lifetimes`) - rust-lang#129891 (Do not request sanitizers for naked functions) - rust-lang#129899 (Add Suggestions for Misspelled Keywords) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129987 (Don't store region in `CapturedPlace`) - rust-lang#130054 (Add missing quotation marks) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 7, 2024
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#128871 (bypass linker configuration and cross target check for specific commands) - rust-lang#129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging) - rust-lang#129614 (Adjust doc comment of Condvar::wait_while) - rust-lang#129840 (Implement suggestions for `elided_named_lifetimes`) - rust-lang#129891 (Do not request sanitizers for naked functions) - rust-lang#129899 (Add Suggestions for Misspelled Keywords) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129987 (Don't store region in `CapturedPlace`) - rust-lang#130054 (Add missing quotation marks) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Sep 7, 2024
Rollup merge of rust-lang#129940 - liushuyu:s390x-target-features, r=RalfJung s390x: Fix a regression related to backchain feature In rust-lang#127506, we introduced a new IBM Z-specific target feature, `backchain`. This particular `target-feature` was available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features. This led to an unfortunate regression where `cfg!(target-feature = "backchain")` will always return true. This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again. Fixes rust-lang#129927. r? `@RalfJung`
7 tasks done
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Nov 22, 2026
…ywiser s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers # Summary On s390x, the `backchain` LLVM function attribute saves the "unwind" (backchain) pointer (r15) into the caller's parameter area, enabling external stack unwinders (e.g. Linux perf) to walk the call chain. Previously this was enabled via `-Ctarget-feature=+backchain`, which piggy-backed on the target-feature machinery even though backchain is not a CPU or ISA feature. This commit introduces a cleaner mechanism: - `-Cforce-frame-pointers` now enables the `"backchain"` LLVM *function attribute* on s390x, rather than the generic `"frame-pointer"` attribute used on other architectures. - `-Ctarget-feature=+backchain` emits a error pointing to the new mechanism. - Other reasons to set frame pointers (e.g. `-Zinstrument-mcount`) are unaffected and still emit `"frame-pointer"`. - All s390x-specific frame-pointer/backchain/packed-stack logic is consolidated in `s390x_fn_attrs()` in `attributes.rs`. This implements the proposed solution discussed on Zulip [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/with/628127751). # Background ## Frame pointers on s390x Setting `-Cforce-frame-pointers=yes` on s390x forces the `"frame-pointer"` LLVM attribute, but this does **not** form a traversable linked list. As [@uweigand] explained ([rust-lang#150766 comment]): > Even *if* we force frame pointer registers to be used, those are not stored on the stack in a way that forms a linked list that can be followed. The `-mbackchain` option simply generates prolog code that manages an equivalent linked list of stack frames at runtime. Therefore `-Cforce-frame-pointers` on s390x provides **no stack-walking benefit**. ## Backchain The [s390x ELF ABI](https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) reserves **backchain slot** - a pointer back to the caller's frame. This can be used to walk the entire call chain without DWARF CFI. LLVM exposes this as the `"backchain"` function attribute, equivalent to GCC's `-mbackchain`. Backchain is **not** a CPU capability. It is a whole-binary code-generation convention, similar in nature to `-fno-omit-frame-pointer` on x86. This is reflected in LLVM modelling it as a *function attribute*, not a target feature [rust-lang#150766 comment 2]. Enabling backchain does **not** break ABI compatibility: backchain-enabled and -disabled functions can freely call each other. The one notable exception is `packed-stack`: combining `-Zpacked-stack` with backchain on a non-softfloat target is rejected at compile time([rust-lang#152432]). ## rustc arg discussion Initially backchain was introduced as an unstable `target-feature` mimicking the gcc and clang behavior. Within the grater effort of stabilizing arguments that are needed for Linux Kernel development(Rust-for-Linux/linux#2), attempts where made to stabilize the `target-feature=+backchain`. This lead to discussions and the overall consent is that: 1. **on s390x, enabling *normal* `frame-poitners` will *never* be done by the user.** > There is never any reason to do the latter, and always forcing it would simply cause extra unnecessary run-time overhead when you only actually want the backchain. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619573547) > The problem is that *even when we have a frame pointer*, it cannot be used for unwinding because it *points to the wrong location*. > @uweigand, [rust-lang#158612](rust-lang#158612 (comment)) 2. **if a user wants `frame-pointers` the user actually wants: stack-unwinding on x86 via `frame-pointers` but on `s390x` via `backchain`** > People being told by the internet that -Cforce-frame-pointers=yes makes their gdb bt/perf stack trace collection/etc" work get the right behaviour on s390x as well. > @nagisa, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) > upstream would prefer to reuse fp rather than adding a new option (because fp cannot work for frame-pointer unwinding anyway [...]) > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) > we'd like to understand why `-Cforce-frame-pointers` can't be treated as "not perfect" name for `-mbackchain` on s390x > @Mark-Simulacrum, [rust-lang#158612](rust-lang#158612 (comment)) 3. **`-Cforce-frame-pointers=yes` should on `s390x` enable `backchain` and **NOT** the `frame-pointer` attribute** > As one of the s390x target maintainers, I would be OK with using -Cforce-frame-pointers to enable backchain on s390x while not forcing actual framepointer (r11) usage. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619778159) > I'm happy to second this with the "re-use -Cforce-frame-pointers" approach above (implemented requiring -Zunstable-options on s390x initially) > @davidtwco, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/624886154) 4. **the old `-Ctarget-feature=+backchain` pattern should emit a nice error and point to `-Cforce-frame-pointers=yes`** > ... which also leads to a nicer error. You can set hard_error: true for that so we don't have to worry about the validation logic. > @RalfJung [rust-lang#163315](rust-lang#163315 (comment)) 5. **the kernel folks are ok with an instant change of behavior without a deprecation period** > a hard switch would be perfectly fine. The grace period actually caused some confusion on my side > @dev-japo [rust-lang#163315](rust-lang#163315 (comment)) # Alternatives Most alternatives where discussed and ruled out: - make `-Ctarget-feature=+backchain` stable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't want `backchain` to remain a `target-feature` - create a new rustc flag `-Zbackhain`: If the purpose of `backchain` is already covered by other flags or options we shouldn't add a new flag. - create a new rustc flag to enable stack-walking (e.g.`-Cstack-walking-support`): Most people mean this by setting `-Cforce-frame-pointers`. We should rather make the compiler behave as expected. # Concerns Enabling backchain via `-Cforce-frame-pointers` is low-risk and not a dead end. Backchain is an established, documented option in LLVM, Clang and GCC. Mixing code with and without it is safe. Reusing the flag matches how users and other tools expect `frame-pointers` to behave. > there are no ABI concerns with this feature (having some parts of the code compiled with and some without can lead to poor backtraces but doesn't break anything worse than that) > @RalfJung , relaying @uweigand , [rust-lang#158612](rust-lang#158612 (comment)) > reusing the option would make things easier for existing users > @uweigand , [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) A real frame pointer can still get its own flag if anyone ever needs it. > if they do actually want the actual frame pointers in the wrong place of the stack, we can add -Cforce-frame-pointers=the-broken-s390x-option for them or something > @nagisa [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) # References - rust-lang#127506 - rust-lang#129927 - rust-lang#129940 - rust-lang#142412 - rust-lang#150259 - rust-lang#150766 - rust-lang#151154 - rust-lang#152432 - rust-lang#158014 - rust-lang#158612 - rust-lang#163315
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Nov 22, 2026
…ywiser s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers # Summary On s390x, the `backchain` LLVM function attribute saves the "unwind" (backchain) pointer (r15) into the caller's parameter area, enabling external stack unwinders (e.g. Linux perf) to walk the call chain. Previously this was enabled via `-Ctarget-feature=+backchain`, which piggy-backed on the target-feature machinery even though backchain is not a CPU or ISA feature. This commit introduces a cleaner mechanism: - `-Cforce-frame-pointers` now enables the `"backchain"` LLVM *function attribute* on s390x, rather than the generic `"frame-pointer"` attribute used on other architectures. - `-Ctarget-feature=+backchain` emits a error pointing to the new mechanism. - Other reasons to set frame pointers (e.g. `-Zinstrument-mcount`) are unaffected and still emit `"frame-pointer"`. - All s390x-specific frame-pointer/backchain/packed-stack logic is consolidated in `s390x_fn_attrs()` in `attributes.rs`. This implements the proposed solution discussed on Zulip [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/with/628127751). # Background ## Frame pointers on s390x Setting `-Cforce-frame-pointers=yes` on s390x forces the `"frame-pointer"` LLVM attribute, but this does **not** form a traversable linked list. As [@uweigand] explained ([rust-lang#150766 comment]): > Even *if* we force frame pointer registers to be used, those are not stored on the stack in a way that forms a linked list that can be followed. The `-mbackchain` option simply generates prolog code that manages an equivalent linked list of stack frames at runtime. Therefore `-Cforce-frame-pointers` on s390x provides **no stack-walking benefit**. ## Backchain The [s390x ELF ABI](https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) reserves **backchain slot** - a pointer back to the caller's frame. This can be used to walk the entire call chain without DWARF CFI. LLVM exposes this as the `"backchain"` function attribute, equivalent to GCC's `-mbackchain`. Backchain is **not** a CPU capability. It is a whole-binary code-generation convention, similar in nature to `-fno-omit-frame-pointer` on x86. This is reflected in LLVM modelling it as a *function attribute*, not a target feature [rust-lang#150766 comment 2]. Enabling backchain does **not** break ABI compatibility: backchain-enabled and -disabled functions can freely call each other. The one notable exception is `packed-stack`: combining `-Zpacked-stack` with backchain on a non-softfloat target is rejected at compile time([rust-lang#152432]). ## rustc arg discussion Initially backchain was introduced as an unstable `target-feature` mimicking the gcc and clang behavior. Within the grater effort of stabilizing arguments that are needed for Linux Kernel development(Rust-for-Linux/linux#2), attempts where made to stabilize the `target-feature=+backchain`. This lead to discussions and the overall consent is that: 1. **on s390x, enabling *normal* `frame-poitners` will *never* be done by the user.** > There is never any reason to do the latter, and always forcing it would simply cause extra unnecessary run-time overhead when you only actually want the backchain. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619573547) > The problem is that *even when we have a frame pointer*, it cannot be used for unwinding because it *points to the wrong location*. > @uweigand, [rust-lang#158612](rust-lang#158612 (comment)) 2. **if a user wants `frame-pointers` the user actually wants: stack-unwinding on x86 via `frame-pointers` but on `s390x` via `backchain`** > People being told by the internet that -Cforce-frame-pointers=yes makes their gdb bt/perf stack trace collection/etc" work get the right behaviour on s390x as well. > @nagisa, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) > upstream would prefer to reuse fp rather than adding a new option (because fp cannot work for frame-pointer unwinding anyway [...]) > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) > we'd like to understand why `-Cforce-frame-pointers` can't be treated as "not perfect" name for `-mbackchain` on s390x > @Mark-Simulacrum, [rust-lang#158612](rust-lang#158612 (comment)) 3. **`-Cforce-frame-pointers=yes` should on `s390x` enable `backchain` and **NOT** the `frame-pointer` attribute** > As one of the s390x target maintainers, I would be OK with using -Cforce-frame-pointers to enable backchain on s390x while not forcing actual framepointer (r11) usage. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619778159) > I'm happy to second this with the "re-use -Cforce-frame-pointers" approach above (implemented requiring -Zunstable-options on s390x initially) > @davidtwco, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/624886154) 4. **the old `-Ctarget-feature=+backchain` pattern should emit a nice error and point to `-Cforce-frame-pointers=yes`** > ... which also leads to a nicer error. You can set hard_error: true for that so we don't have to worry about the validation logic. > @RalfJung [rust-lang#163315](rust-lang#163315 (comment)) 5. **the kernel folks are ok with an instant change of behavior without a deprecation period** > a hard switch would be perfectly fine. The grace period actually caused some confusion on my side > @dev-japo [rust-lang#163315](rust-lang#163315 (comment)) # Alternatives Most alternatives where discussed and ruled out: - make `-Ctarget-feature=+backchain` stable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't want `backchain` to remain a `target-feature` - create a new rustc flag `-Zbackhain`: If the purpose of `backchain` is already covered by other flags or options we shouldn't add a new flag. - create a new rustc flag to enable stack-walking (e.g.`-Cstack-walking-support`): Most people mean this by setting `-Cforce-frame-pointers`. We should rather make the compiler behave as expected. # Concerns Enabling backchain via `-Cforce-frame-pointers` is low-risk and not a dead end. Backchain is an established, documented option in LLVM, Clang and GCC. Mixing code with and without it is safe. Reusing the flag matches how users and other tools expect `frame-pointers` to behave. > there are no ABI concerns with this feature (having some parts of the code compiled with and some without can lead to poor backtraces but doesn't break anything worse than that) > @RalfJung , relaying @uweigand , [rust-lang#158612](rust-lang#158612 (comment)) > reusing the option would make things easier for existing users > @uweigand , [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) A real frame pointer can still get its own flag if anyone ever needs it. > if they do actually want the actual frame pointers in the wrong place of the stack, we can add -Cforce-frame-pointers=the-broken-s390x-option for them or something > @nagisa [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) # References - rust-lang#127506 - rust-lang#129927 - rust-lang#129940 - rust-lang#142412 - rust-lang#150259 - rust-lang#150766 - rust-lang#151154 - rust-lang#152432 - rust-lang#158014 - rust-lang#158612 - rust-lang#163315
rust-bors Bot
pushed a commit
that referenced
this pull request
Nov 22, 2026
Rollup merge of #163315 - fneddy:s390x_framepointer, r=wesleywiser s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers # Summary On s390x, the `backchain` LLVM function attribute saves the "unwind" (backchain) pointer (r15) into the caller's parameter area, enabling external stack unwinders (e.g. Linux perf) to walk the call chain. Previously this was enabled via `-Ctarget-feature=+backchain`, which piggy-backed on the target-feature machinery even though backchain is not a CPU or ISA feature. This commit introduces a cleaner mechanism: - `-Cforce-frame-pointers` now enables the `"backchain"` LLVM *function attribute* on s390x, rather than the generic `"frame-pointer"` attribute used on other architectures. - `-Ctarget-feature=+backchain` emits a error pointing to the new mechanism. - Other reasons to set frame pointers (e.g. `-Zinstrument-mcount`) are unaffected and still emit `"frame-pointer"`. - All s390x-specific frame-pointer/backchain/packed-stack logic is consolidated in `s390x_fn_attrs()` in `attributes.rs`. This implements the proposed solution discussed on Zulip [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/with/628127751). # Background ## Frame pointers on s390x Setting `-Cforce-frame-pointers=yes` on s390x forces the `"frame-pointer"` LLVM attribute, but this does **not** form a traversable linked list. As [@uweigand] explained ([#150766 comment]): > Even *if* we force frame pointer registers to be used, those are not stored on the stack in a way that forms a linked list that can be followed. The `-mbackchain` option simply generates prolog code that manages an equivalent linked list of stack frames at runtime. Therefore `-Cforce-frame-pointers` on s390x provides **no stack-walking benefit**. ## Backchain The [s390x ELF ABI](https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) reserves **backchain slot** - a pointer back to the caller's frame. This can be used to walk the entire call chain without DWARF CFI. LLVM exposes this as the `"backchain"` function attribute, equivalent to GCC's `-mbackchain`. Backchain is **not** a CPU capability. It is a whole-binary code-generation convention, similar in nature to `-fno-omit-frame-pointer` on x86. This is reflected in LLVM modelling it as a *function attribute*, not a target feature [#150766 comment 2]. Enabling backchain does **not** break ABI compatibility: backchain-enabled and -disabled functions can freely call each other. The one notable exception is `packed-stack`: combining `-Zpacked-stack` with backchain on a non-softfloat target is rejected at compile time([#152432]). ## rustc arg discussion Initially backchain was introduced as an unstable `target-feature` mimicking the gcc and clang behavior. Within the grater effort of stabilizing arguments that are needed for Linux Kernel development(Rust-for-Linux/linux#2), attempts where made to stabilize the `target-feature=+backchain`. This lead to discussions and the overall consent is that: 1. **on s390x, enabling *normal* `frame-poitners` will *never* be done by the user.** > There is never any reason to do the latter, and always forcing it would simply cause extra unnecessary run-time overhead when you only actually want the backchain. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619573547) > The problem is that *even when we have a frame pointer*, it cannot be used for unwinding because it *points to the wrong location*. > @uweigand, [#158612](#158612 (comment)) 2. **if a user wants `frame-pointers` the user actually wants: stack-unwinding on x86 via `frame-pointers` but on `s390x` via `backchain`** > People being told by the internet that -Cforce-frame-pointers=yes makes their gdb bt/perf stack trace collection/etc" work get the right behaviour on s390x as well. > @nagisa, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) > upstream would prefer to reuse fp rather than adding a new option (because fp cannot work for frame-pointer unwinding anyway [...]) > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) > we'd like to understand why `-Cforce-frame-pointers` can't be treated as "not perfect" name for `-mbackchain` on s390x > @Mark-Simulacrum, [#158612](#158612 (comment)) 3. **`-Cforce-frame-pointers=yes` should on `s390x` enable `backchain` and **NOT** the `frame-pointer` attribute** > As one of the s390x target maintainers, I would be OK with using -Cforce-frame-pointers to enable backchain on s390x while not forcing actual framepointer (r11) usage. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619778159) > I'm happy to second this with the "re-use -Cforce-frame-pointers" approach above (implemented requiring -Zunstable-options on s390x initially) > @davidtwco, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/624886154) 4. **the old `-Ctarget-feature=+backchain` pattern should emit a nice error and point to `-Cforce-frame-pointers=yes`** > ... which also leads to a nicer error. You can set hard_error: true for that so we don't have to worry about the validation logic. > @RalfJung [#163315](#163315 (comment)) 5. **the kernel folks are ok with an instant change of behavior without a deprecation period** > a hard switch would be perfectly fine. The grace period actually caused some confusion on my side > @dev-japo [#163315](#163315 (comment)) # Alternatives Most alternatives where discussed and ruled out: - make `-Ctarget-feature=+backchain` stable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't want `backchain` to remain a `target-feature` - create a new rustc flag `-Zbackhain`: If the purpose of `backchain` is already covered by other flags or options we shouldn't add a new flag. - create a new rustc flag to enable stack-walking (e.g.`-Cstack-walking-support`): Most people mean this by setting `-Cforce-frame-pointers`. We should rather make the compiler behave as expected. # Concerns Enabling backchain via `-Cforce-frame-pointers` is low-risk and not a dead end. Backchain is an established, documented option in LLVM, Clang and GCC. Mixing code with and without it is safe. Reusing the flag matches how users and other tools expect `frame-pointers` to behave. > there are no ABI concerns with this feature (having some parts of the code compiled with and some without can lead to poor backtraces but doesn't break anything worse than that) > @RalfJung , relaying @uweigand , [#158612](#158612 (comment)) > reusing the option would make things easier for existing users > @uweigand , [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) A real frame pointer can still get its own flag if anyone ever needs it. > if they do actually want the actual frame pointers in the wrong place of the stack, we can add -Cforce-frame-pointers=the-broken-s390x-option for them or something > @nagisa [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) # References - #127506 - #129927 - #129940 - #142412 - #150259 - #150766 - #151154 - #152432 - #158014 - #158612 - #163315
github-actions Bot
pushed a commit
to rust-lang/stdarch
that referenced
this pull request
Nov 23, 2026
s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers # Summary On s390x, the `backchain` LLVM function attribute saves the "unwind" (backchain) pointer (r15) into the caller's parameter area, enabling external stack unwinders (e.g. Linux perf) to walk the call chain. Previously this was enabled via `-Ctarget-feature=+backchain`, which piggy-backed on the target-feature machinery even though backchain is not a CPU or ISA feature. This commit introduces a cleaner mechanism: - `-Cforce-frame-pointers` now enables the `"backchain"` LLVM *function attribute* on s390x, rather than the generic `"frame-pointer"` attribute used on other architectures. - `-Ctarget-feature=+backchain` emits a error pointing to the new mechanism. - Other reasons to set frame pointers (e.g. `-Zinstrument-mcount`) are unaffected and still emit `"frame-pointer"`. - All s390x-specific frame-pointer/backchain/packed-stack logic is consolidated in `s390x_fn_attrs()` in `attributes.rs`. This implements the proposed solution discussed on Zulip [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/with/628127751). # Background ## Frame pointers on s390x Setting `-Cforce-frame-pointers=yes` on s390x forces the `"frame-pointer"` LLVM attribute, but this does **not** form a traversable linked list. As [@uweigand] explained ([rust-lang/rust#150766 comment]): > Even *if* we force frame pointer registers to be used, those are not stored on the stack in a way that forms a linked list that can be followed. The `-mbackchain` option simply generates prolog code that manages an equivalent linked list of stack frames at runtime. Therefore `-Cforce-frame-pointers` on s390x provides **no stack-walking benefit**. ## Backchain The [s390x ELF ABI](https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) reserves **backchain slot** - a pointer back to the caller's frame. This can be used to walk the entire call chain without DWARF CFI. LLVM exposes this as the `"backchain"` function attribute, equivalent to GCC's `-mbackchain`. Backchain is **not** a CPU capability. It is a whole-binary code-generation convention, similar in nature to `-fno-omit-frame-pointer` on x86. This is reflected in LLVM modelling it as a *function attribute*, not a target feature [rust-lang/rust#150766 comment 2]. Enabling backchain does **not** break ABI compatibility: backchain-enabled and -disabled functions can freely call each other. The one notable exception is `packed-stack`: combining `-Zpacked-stack` with backchain on a non-softfloat target is rejected at compile time([rust-lang/rust#152432]). ## rustc arg discussion Initially backchain was introduced as an unstable `target-feature` mimicking the gcc and clang behavior. Within the grater effort of stabilizing arguments that are needed for Linux Kernel development(Rust-for-Linux/linux#2), attempts where made to stabilize the `target-feature=+backchain`. This lead to discussions and the overall consent is that: 1. **on s390x, enabling *normal* `frame-poitners` will *never* be done by the user.** > There is never any reason to do the latter, and always forcing it would simply cause extra unnecessary run-time overhead when you only actually want the backchain. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619573547) > The problem is that *even when we have a frame pointer*, it cannot be used for unwinding because it *points to the wrong location*. > @uweigand, [#158612](rust-lang/rust#158612 (comment)) 2. **if a user wants `frame-pointers` the user actually wants: stack-unwinding on x86 via `frame-pointers` but on `s390x` via `backchain`** > People being told by the internet that -Cforce-frame-pointers=yes makes their gdb bt/perf stack trace collection/etc" work get the right behaviour on s390x as well. > @nagisa, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) > upstream would prefer to reuse fp rather than adding a new option (because fp cannot work for frame-pointer unwinding anyway [...]) > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) > we'd like to understand why `-Cforce-frame-pointers` can't be treated as "not perfect" name for `-mbackchain` on s390x > @Mark-Simulacrum, [#158612](rust-lang/rust#158612 (comment)) 3. **`-Cforce-frame-pointers=yes` should on `s390x` enable `backchain` and **NOT** the `frame-pointer` attribute** > As one of the s390x target maintainers, I would be OK with using -Cforce-frame-pointers to enable backchain on s390x while not forcing actual framepointer (r11) usage. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619778159) > I'm happy to second this with the "re-use -Cforce-frame-pointers" approach above (implemented requiring -Zunstable-options on s390x initially) > @davidtwco, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/624886154) 4. **the old `-Ctarget-feature=+backchain` pattern should emit a nice error and point to `-Cforce-frame-pointers=yes`** > ... which also leads to a nicer error. You can set hard_error: true for that so we don't have to worry about the validation logic. > @RalfJung [#163315](rust-lang/rust#163315 (comment)) 5. **the kernel folks are ok with an instant change of behavior without a deprecation period** > a hard switch would be perfectly fine. The grace period actually caused some confusion on my side > @dev-japo [#163315](rust-lang/rust#163315 (comment)) # Alternatives Most alternatives where discussed and ruled out: - make `-Ctarget-feature=+backchain` stable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't want `backchain` to remain a `target-feature` - create a new rustc flag `-Zbackhain`: If the purpose of `backchain` is already covered by other flags or options we shouldn't add a new flag. - create a new rustc flag to enable stack-walking (e.g.`-Cstack-walking-support`): Most people mean this by setting `-Cforce-frame-pointers`. We should rather make the compiler behave as expected. # Concerns Enabling backchain via `-Cforce-frame-pointers` is low-risk and not a dead end. Backchain is an established, documented option in LLVM, Clang and GCC. Mixing code with and without it is safe. Reusing the flag matches how users and other tools expect `frame-pointers` to behave. > there are no ABI concerns with this feature (having some parts of the code compiled with and some without can lead to poor backtraces but doesn't break anything worse than that) > @RalfJung , relaying @uweigand , [#158612](rust-lang/rust#158612 (comment)) > reusing the option would make things easier for existing users > @uweigand , [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) A real frame pointer can still get its own flag if anyone ever needs it. > if they do actually want the actual frame pointers in the wrong place of the stack, we can add -Cforce-frame-pointers=the-broken-s390x-option for them or something > @nagisa [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) # References - rust-lang/rust#127506 - rust-lang/rust#129927 - rust-lang/rust#129940 - rust-lang/rust#142412 - rust-lang/rust#150259 - rust-lang/rust#150766 - rust-lang/rust#151154 - rust-lang/rust#152432 - rust-lang/rust#158014 - rust-lang/rust#158612 - rust-lang/rust#163315
github-merge-queue Bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Nov 23, 2026
s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers # Summary On s390x, the `backchain` LLVM function attribute saves the "unwind" (backchain) pointer (r15) into the caller's parameter area, enabling external stack unwinders (e.g. Linux perf) to walk the call chain. Previously this was enabled via `-Ctarget-feature=+backchain`, which piggy-backed on the target-feature machinery even though backchain is not a CPU or ISA feature. This commit introduces a cleaner mechanism: - `-Cforce-frame-pointers` now enables the `"backchain"` LLVM *function attribute* on s390x, rather than the generic `"frame-pointer"` attribute used on other architectures. - `-Ctarget-feature=+backchain` emits a error pointing to the new mechanism. - Other reasons to set frame pointers (e.g. `-Zinstrument-mcount`) are unaffected and still emit `"frame-pointer"`. - All s390x-specific frame-pointer/backchain/packed-stack logic is consolidated in `s390x_fn_attrs()` in `attributes.rs`. This implements the proposed solution discussed on Zulip [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/with/628127751). # Background ## Frame pointers on s390x Setting `-Cforce-frame-pointers=yes` on s390x forces the `"frame-pointer"` LLVM attribute, but this does **not** form a traversable linked list. As [@uweigand] explained ([rust-lang/rust#150766 comment]): > Even *if* we force frame pointer registers to be used, those are not stored on the stack in a way that forms a linked list that can be followed. The `-mbackchain` option simply generates prolog code that manages an equivalent linked list of stack frames at runtime. Therefore `-Cforce-frame-pointers` on s390x provides **no stack-walking benefit**. ## Backchain The [s390x ELF ABI](https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) reserves **backchain slot** - a pointer back to the caller's frame. This can be used to walk the entire call chain without DWARF CFI. LLVM exposes this as the `"backchain"` function attribute, equivalent to GCC's `-mbackchain`. Backchain is **not** a CPU capability. It is a whole-binary code-generation convention, similar in nature to `-fno-omit-frame-pointer` on x86. This is reflected in LLVM modelling it as a *function attribute*, not a target feature [rust-lang/rust#150766 comment 2]. Enabling backchain does **not** break ABI compatibility: backchain-enabled and -disabled functions can freely call each other. The one notable exception is `packed-stack`: combining `-Zpacked-stack` with backchain on a non-softfloat target is rejected at compile time([rust-lang/rust#152432]). ## rustc arg discussion Initially backchain was introduced as an unstable `target-feature` mimicking the gcc and clang behavior. Within the grater effort of stabilizing arguments that are needed for Linux Kernel development(Rust-for-Linux/linux#2), attempts where made to stabilize the `target-feature=+backchain`. This lead to discussions and the overall consent is that: 1. **on s390x, enabling *normal* `frame-poitners` will *never* be done by the user.** > There is never any reason to do the latter, and always forcing it would simply cause extra unnecessary run-time overhead when you only actually want the backchain. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619573547) > The problem is that *even when we have a frame pointer*, it cannot be used for unwinding because it *points to the wrong location*. > @uweigand, [#158612](rust-lang/rust#158612 (comment)) 2. **if a user wants `frame-pointers` the user actually wants: stack-unwinding on x86 via `frame-pointers` but on `s390x` via `backchain`** > People being told by the internet that -Cforce-frame-pointers=yes makes their gdb bt/perf stack trace collection/etc" work get the right behaviour on s390x as well. > @nagisa, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) > upstream would prefer to reuse fp rather than adding a new option (because fp cannot work for frame-pointer unwinding anyway [...]) > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) > we'd like to understand why `-Cforce-frame-pointers` can't be treated as "not perfect" name for `-mbackchain` on s390x > @Mark-Simulacrum, [#158612](rust-lang/rust#158612 (comment)) 3. **`-Cforce-frame-pointers=yes` should on `s390x` enable `backchain` and **NOT** the `frame-pointer` attribute** > As one of the s390x target maintainers, I would be OK with using -Cforce-frame-pointers to enable backchain on s390x while not forcing actual framepointer (r11) usage. > @uweigand, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/619778159) > I'm happy to second this with the "re-use -Cforce-frame-pointers" approach above (implemented requiring -Zunstable-options on s390x initially) > @davidtwco, [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/624886154) 4. **the old `-Ctarget-feature=+backchain` pattern should emit a nice error and point to `-Cforce-frame-pointers=yes`** > ... which also leads to a nicer error. You can set hard_error: true for that so we don't have to worry about the validation logic. > @RalfJung [#163315](rust-lang/rust#163315 (comment)) 5. **the kernel folks are ok with an instant change of behavior without a deprecation period** > a hard switch would be perfectly fine. The grace period actually caused some confusion on my side > @dev-japo [#163315](rust-lang/rust#163315 (comment)) # Alternatives Most alternatives where discussed and ruled out: - make `-Ctarget-feature=+backchain` stable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't want `backchain` to remain a `target-feature` - create a new rustc flag `-Zbackhain`: If the purpose of `backchain` is already covered by other flags or options we shouldn't add a new flag. - create a new rustc flag to enable stack-walking (e.g.`-Cstack-walking-support`): Most people mean this by setting `-Cforce-frame-pointers`. We should rather make the compiler behave as expected. # Concerns Enabling backchain via `-Cforce-frame-pointers` is low-risk and not a dead end. Backchain is an established, documented option in LLVM, Clang and GCC. Mixing code with and without it is safe. Reusing the flag matches how users and other tools expect `frame-pointers` to behave. > there are no ABI concerns with this feature (having some parts of the code compiled with and some without can lead to poor backtraces but doesn't break anything worse than that) > @RalfJung , relaying @uweigand , [#158612](rust-lang/rust#158612 (comment)) > reusing the option would make things easier for existing users > @uweigand , [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614979602) A real frame pointer can still get its own flag if anyone ever needs it. > if they do actually want the actual frame pointers in the wrong place of the stack, we can add -Cforce-frame-pointers=the-broken-s390x-option for them or something > @nagisa [#t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Introduce.20new.20-C.20flag.20for.20cross-target.20c.E2.80.A6.20compiler-team.231027/near/614754887) # References - rust-lang/rust#127506 - rust-lang/rust#129927 - rust-lang/rust#129940 - rust-lang/rust#142412 - rust-lang/rust#150259 - rust-lang/rust#150766 - rust-lang/rust#151154 - rust-lang/rust#152432 - rust-lang/rust#158014 - rust-lang/rust#158612 - rust-lang/rust#163315
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #127506, we introduced a new IBM Z-specific target feature,
backchain.This particular
target-featurewas available as a function-level attribute in LLVM 17 and below, so some hacks were used to avoid blowing up LLVM when querying the supported LLVM features.This led to an unfortunate regression where
cfg!(target-feature = "backchain")will always return true.This pull request aims to fix this issue, and a test has been introduced to ensure it will never happen again.
Fixes #129927.
r? @RalfJung