[cxx-abi-dev] question on the virtual base offset
Nathan Sidwell
nathan at codesourcery.com
Mon Sep 6 13:18:52 UTC 2004
Yan Liu wrote:
>
>
>
> I found that g++ 3.3, 3.4 and 3.5 have different class layout for the
> following testcase:
> struct A {char a;};
>
> struct B: virtual public A {};
>
> struct C:public B{
> int c;
> virtual void f() {};
> };
> struct D {
> char d;
> };
> struct E {int:3;};
> struct F: public C, virtual E, public D {
> char f1;
> virtual void f(){}
> };
> int main()
> {F f;}
>
> Attached files are the class and vft layout results with three g++
> compilers using -fdump-class-hierarchy option.
>
>
> (See attached file: temp4.g++35.class)(See attached file:
> temp4.g++33.class)(See attached file: temp4.C.g++34_32.class)
> According to the C++ ABI online document chapter 2.4
> (http://www.codesourcery.com/cxx-abi/abi.html). After mapping the virtual
> base class A while mapping of the most derived class F, the dsize(F)=11,
> size(F)=11, align(F)=4, and nvsize(E)=4, nvalign(E)=4. So, when mapping
> virtual base class E, the next available bits are at offset dsize(F)=11. E
> should be put at offset(F) which is the dsize(F) =11, and the final class
> size should be 12. To me, g++3.4 gives the most reasonable result, I don't
> understand why g++3.5 put E at offset 12, and the final class size is 16.
> Is it means that ABI has changed or just a gcc bug?
>
> Your kind help is highly appreciated. Thanks.
the layout 3.5 gives looks ok to me. E requires 4 byte alignment, so
cannot be at 11.
3.4 incorrectly packed the bitfield into a char.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan at codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the cxx-abi-dev
mailing list