[LLVMdev] different layout of structs for llc vs. llvm-gcc

Torvald Riegel torvald at se.inf.tu-dresden.de
Tue Jul 13 10:09:20 PDT 2010


attached is small program in which padding inside a struct is lost when using 
llc, but is not lost when using llvm-gcc or gcc. In particular, padding is 
missing after codegen with llc (see (1) below, LLVM 2.7, Linux x86_64):
typedef struct {
    unsigned txnal;
    char padding[64];
    unsigned nontxnal;
} Data;
Data data;

I thought that the layout of structs was supposed to be preserved (wrong 
assumption?). Otherwise, any ideas why this happens?


llvm-gcc -emit-llvm -c -o padtest.bc padtest.c; llvm-ld -link-as-library 
padtest.bc -o padtest2.bc; llc padtest2.bc -o padtest.s; gcc padtest.s  -
lpthread -o padtestllc

0000000000400640 <updater>:
  400640:       89 3d 9a 04 20 00       mov    %edi,0x20049a(%rip)        # 
600ae0 <data.0>
  400646:       89 3d 98 04 20 00       mov    %edi,0x200498(%rip)        # 
600ae4 <data.2>

padtest2.bc (input to llc) still has the padding in the struct. Also note that 
the padding is not removed if the addresses of data's fields are printed.

llvm-gcc padtest.c -o padtesto3 -O3 -lpthread

00000000004005d0 <updater>:
  4005d0:       89 3d ea 04 20 00       mov    %edi,0x2004ea(%rip)        # 
600ac0 <data>
  4005d6:       89 3d 28 05 20 00       mov    %edi,0x200528(%rip)        # 
600b04 <data+0x44>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: padtest.c
Type: text/x-csrc
Size: 947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100713/ca643219/attachment.c>

More information about the llvm-dev mailing list