[LLVMdev] Dragonegg stack variables reorderings

Duncan Sands baldrick at free.fr
Thu Mar 15 06:42:03 PDT 2012


Hi Job,

On 15/03/12 13:56, Job Noorman wrote:
> I have noticed that dragonegg sometimes allocates stack objects in a different
> order than they were declared in the source file.
>
> I experienced this behavior when compiling RIPE
> (https://github.com/johnwilander/RIPE) in the function perform_attack.
> Unfortunately, I haven't been able to reproduce this in a minimal example.
>
> (Note that when compiling RIPE with GCC, the order of stack variables is
> preserved)

as far as I know reordering stack variables or placing arbitrary padding
between them is perfectly conformant with the C standard.  The LLVM optimizers
know this, so if you compile with optimization then code that relies on a
particular stack layout is liable to break even if the front-end outputs
everything in textual order.

> So, I have two questions about this behavior:
>   1) When exactly does dragonegg reorder stack variables?

I think this is probably due to stack variables being output lazily, i.e. when
first used.  For example, if you declare variables A and B but use B first then
probably B will get output to the LLVM IR first.

>   2) Is there a way to always keep the variables in declared order?

I guess I could arrange for them all to be output in one fell swoop at the start
of the function.  Why do you need this?

Ciao, Duncan.



More information about the llvm-dev mailing list