Long time ago Rust used segmented stack (split stack), but switched to continuous stack around 2013. I am now working on ARM Cortex-M baremetal targets and trying to use segmented stack to prevent stack overflow. I would like to know how to let the current Rust compiler compile functions with segmented stack.
My understanding:
-
rustc
needs to emit the LLVM attributesplit-stack
to the compiled functions. - Currently we have no
rustc
option that controls this behavior. Related discussion here. - I will need to modify the compiler source code to add the
split-stack
attribute to the generated LLVM IR.
What I have done:
- Patched LLVM to emit the segmented stack function prologue for my embedded baremetal target.
- Wrote a runtime to support
__morestack
call. - Tested the LLVM patch and the runtime implementation by some test code written in C compiled with Clang (with
-fsplit-stack
option turned on). - Built
rustc
from source with my patched LLVM and linked it torustup toolchain
.
It seems that the only missing piece in the puzzle is to let rustc
emit the split-stack
attribute. Could someone please point me to the source file that is responsible for picking LLVM attributes for functions? Thanks!