Size difference in base class between GCC releases

2012-08-27 Thread Paul_Koning
I'm doing some checking of data structure layouts in different releases of our 
code -- which were produced by different releases of GCC (3.3.3 vs. 4.5.4).

One difference I'm seeing that is puzzling is in the handling of base classes.  
Specifically, the case where a base class has padding at the end to fill it out 
to a multiple of the alignment.

In GCC 3.3.3, when such a class is used as a base class, that padding is 
omitted, and the first derived class data member starts right after the last 
base class real (not pad) data member.  In GCC 4.5.4, the base class is used 
padding and all, the first derived class data member starts after the padding 
of the base class.

Which is correct?  Or are both correct?  This sort of thing is a potential 
cause of trouble if such a class is used as a container for persistent data.

paul



Re: Size difference in base class between GCC releases

2012-08-27 Thread Jonathan Wakely
On 27 August 2012 19:48, Paul_Koningwrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).

 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end to 
 fill it out to a multiple of the alignment.

 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the last 
 base class real (not pad) data member.  In GCC 4.5.4, the base class is used 
 padding and all, the first derived class data member starts after the padding 
 of the base class.

This depends on whether the base class is a POD or not.

According to a note in the Itanium C++ ABI the C++ standard requires
that compilers not overlay the tail padding in a POD (I don't know
off the top of my head where that is stated in the standard.)

 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.

GCC 3.4 and later conform to the Itanium C++ ABI, which specifies the
behaviour you're seeing as required by the C++ standard, so 4.5 is
correct.


Re: Size difference in base class between GCC releases

2012-08-27 Thread Paul_Koning

On Aug 27, 2012, at 3:33 PM, Jonathan Wakely wrote:

 On 27 August 2012 19:48, Paul_Koningwrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).
 
 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end 
 to fill it out to a multiple of the alignment.
 
 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the last 
 base class real (not pad) data member.  In GCC 4.5.4, the base class is used 
 padding and all, the first derived class data member starts after the 
 padding of the base class.
 
 This depends on whether the base class is a POD or not.
 
 According to a note in the Itanium C++ ABI the C++ standard requires
 that compilers not overlay the tail padding in a POD (I don't know
 off the top of my head where that is stated in the standard.)
 
 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.
 
 GCC 3.4 and later conform to the Itanium C++ ABI, which specifies the
 behaviour you're seeing as required by the C++ standard, so 4.5 is
 correct.

Interesting.  What if the base class is not a POD?  It doesn't seem to be, if I 
remember the definition of POD correctly.

paul



Re: Size difference in base class between GCC releases

2012-08-27 Thread Gabriel Dos Reis
On Mon, Aug 27, 2012 at 1:48 PM,  paul_kon...@dell.com wrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).

 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end to 
 fill it out to a multiple of the alignment.

 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the last 
 base class real (not pad) data member.  In GCC 4.5.4, the base class is used 
 padding and all, the first derived class data member starts after the padding 
 of the base class.

 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.

 paul


Is this message

 http://gcc.gnu.org/ml/gcc/2002-08/msg00874.html

relevant to your case?

-- Gaby


Re: Size difference in base class between GCC releases

2012-08-27 Thread Paul_Koning

On Aug 27, 2012, at 4:05 PM, Gabriel Dos Reis wrote:

 On Mon, Aug 27, 2012 at 1:48 PM,  paul_kon...@dell.com wrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).
 
 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end 
 to fill it out to a multiple of the alignment.
 
 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the last 
 base class real (not pad) data member.  In GCC 4.5.4, the base class is used 
 padding and all, the first derived class data member starts after the 
 padding of the base class.
 
 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.
 
paul
 
 
 Is this message
 
 http://gcc.gnu.org/ml/gcc/2002-08/msg00874.html
 
 relevant to your case?
 
 -- Gaby

Yes, that looks like the exact case.  And the mail thread seems to say that the 
3.3.3 behavior I'm seeing is what G++ was doing at that time, as was HP -- 
but not Intel.  So now we have it done differently in later compilers.

I know this is changing data structure layouts in our code; I don't know yet if 
that is a problem (i.e., if it applies to layouts used in persistent data or in 
protocol messages).  I assume there isn't some compiler switch I can use to 
control this behavior?

paul



Re: Size difference in base class between GCC releases

2012-08-27 Thread Gabriel Dos Reis
On Mon, Aug 27, 2012 at 3:16 PM,  paul_kon...@dell.com wrote:
 On Aug 27, 2012, at 4:05 PM, Gabriel Dos Reis wrote:

 On Mon, Aug 27, 2012 at 1:48 PM,  paul_kon...@dell.com wrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).

 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end 
 to fill it out to a multiple of the alignment.

 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the 
 last base class real (not pad) data member.  In GCC 4.5.4, the base class 
 is used padding and all, the first derived class data member starts after 
 the padding of the base class.

 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.

paul


 Is this message

 http://gcc.gnu.org/ml/gcc/2002-08/msg00874.html

 relevant to your case?

 -- Gaby

 Yes, that looks like the exact case.  And the mail thread seems to say that 
 the 3.3.3 behavior I'm seeing is what G++ was doing at that time, as was HP 
 -- but not Intel.  So now we have it done differently in later compilers.

Yes.


 I know this is changing data structure layouts in our code; I don't know yet 
 if that is a problem (i.e., if it applies to layouts used in persistent data 
 or in protocol messages).  I assume there isn't some compiler switch I can 
 use to control this behavior?


Normally, any changes like this is controlled by -fabi-version; you
can also get warnings
with -Wabi.  See the discussion at


http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wabi-168

if it is of any help.

-- Gaby


Re: Size difference in base class between GCC releases

2012-08-27 Thread Jonathan Wakely
On 27 August 2012 20:49 Paul Koning wrote:

 On Aug 27, 2012, at 3:33 PM, Jonathan Wakely wrote:

 On 27 August 2012 19:48, Paul_Koningwrote:
 I'm doing some checking of data structure layouts in different releases of 
 our code -- which were produced by different releases of GCC (3.3.3 vs. 
 4.5.4).

 One difference I'm seeing that is puzzling is in the handling of base 
 classes.  Specifically, the case where a base class has padding at the end 
 to fill it out to a multiple of the alignment.

 In GCC 3.3.3, when such a class is used as a base class, that padding is 
 omitted, and the first derived class data member starts right after the 
 last base class real (not pad) data member.  In GCC 4.5.4, the base class 
 is used padding and all, the first derived class data member starts after 
 the padding of the base class.

 This depends on whether the base class is a POD or not.

 According to a note in the Itanium C++ ABI the C++ standard requires
 that compilers not overlay the tail padding in a POD (I don't know
 off the top of my head where that is stated in the standard.)

 Which is correct?  Or are both correct?  This sort of thing is a potential 
 cause of trouble if such a class is used as a container for persistent data.

 GCC 3.4 and later conform to the Itanium C++ ABI, which specifies the
 behaviour you're seeing as required by the C++ standard, so 4.5 is
 correct.

 Interesting.  What if the base class is not a POD?  It doesn't seem to be, if 
 I remember the definition of POD correctly.

G++ 3.4 and later can, and will, reuse the tail padding in a non-POD.


Re: Size difference in base class between GCC releases

2012-08-27 Thread Jonathan Wakely
On 27 August 2012 21:16,  Paul Koning wrote:

 On Aug 27, 2012, at 4:05 PM, Gabriel Dos Reis wrote:

 Is this message

 http://gcc.gnu.org/ml/gcc/2002-08/msg00874.html

 relevant to your case?

 -- Gaby

 Yes, that looks like the exact case.  And the mail thread seems to say that 
 the 3.3.3 behavior I'm seeing is what G++ was doing at that time, as was HP 
 -- but not Intel.  So now we have it done differently in later compilers.

That mail is talking about reusing tail padding in non-PODs, and G++
still does that, i.e. this code compiles:

struct S1 {
   virtual void f();
   int i;
   char c1;
 };

 struct S2 : public S1 {
   char c2;
 };

const S2 s2{};

static_assert( (s2.c2 - s2.c1) == 1, Reused tail padding );

Please check whether the code you're looking at involves a POD base
class, because that would explain why G++ 4.5 doesn't reuse the tail
padding (I have no idea if 3.3 does or doesn't, but using
-fabi-version=1 to request the G++ 3.2 ABI doesn't seem to cause tail
padding in PODs to be reused.)