Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

GCC 4.7.0 breaks __attribute__((packed)) behavior on... (Developers)

posted by Rugxulo Homepage, Usono, 05.09.2012, 11:26

> I don't want/have time for long philosophic discussion about portable code,
> different C compilers, why need packed structures, etc...

I know, me neither, just saying, things are more complicated than they seem. It's not necessarily clear cut. Maybe it's a bug, maybe not, dunno.

> I just giving a warning, that new gcc since ver 4.7.0 changed default
> bahavior of attribute packed (-mms-bitfields become default) that may
> affect older SW when recompiling. I see it as very serious change.

It was (partially) mentioned:

http://gcc.gnu.org/gcc-4.7/changes.html

"IA-32/x86-64
Windows mingw targets are using the -mms-bitfields option by default."

> I understand this was done for some reasons of compatability with M$ and/or
> 64bit stuff but I don't agree with this way.

But if they left it incompatible with MSVC, other people would complain. You can't please everybody, something had to change. (Though, again, this may indeed be a bug where "packed" should always be minimal, but I vaguely doubt it.)

> Attribute packed should be
> left to always pack the structure to minimum size without padding
> (otherwise I would't use this attribute at all) and they could introduce
> some new attribute ms_packed...

Just for reference, I found a few interesting tidbits in the manual (gcc.info):

= http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Warning-Options.html#Warning-Options
= http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Variable-Attributes.html#Variable-Attributes
= http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Struct...king-Pragmas.html#Structure_002dPacking-Pragmas
= http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Compatibility.html#Compatibility

"-Wpadded
Warn if padding is included in a structure, either to align an element of the structure or to align the whole structure. Sometimes when this happens it is possible to rearrange the fields of the structure to reduce the padding and so make the structure smaller." (does this warn you at all in this specific instance??)

"Note: The 4.1, 4.2 and 4.3 series of GCC ignore the packed attribute on bit-fields of type char. This has been fixed in GCC 4.4 but the change can lead to differences in the structure layout. See the documentation of -Wpacked-bitfield-compat for more information." (so a bug isn't impossible)

"6.36.5 i386 Variable Attributes

Two attributes are currently defined for i386 configurations: ms_struct and gcc_struct

ms_struct
gcc_struct
If packed is used on a structure, or if bit-fields are used it may be that the Microsoft ABI packs them differently than GCC would normally pack them. Particularly when moving packed data between functions compiled with GCC and the native Microsoft compiler (either via function call or as data in a file), it may be necessary to access either format."

"Some targets, e.g. i386 and powerpc, support the ms_struct #pragma which lays out a structure as the documented __attribute__ ((ms_struct)).

#pragma ms_struct on turns on the layout for structures declared.
#pragma ms_struct off turns off the layout for structures declared.
#pragma ms_struct reset goes back to the default layout."

So, you may? want to do something like this (untested):


#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) && defined(__MINGW32__)
#pragma ms_struct off
#endif

 

Complete thread:

Back to the forum
Board view  Mix view
22762 Postings in 2122 Threads, 402 registered users (1 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum