3

RFC: Add realign_stack attribute to rustc by benisxdxd · Pull Request #3594 · ru...

 4 weeks ago
source link: https://github.com/rust-lang/rfcs/pull/3594
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Contributor

This is useful on ARM as well, where an interrupt handler could be called when the stack isn't 8-byte aligned, which is what the extern "C" ABI expects.

Ideally, if an align_stack fn is called but it doesn't actually use the stack at all then the function could just skip aligning the stack.

ehuss

added the T-lang Relevant to the language subteam, which will review and decide on the RFC. label

Mar 26, 2024

The motivation section currently quotes the documentation of LLVM's stackrealign attribute, where an example is given of a function requiring 16-byte aligned stack due to its use of SSE but on a platform that otherwise requires only a 4-byte aligned stack.

However:

  1. If compiled for an SSE enabled target, perhaps all functions should have 16-byte aligned stacks?

  2. If that's too wasteful, perhaps all functions that utilise SSE operations can automatically realign their stack to 16-byte without having to be annotated (albeit perhaps this would have to be implemented in LLVM as rustc may not know whether SSE will be used)?

In any case, this would appear to be a requirement irrespective of the calling code, whether from elsewhere in Rust or from a foreign language/compiler? Indeed, it would appear to be a requirement irrespective of the ABI (extern "C" or not)? (Incidentally it's not clear to me how LLVM discovers what alignment the stack of such annotated functions should have, given that it's not specified in the attribute?)

Then in the guide level explanation section, an entirely different motivation appears to be given: "cases where your code is called from a thread or a binary compiled with another compiler, that uses different aligmnet and thus lead to a corruption". Admittedly this is far from my area of expertise, but I'm struggling to understand exactly what this means and why LLVM's stackrealign is the correct solution? Perhaps some more detail could help to elaborate.

In particular, what might be emitted by the foreign compiler that causes a problem with the code currently emitted by rustc, and in what circumstances does that happen?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK