Stream: cranelift

Topic: Is there a way to manually manage the stack pointer?


view this post on Zulip Bley (Jun 20 2025 at 13:52):

Hello,
I was wondering if there was any way of manually manipulating the stack pointer, I know that doing so is known to be a nice foot-gun but my use case is a bit strange and the current way the stack works doesn't seem to let me fulfill my use case...

To be less mysterious, I'm currently writing a tool that takes some user-compiled code and I execute a subset of x86's instruction with cranelift, but I'm a bit stuck on how to encode any sub rsp, 8 while preserving the original code's flow of execution in a cranelift-way

view this post on Zulip bjorn3 (Jun 20 2025 at 14:53):

No, doing so would break the register allocator. The register allocator is allowed to insert stack accesses at basically any point. What you probably want to do instead is to pass and return the "guest" stack pointer as a regular argument.


Last updated: Dec 06 2025 at 07:03 UTC