struct align on 8 byte boundary for gcc

struct align on 8 byte boundary for gcc

Post by kjackson1.. » Sun, 04 Nov 2001 05:59:43



I was wondering if there was a compiler flag for gcc that set all
struct alignment on an 8 byte boundary....

I have an application that we are now porting to Linux, and we're
running into this issue with byte alignment.  I did a search on
Google, and I found info pointing me to the "attribute" tag that will
set alignment on a struct-by-struct basis, but I was wondering if
there was a general flag that would do the same thing....

I also found the -align-code flag, but this only seems to align the
code, and not the structures.

Is there such a flag, or do I need to really set the alignment per
structure?

Thanks,

Kevin

 
 
 

struct align on 8 byte boundary for gcc

Post by Phil Edwar » Sun, 04 Nov 2001 08:05:43



> I was wondering if there was a compiler flag for gcc that set all
> struct alignment on an 8 byte boundary....

Hit the online manual at gcc.gnu.org/onlinedocs/ and search for something
like "stack preferred boundary" or some such.

Luck++;
Phil

--
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and* the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

 
 
 

struct align on 8 byte boundary for gcc

Post by Andrew Giert » Sun, 04 Nov 2001 10:00:13


 kjackson1997> I was wondering if there was a compiler flag for gcc
 kjackson1997> that set all struct alignment on an 8 byte boundary....

why, exactly?

Do you want it to use 8-byte alignment even when it doesn't need to?
Are you concerned about performance, or are you trying to get
layout-compatibility with some other architecture?

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

struct align on 8 byte boundary for gcc

Post by Andrew Giert » Sun, 04 Nov 2001 10:02:17


 Phil> Hit the online manual at gcc.gnu.org/onlinedocs/ and search for
 Phil> something like "stack preferred boundary" or some such.

the default _stack_ alignment for gcc on x86 is actually 16 bytes....

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

struct align on 8 byte boundary for gcc

Post by Juergen Hein » Sun, 04 Nov 2001 11:37:45




>> I was wondering if there was a compiler flag for gcc that set all
>> struct alignment on an 8 byte boundary....

> Hit the online manual at gcc.gnu.org/onlinedocs/ and search for something
> like "stack preferred boundary" or some such.

[-]
Search for -malign ...

-malign-int
-malign-float
-malign-double

... yet if what you want is to align *all* types on an 8 byte boundary,
then you're out of luck (at least I'm pretty sure) as even ...
__attribute__ (( aligned(8) ));
... says only what it should do, not what it actually does 8-}

One word of warning - using those options can cause problems and
applications can stop working; been there, done that.

If you really need it though then you can do something like this ...

struct s {
 union {
   double to8;
   char     c;
 } u1;
 union {
   double to8;
   short    h;
 } u2;

Quote:};

... yet of course this becomes unwieldy pretty quick.

Cheers,
Juergen

--
\ Real name     : Juergen Heinzl                \       no flames      /

 
 
 

struct align on 8 byte boundary for gcc

Post by Phil Edwar » Thu, 08 Nov 2001 07:34:36





> >> I was wondering if there was a compiler flag for gcc that set all
> >> struct alignment on an 8 byte boundary....

> > Hit the online manual at gcc.gnu.org/onlinedocs/ and search for something
> > like "stack preferred boundary" or some such.
> [-]
> Search for -malign ...

> -malign-int
> -malign-float
> -malign-double

Those, plus a few more.  I know "-mpreferred-stack-boundary=N" can have
useful and interesting effects.

Luck++;
Phil

--
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and* the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

 
 
 

1. Byte align structs in gcc?

I need to read binary files written in DOS - I'd like to ust fread the
structs, the way I do in DOS, but alas, in gcc aligns stuff on a
word (32 bit) boundary, not a byte boundary.  I've read the FAQ, and I'm
grabbing more docs on gcc (man page doesn't discuss it), but is there a
way to force gcc to byte align structures in memory?  You can force BC 3.1
to do so...  I figure gcc ought to be able to!

Thanks in advance...

--
Greg Herlein
Vallejo, CA

2. How to get GCC to link in global constructors under Solaris 2.3?

3. help - byte aligned vs. word aligned structures using gcc...

4. User Access to a Hard Drive Partition

5. hrtime_t not aligned on an 8 byte boundary.

6. KDE icons licence

7. Have to byte align structs but how!?

8. Sound Blaster Live!

9. Problem with struct members (does gcc align it automatically ?)

10. 2.5.45: gcc 3.2 aligns everything to 16 bytes when I compile for 486

11. 4 bytes align with gcc

12. mtrr: base(0xf8000000) is not aligned on a size(0x180000) boundary

13. Partition 0 not aligned on cylinder boundary