When emitting llvm code (-emit-llvm), llvm-gcc generates a Target Data Layout of "e-p:32:32" for x86-pc-linux-gnu. This is insufficient for some programs as the defaults will use f64:64:64 whereas the correct alignment is f64:32:64. This causes a problem in accessing fields of structures that use double/long long.
Created attachment 696 [details] A simple program that produces the bug. This program is extracted (manually) from llvm-test/MultiSource/Olden/bh. It simply allocates and initializes a structure containing several fields. When the last field is initialized this causes LLI to corrupt memory because the StructureLayout returned an offset of 136 for the last field while llvm-gcc generated a malloc call for only 132 bytes. Subsequent operations result in a glibc malloc error. This doesn't happen in llc or jit because they update the target data for the specific target for which code is being generated.
Created attachment 697 [details] Equivalent llvm assembly for struct-size.c This is generated by llvm-gcc -S -emit-llvm struct-size.c -o ss.ll
Fixed, patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070305/045573.html