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

Eli Friedman eli.friedman at gmail.com
Tue Jul 13 10:48:25 PDT 2010


On Tue, Jul 13, 2010 at 10:09 AM, Torvald Riegel
<torvald at se.inf.tu-dresden.de> wrote:
> Hi,
>
> 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?

It should be preserved in general; probably what's happening here is
that when you use llvm-ld, it assumes the variable data isn't used
outside of the file in question.  Therefore, it ends up splitting the
global into its respective members and eliminating the apparently
unused padding.  Passing -disable-internalize to llvm-ld or declaring
data as volatile should solve this.

-Eli




More information about the llvm-dev mailing list