Repository navigation
s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers - #163315
Conversation
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rustbot reroll |
33ff467 to
b0cd986
Compare
This comment has been minimized.
This comment has been minimized.
|
Or I just move the warning to creation time of the |
b0cd986 to
ebe9107
Compare
|
Per #t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027 @ 💬 I think this needs an MCP, r? @davidtwco |
|
my understanding is that we need the MCP as soon as the |
|
My impression from the Zulip thread and the MCP RFC is that an MCP is generally for when the (unstable) flag is being added, with a rfcbot FCP required for stabilisation. |
|
Thanks for looking into this. From my perspective, a hard switch would be perfectly fine. The grace period actually caused some confusion on my side, and I don't think there's much value in carrying both variants for a transition period. While enabling Rust support for s390 in the Linux kernel, I ended up using this argument as well, and I'd be happy to adapt to the new form directly. Redirecting the argument from one version to the next sounds like a good solution to me. |
|
I think it'd be very confusing for |
ebe9107 to
369414c
Compare
|
Target features are being changed; ensure all ABI effects are being accounted for cc @RalfJung |
369414c to
74285e0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
74285e0 to
91aa84d
Compare
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
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` is completely removed and will be rejected. - When the backchain opt-in is active, the `"frame-pointer"` attribute is suppressed on s390x. 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`. Co-authored-by: Ralf Jung <post@ralfj.de>
474b14c to
94bcd6d
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. |
|
I'll rebase this every now and then on main. Anything else I should do? |
|
Going by @wesleywiser's earlier review and "r=me when FCP passes" statement, plus the only changes since then being obviously correct conflict resolution + the documentation that Wesley suggested: @bors r=wesleywiser |
…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
…uwer Rollup of 13 pull requests Successful merges: - #166266 (miri subtree update) - #155216 (match: Use an aggregate equality comparison for constant array/slice patterns) - #166142 (Lower to `hir::Param`s for extern functions) - #163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers) - #165238 (make conflicting_repr_hints a hard error) - #165366 (Add lint against duplicate parameter names in fns without body) - #166269 (libcore: Revert some comment changes) - #166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates) - #166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta) - #166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods) - #166315 (rustc_diagnostic_item macros added on some iter functions) - #166331 (Include Build IDs in VEX V5 executables) - #166349 (compiletest: Remove some old special-case code paths)
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
…uwer Rollup of 13 pull requests Successful merges: - rust-lang/rust#166266 (miri subtree update) - rust-lang/rust#155216 (match: Use an aggregate equality comparison for constant array/slice patterns) - rust-lang/rust#166142 (Lower to `hir::Param`s for extern functions) - rust-lang/rust#163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers) - rust-lang/rust#165238 (make conflicting_repr_hints a hard error) - rust-lang/rust#165366 (Add lint against duplicate parameter names in fns without body) - rust-lang/rust#166269 (libcore: Revert some comment changes) - rust-lang/rust#166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates) - rust-lang/rust#166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta) - rust-lang/rust#166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods) - rust-lang/rust#166315 (rustc_diagnostic_item macros added on some iter functions) - rust-lang/rust#166331 (Include Build IDs in VEX V5 executables) - rust-lang/rust#166349 (compiletest: Remove some old special-case code paths)
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (1ae83a0): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesResults (primary 2.7%, secondary 2.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Artifact size: 406.41 MiB -> 405.74 MiB (-0.17%) |
|
@rustbot label: +perf-regression-triaged |
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
…uwer Rollup of 13 pull requests Successful merges: - rust-lang/rust#166266 (miri subtree update) - rust-lang/rust#155216 (match: Use an aggregate equality comparison for constant array/slice patterns) - rust-lang/rust#166142 (Lower to `hir::Param`s for extern functions) - rust-lang/rust#163315 (s390x: replace -Ctarget-feature=+backchain with -Cforce-frame-pointers) - rust-lang/rust#165238 (make conflicting_repr_hints a hard error) - rust-lang/rust#165366 (Add lint against duplicate parameter names in fns without body) - rust-lang/rust#166269 (libcore: Revert some comment changes) - rust-lang/rust#166287 (Use `core::ptr` in `implicit_provenance_casts` help for `no_std` crates) - rust-lang/rust#166306 (bootstrap: Stop passing `-Ztrim-paths` to cargo now that it's stable in beta) - rust-lang/rust#166309 (Add `#[must_use]` to `Ip*Addr::as_octets` methods) - rust-lang/rust#166315 (rustc_diagnostic_item macros added on some iter functions) - rust-lang/rust#166331 (Include Build IDs in VEX V5 executables) - rust-lang/rust#166349 (compiletest: Remove some old special-case code paths)
View all comments
Summary
On s390x, the
backchainLLVM 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-pointersnow enables the"backchain"LLVM function attribute on s390x, rather than the generic"frame-pointer"attribute used on other architectures.-Ctarget-feature=+backchainemits a error pointing to the new mechanism.-Zinstrument-mcount) are unaffected and still emit"frame-pointer".s390x_fn_attrs()inattributes.rs.This implements the proposed solution discussed on Zulip #t-compiler/major changes > Introduce new -C flag for cross-target c… compiler-team#1027.
Background
Frame pointers on s390x
Setting
-Cforce-frame-pointers=yeson s390x forces the"frame-pointer"LLVM attribute, but this does not form a traversable linked list. As [@uweigand] explained ([#150766 comment]):Therefore
-Cforce-frame-pointerson s390x provides no stack-walking benefit.Backchain
The s390x ELF ABI 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-pointeron 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-stackwith backchain on a non-softfloat target is rejected at compile time([#152432]).rustc arg discussion
Initially backchain was introduced as an unstable
target-featuremimicking 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 thetarget-feature=+backchain. This lead to discussions and the overall consent is that:on s390x, enabling normal
frame-poitnerswill never be done by the user.if a user wants
frame-pointersthe user actually wants: stack-unwinding on x86 viaframe-pointersbut ons390xviabackchain-Cforce-frame-pointers=yesshould ons390xenablebackchainand NOT theframe-pointerattributethe old
-Ctarget-feature=+backchainpattern should emit a nice error and point to-Cforce-frame-pointers=yesthe kernel folks are ok with an instant change of behavior without a deprecation period
Alternatives
Most alternatives where discussed and ruled out:
-Ctarget-feature=+backchainstable: backchain is not a real target-feature as its not part of the ISA or architecture. We rather don't wantbackchainto remain atarget-feature-Zbackhain: If the purpose ofbackchainis already covered by other flags or options we shouldn't add a new flag.-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-pointersis 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 expectframe-pointersto behave.A real frame pointer can still get its own flag if anyone ever needs it.
References
cfg(target_feature = "backchain")(s390x target feature) be enabled? #142412soft-floatandpacked-stack#150766s390x-unknown-none-softfloatwithRustcAbi::Softfloat#151154-Ctarget-feature=+backchain#158014