Implementing ALLOCA/ALLOCA_HYBRID
Currently the compiler assumes that frame size is constant at compile time.
For x86_64, stack pointer needs to be 16-bytes aligned before a function call. The compiler ensures this by:
-
rbp
is always 16-bytes aligned. - frame size is a multiple of 16-bytes (align up to 16-bytes if it is not, see
frame.rs
). - if any call argument is passed on stack, if necessary, push a padding value to stack so that
rsp
is still 16-bytes aligned after pushing call arguments. - restoring from an exception will set
rsp
fromrbp
and the constant frame size.
We can implement ALLOCA
by computing allocating size during compile time, and frame size is still a compile-time constant. However, the implementation of ALLOCA_HYBRID
will break this assumption. A straightforward solution is to make the alloca'd size always a multiple of 16-bytes (for alignment requirement), and record a current frame size somewhere (for restoring from exception) - this would keep most of the above unchanged. This issue tracks related discussion.