Repository navigation
Conversation
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Target features always need to be documented (example from a past s390x stabilization). Also, since these always need a lang FCP, they generally need a written proposal as to what is being stabilized in order for them to make a decision. |
|
According to target expert @uweigand, 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). So 👍 from the ABI side. |
3e78ec9 to
7784825
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
ok, I think for backchain stabilization this should be it. |
|
So you mean this? |
7784825 to
789b5ce
Compare
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
I definitely do not want a single flag that provides different backtrace mechanisms on different versions of rustc. In Linux, we'll need to make sure that Rust and C use the same mechanism, and this would make that a lot harder. We would have to start hard-coding the version numbers at which rustc switches from one mechanism to another in our makefiles. |
|
One is users of tooling like Linux's perf, backtrace, and similar tooling that should make use of what it can find in the binary to figure out what the stack is at any given point in time. For the most part users of this tooling don't care how that goal is actually accomplished (I think), they just want it to work. For that usecase, it seems like I think there is a legitimate need for requesting a particular implementation of the "fast stack trace" or whatever we call it that you're calling out -- cross-compiler interop. I could see that being an optional parameter, e.g., We could also add this to Ultimately if the only targets that don't use frame pointers are less frequently used ones (e.g., s390x), maybe the cost of designing a nice option for this isn't worth it and we could stabilize it under -Ctarget-feature or -Cbackchain. It does seem like there's opportunity to provide a better cross-target experience here. |
|
First, I agree that rustc definitely needs to expose the same control over low-level platform-specific details what code and metadata gets emitted as other toolchains. I think it's also really important to expose them under recognizably similar names. Not only for specific interop needs, but also because there is a lot of existing material and knowledge out there and in people's heads that speaks about frame pointers even though it's technically incorrect and not completely portable. I don't think Given that such a low level knobs need to exit, I'm skeptical about doing a larger redesign of
In addition, it's not obvious to me that So I don't think this PR / stabilization is a good place to try and tackle this much larger problem. Let's spin that off into a separate thread and not block the s390x-specific low-level compiler knob on it. |
|
One of the big value-adds of Rust is that we are not just repeating the mistakes of C and C++, so "we should use their names even if we all agree they are terrible" is IMO not a good argument. rustc flag names are as good a place to get pedagogic about this as the Rust standard library and the language itself, and there we deliberately make our own choices all the time, often with great success.
So are you saying we should add |
|
I don't (yet?) have a strong opinion on how to spell the target-specific flag for controlling this aspect of codegen. It could be a target feature, or a new top level flag What I am saying is that we should have that low-level, target-specific flag in some form. I don't see a good way to not have that flag. Maybe if another target (PPC?) has basically the same mechanism, we can have a common flag for that, similar to e.g. Centering user stories like "profiling" or "better backtrace on panic" means not guaranteeing what concrete mechanism it maps to. As discussed above, that's insufficient because sometimes the user's intent is to pick the mechanism. We may still want to have flags aimed at those use cases, but as they touch many areas that are currently separate stable flags, it seems like a different feature that should be designed separately. If we center the low-level mechanisms of stack-walking, then the available options, what they mean, and their trade-offs are necessarily platform-specific to some extent. There is some commonality between "things that let you walk the stack but not actually unwind it" (frame pointers, backchain, SFrame, ORC), which may suggest a new And if you expose the individual platform specific mechanisms, you have to name them. In that context I don't think there's anything really wrong with
|
Alice also said that above. This is a fair point, I agree we need to maintain a way to control the mechanism. This could be achieved by having specific values for such a (Note that I don't have made up my mind about this yet, I am just throwing ideas into the room.) |
|
It is worth mentioning that we already have at least one target feature that's arguably not a target feature: |
|
I filed an MCP for the compiler team to discuss what the codegen option should look like: rust-lang/compiler-team#1027. |
|
☔ The latest upstream changes (presumably #160725) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
Let's cancel that FCP... @rfcbot fcp cancel Please renominate if, after discussion, there are further questions for lang. |
|
@traviscross proposal cancelled. |
…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
…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
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
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
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
|
|
View all comments
Stabilization report: s390x
backchaintarget featureSummary
This stabilizes the s390x (SystemZ) target feature
backchain.When
backchainis enabled, the function prologue stores the caller's stackpointer into the first slot (the
backchainslot) of the function's stackframe. This links all stack frames into a chain that can be walked without
DWARF/CFI unwind information, which is how the Linux kernel unwinds the stack
on s390x. The primary motivation for stabilization is Rust-for-Linux: the s390x
kernel is compiled with
backchainenabled (-mbackchainin GCC/Clang), andRust kernel code must match.
backchainis not a hardware (ISA) capability — it is a pure codegen option,available on every s390x CPU. The feature name matches LLVM's SystemZ feature
backchain; GCC and Clang expose the same functionality as-mbackchain.Tracking:
-Ctarget-feature=+backchain#158014Reference PRs:
What is stabilized
On s390x targets,
backchainbecomes a stable target feature, i.e. all of thefollowing are accepted on stable without warnings:
and on the command line:
What isn't stabilized
vector-*extensions were stabilizedseparately in 1.93 via
s390x_target_feature_vector; the remaining ISAfeatures stay gated behind
s390x_target_feature).-Zpacked-stack(the GCC-mpacked-stackequivalent) remains unstable; onlyits interaction with
backchainis relevant here (see below).soft-floatremains unstable.Design
Reference
The Reference documents stable target features per architecture in
attributes/codegen.md. A PR addingbackchainto the s390x table accompaniesthis stabilization: rust-lang/reference#2317
RFC history
None. Target features are added and stabilized through the tracking-issue /
stabilization-report process rather than the RFC process.
Answers to unresolved questions
The tracking issue (#150259) listed one unresolved question about
the
packed-stackinteraction (#152432). It has no impact onbackchainitself, which stays a regular target feature matching how LLVMmodels it; the
packed-stackcombination is handled as described in Key points.No unresolved questions remain.
Post-RFC changes
None (no RFC; see above).
Key points
The only design decision of note is how to handle the interaction with the
(unstable)
-Zpacked-stackoption. A packed stack frame has nobackchainslot unless
soft-floatis also enabled, so thepacked-stack+backchain+hard-floatcombination cannot be lowered and makes LLVM ICE.rustcrejectsit up front with a dedicated hard error (#152432).
backchainonits own is uncontentious: it is a pure, additive codegen option available on
every s390x CPU.
Nightly extensions
The remaining s390x ISA target features stay gated behind
s390x_target_feature, and-Zpacked-stackandsoft-floatremain unstable.Stabilizing
backchaincommits us to nothing about those: it is a single,self-contained codegen flag whose only cross-feature interaction
(
packed-stack) is guarded by a hard error (see Key points).Doors closed
None.
backchainmaps directly onto the LLVMbackchainfeature and theestablished
-mbackchainsemantics shared with GCC/Clang, so stabilizing itdoes not constrain future language or target-feature work.
Feedback
Call for testing
No formal "call for testing" was issued. The feature has been exercised on
nightly by the Rust-for-Linux s390x work (see Nightly use).
Nightly use
The known nightly consumer is Rust-for-Linux: the s390x kernel is built with
-mbackchain, so Rust kernel code targeting s390x must enablebackchaintomatch. This is the motivation for stabilization.
Implementation
Major parts
s390x-unknown-none-softfloatwithRustcAbi::Softfloat#151154Coverage
tests/codegen-llvm/backchain.rs—-Ctarget-feature=+backchainresults inthe
+backchainLLVM function attribute.tests/assembly-llvm/s390x-backchain-toggle.rs— the prologue actuallystores the
backchainwhen enabled (+backchain), and does not when disabled(
-backchain) or by default.tests/ui/target-feature/packedstack-combinations.rs— thepacked-stack/backchaininteraction: rejected onhard-floattargetswhether
backchaincomes from#[target_feature]or-Ctarget-feature,accepted on
s390x-unknown-none-softfloat.tests/codegen-llvm/packedstack.rs—packed-stackattribute emission onthe
soft-floattarget.tests/ui/check-cfg/target_feature.rs—backchainis a known value forcfg(target_feature).There are no known or intentional gaps in coverage.
Outstanding bugs
None. The former blocker #142412 is fixed.
Outstanding FIXMEs
None.
Tool changes
None required — target features need no support from these tools beyond what
exists generically.
Breaking changes
None. This stabilization only makes an already-existing nightly target feature
available on stable; it does not change the meaning of any existing code, so no
crater run is applicable.
Crater report:
Crater analysis:
PRs to affected crates:
Type system, opsem
Compile-time checks
The only compile-time check is the rejection of the invalid
packed-stack+backchain+hard-floatcombination, which LLVM cannot lower and would ICEon.
rustcemits a dedicated hard error up front (#152432); seeCoverage for the test.
Type system rules
No new type system rules.
backchainis governed by the existingtarget_feature1.1 rules for enabling and detecting target features; it addsno feature-specific typing rules.
Sound by default?
Yes. It does not change the calling convention or any type's ABI: the
backchainslot is part of the standard s390x ELF ABI stack frame layout, andthe feature only controls whether the prologue stores into it. Since it is not
a hardware
capability (see Summary), the
#[target_feature]caller obligation is triviallysatisfied on every s390x CPU, so no unsafe opt-in is needed.
Breaks the AM?
No. It cannot introduce undefined behavior or expose the underlying
assembly-level implementation. The one invalid combination is rejected at
compile time (see Compile-time checks).
Common interactions
Temporaries
Not applicable. The feature introduces no new expressions and therefore no new
temporaries.
Drop order
Not applicable. The feature does not affect the order in which values are
dropped.
Pre-expansion / post-expansion
Not applicable.
backchainraises no new pre- vs. post-expansion questions; itis handled like any other target feature in
#[target_feature]andcfg(target_feature).Edition hygiene
Not applicable. The feature is not gated on an edition.
SemVer implications
No new hazards beyond those that already apply to
#[target_feature]generally. As with any target feature, adding or removing
#[target_feature(enable = "backchain")]on a public function can affectwhether it can be used as a plain function pointer, so it follows the existing
target_featureconventions;backchainintroduces nothing beyond that.Exposing other features
None. Its only interaction with an unstable feature is the guarded
-Zpacked-stackcombination (see Key points); nopacked-stackbehavior leaksonto stable.
History
See Major parts for the annotated implementation PRs. Additional context not
listed there:
cfg(target_feature = "backchain")(s390x target feature) be enabled? #142412-Ctarget-feature=+backchain#158014Acknowledgments
backchaintarget featurepacked-stacksupport,soft-floattarget, this stabilizationNo one who worked on this has objected to stabilizing it now.
Open items