Structure alignment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Structure alignment

Manoel Teixeira

%FIRSTSTRU = type { i32,  double, i32, i8* }

struct  {
        int var1;
        double var2;
        int var3;
        char *var4;
}firstStru ;

Could someone help?
If, running a application in windows with MSVC,  I allocate a memmory buffer and call a LLVM
function with such buffer, there's a structure alignment problem.
If the LLVM function call a C function using the same buffer, it runs fine.
Any ideas?

Thanks,


Manoel Teixeira






 
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Structure alignment

Eli Friedman-2
On Mon, Jun 8, 2009 at 1:53 PM, Manoel Teixeira<[hidden email]> wrote:

>
> %FIRSTSTRU = type { i32,  double, i32, i8* }
>
> struct  {
>        int                             var1;
>        double                  var2;
>        int                             var3;
>        char    *var4;
> }firstStru ;
>
> Could someone help?
> If, running a application in windows with MSVC,  I allocate a memmory buffer and call a LLVM
> function with such buffer, there's a structure alignment problem.
> If the LLVM function call a C function using the same buffer, it runs fine.
> Any ideas?

You're probably passing in the wrong string to the TargetData; try
something like the following:
target datalayout =
"e-p:32:32:32-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-f80:32:32"

-Eli

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Structure alignment

Anton Korobeynikov-2
In reply to this post by Manoel Teixeira
Hello

> %FIRSTSTRU = type { i32,  double, i32, i8* }
>
> struct  {
>        int                             var1;
>        double                  var2;
>        int                             var3;
>        char    *var4;
> }firstStru ;
LLVM type is not equivalent to mentioned C struct type. You need to
insert padding field into LLVM type.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Structure alignment

Duncan Sands
In reply to this post by Manoel Teixeira
Manoel Teixeira wrote:

> %FIRSTSTRU = type { i32,  double, i32, i8* }
>
> struct  {
> int var1;
> double var2;
> int var3;
> char *var4;
> }firstStru ;
>
> Could someone help?
> If, running a application in windows with MSVC,  I allocate a memmory buffer and call a LLVM
> function with such buffer, there's a structure alignment problem.
> If the LLVM function call a C function using the same buffer, it runs fine.
> Any ideas?

I think it's best if you send the bitcode produced by llvm-gcc/clang.

Ciao,

Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev