Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM disable the stack

Tags:

llvm

When compiling a language which uses heap allocated closures holding by-val or pointers to heap allocated arguments, how might one guarantee that LLVM doesn't generate code which uses the stack (and optionally use ebp/esp as another general-purpose register)?

The function may be running in a strand/microthread which doesn't have a C/traditional stack at all.


Edit

An article that might be relevant, but it doesn't say whether there is a guarantee LLVM won't try and consume stack.

http://nondot.org/sabre/LLVMNotes/ExplicitlyManagedStackFrames.txt


Edit 2

To be clear, I don't need the stack for regular calls because I can generate new closures with pointers to old closures so that the state is proper on returning from a call.

Think of this as just a linked stack.

like image 297
kvanbere Avatar asked May 08 '26 04:05

kvanbere


1 Answers

You would have to code your own backend. The existing x86/x64 backends will not be programmed to support this- stack use is basically mandatory for virtually all functions. You could lower alloca() instructions to your own pseudo-stack which is really on the heap. Not to mention you'd have to develop your own call stack, your own function calling ABIs, all of that nasty stuff. Even then, you're basically down to emulating a stack.

The only programming environments that do not provide a hardware stack and are still even somewhat useful are GPUs, realistically, and that's only because they offer so many available registers and each function is supposed to be very restricted. Only having register space available would cripple programs running on x86 or x64.

like image 168
Puppy Avatar answered May 10 '26 21:05

Puppy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!