[LLVMdev] Data layout of structs

Óscar Fuentes ofv at wanadoo.es
Fri Feb 4 07:00:54 PST 2011


Thomas Ströder <stroeder at informatik.rwth-aachen.de> writes:

> target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
> target triple = "x86_64-linux-gnu"

[snip]

> Now my problem is as follows. The pointer %4 (pointing to the second
> field in the list element) is calculated by going 8 byte further in
> memory. However, i32 only has a size of 4 byte. What is the reason
> for the struct having the data layout of two times 8 bytes instead
> of having 4 bytes for the integer and 8 bytes for the pointer to the
> next element?

See the datalayout string:

p:64:64:64

that means that pointers are aligned to 64 bit boundaries. Your struct
ends being like this:

  offset bytes 0-3 : int data member
  offset bytes 4-7 : padding
  offset bytes 8-15: pointer data member

> Is there a general rule for the data layout of structs in LLVM?

LLVM follows the platform's C ABI, in this case x86_64-linux.
That's hard-coded. Don't be lured by Module::setDataLayout.




More information about the llvm-dev mailing list