[LLVMdev] Controlling the stack layout

Nick Johnson npjohnso at cs.princeton.edu
Sun Dec 28 08:31:22 PST 2008


> 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
>

Take a look at the register allocators, each of which is implemented
as a MachineFunctionPass.  These are responsible for assigning stack
slots, and it shouldn't be too hard to modify them to reserve some
stack slots.

Also, I'd recommend that you consider the prevalence of this language
specific information, and re-evaluate whether you want to modify the
stack frame at all.  Do you expect *every* function will need it, or
*at most* every function will need it?  Could this information also be
encoded into a per-function local variable?  Could your compiler
generate code to maintain a separate stack for such information?

Also, out of curiosity: are you working on something like Java
security contexts?  Or perhaps something like ProPolice canary values?

-- 
Nick Johnson



More information about the llvm-dev mailing list