1

I'm trying to modify llvm X86 backend to use rsp to locate/index local variables rather than rbp. The problem is that the offset between local variables and rsp is not fixed, so I have to calculate it by myself. It's easy to handle it if rsp's location was modified by these instructions as follows:

push 
pop
sub rsp, $immediate

In these situations, I can know the offset at compile-time. But nowadays I get stuck in a problem. I find that rsp is not only modified by these instructions mentioned before. For example:

lstr = (char *)alloca(strlen(ss) + 1);

This instruction will modify rsp like this and I can't know the offset at compile-time.

sub rsp, $register

Is it possible or not to use llvm to generate execute file which using stack pointer to locate local variables?

ys z
  • 71
  • 1
  • 3

1 Answers1

3

Short answer: no. There are many cases when stack pointer value may change in "non-constant way". Examples include VLAs (either direct or via alloca() calls), variadic functions, etc. Also note that in some cases the stack could be realigned dynamically as well.

Anton Korobeynikov
  • 9,074
  • 25
  • 28