[LLVMdev] Controlling the stack layout

Bill Wendling isanbard at gmail.com
Mon Dec 29 15:15:07 PST 2008


On Dec 27, 2008, at 2:28 PM, Nicolas Geoffray wrote:

> Hi everyone,
>
> As a front-end developer, I'd like to add a language-specific
> information at a fixed location of each stack frame. The reason is  
> that
> I want to retrieve this information when dynamically walking the  
> stack.
>
> For example, X86 has the following stack layout for a function with  
> two
> arguments and two locals:
>
> 12(%ebp)    - second function parameter
> 8(%ebp)      - first function parameter
> 4(%ebp)      - old %EIP (the function's "return address")
> 0(%ebp)      - old %EBP (previous function's base pointer)
> -4(%ebp)     - first local variable
> -8(%ebp)     - second local variable
>
>
> I'd like to generate this layout:
>
> 12(%ebp)    - second function parameter
> 8(%ebp)      - first function parameter
> 4(%ebp)      - old %EIP (the function's "return address")
> 0(%ebp)      - old %EBP (previous function's base pointer)
> -4(%ebp)     - My language specific information
> -8(%ebp)     - first local variable
> -12(%ebp)   - second local variable
>
>
> Can I express this in LLVM without modifying llvm internals? I  
> looked at
> writing a machine function pass, but I can't register one when  
> JITting.
> Is the machine function pass the correct way of implementing this?
>
This might help. See how "stack protectors" is implemented here:

	lib/CodeGen/StackProtector.cpp

It places a special value at a specific place on the stack. You can  
use the same trick to put your own information on a set stack  
position. There's more to the code than just that .cpp file. It's done  
with intrinsics. You'll also need to check out the  
PrologEpilogInserter.cpp code.

-bw



More information about the llvm-dev mailing list