libraw1394 struct layouts, i386 vs. x86_64

Paul Moore pcmoore at umich.edu
Wed Jan 7 14:11:14 EST 2009


On Wednesday 07 January 2009 1:22:10 pm Michael ODonnell wrote:
> When I added debug code to the library to dump the sizes and offsets of
> the various structure members when built for 32bit and 64bit they're
> different in ways that don't surprise me.  For example, in this sort
> of situation:
>
>    struct x {
>        __u32 x1;
>        __u32 x2;
>        __u32 x3;
>        __u64 x4;
>    };
>
> ...x4 ends up at offset 12 (being sizeof(int) times 3) when compiled for
> 32bit but it ends up automatically padded out to offset 16 when compiled
> for 64 bit.  I have been able to get the relevant section of library
> code to work by padding out some structs with extra dummy members such
> that the various members are nudged into positions that agree with the
> layouts expected by the kernel's raw1394 module, but that sort of b0rken
> hackery is not, of course, how I want to solve this.
>
> I've been looking for something like a magic compiler switch to force
> the desired 64bit-style alignments to our 32bit builds - anybody know
> what the trick is in this case?

I haven't used this trick in a while, but I know of a few compilers that 
support a structure packing pragma that can be used to control how the 
structure is packed/padded.  Googling "gcc pragma pack" yielded the following 
link which seems to explain it fairly well.

 * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html

-Paul


More information about the gnhlug-discuss mailing list