public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* question on class layout with virtual base classes
@ 2004-08-31 19:55 Yan Liu
  2004-09-01 15:27 ` Giovanni Bajo
  0 siblings, 1 reply; 2+ messages in thread
From: Yan Liu @ 2004-08-31 19:55 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 2582 bytes --]





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;}

g++ 3.3's information is:
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada
--disable-checking --libdir=/usr/lib --enable-libgcj
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit
--host=powerpc-suse-linux --build=powerpc-suse-linux
--target=powerpc-suse-linux --enable-targets=powerpc64-suse-linux
--enable-biarch
Thread model: posix
gcc version 3.3.3 (SuSE Linux)
g++3.4's information is:
 Configured with: ../gcc/configure
--prefix=/.../torolab.ibm.com/fs/projects/vabld/run/gcc/linux_ppc/3.4-dev
--enable-languages=c,c++,f77,objc --enable-altivec --enable-shared
powerpc-suse-linux
Thread model: posix
gcc version 3.4.0 20040212 (prerelease)

g++ 3.5's information is:
Configured with: /private/var/tmp/gcc/gcc-1765.obj~1/src/configure
--disable-checking --prefix=/usr --disable-libmudflap --mandir=/share/man
--enable-languages=c,objc,c++ --disable-libada
--program-transform-name=/^[cg][^+.-]*$/s/$/-3.5/
--with-gxx-include-dir=/include/gcc/darwin/3.5/c++
--build=powerpc-apple-darwin --host=powerpc-apple-darwin
--target=powerpc-apple-darwin
Thread model: posix
gcc version 3.5.0-tree-ssa 20040321 (merged 20040529) (Apple Computer, Inc.
build 1765)

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)

For the virtual base class A in the class F's layout, I thought tail
padding rule should only apply to non-virtual base classes. Before mapping
the virtual base class A, the current class size should be increased to the
mutiplication of alignment ( which is 4 at this moment), and A should be
put at offset 12 rather at offset 10.

I understant that C++ ABI does not explicitly specify the tail padding
rule. I would like to take this opportunity to understand  the tail padding
rules and empty base class mapping strategies you are using.

Your kind help is highly appreciated. Thanks.

Yan Liu
 email: yanliu@ca.ibm.com

[-- Attachment #2: temp4.g++35.class --]
[-- Type: application/octet-stream, Size: 2200 bytes --]

Class A
   size=1 align=1
   base size=1 base align=1
A (0x41032040) 0

Vtable for B
B::_ZTV1B: 3u entries
0     4u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for B
B::_ZTT1B: 1u entries
0     (const void*)((void*)((&B::_ZTV1B) + 12u))

Class B
   size=8 align=4
   base size=4 base align=4
B (0x41032180) 0 nearly-empty
    vptridx=0u vptr=((&B::_ZTV1B) + 12u)
  A (0x410321c0) 4 virtual
      vbaseoffset=-0x0000000000000000c

Vtable for C
C::_ZTV1C: 4u entries
0     8u
4     0u
8     (int (*)(...))(&_ZTI1C)
12    C::f

Construction vtable for B (0x41032500 instance) in C
C::_ZTC1C0_1B: 3u entries
0     8u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for C
C::_ZTT1C: 2u entries
0     (const void*)((void*)((&C::_ZTV1C) + 12u))
4     (const void*)((void*)((&C::_ZTC1C0_1B) + 12u))

Class C
   size=12 align=4
   base size=8 base align=4
C (0x410324c0) 0
    vptridx=0u vptr=((&C::_ZTV1C) + 12u)
  B (0x41032500) 0 nearly-empty
      primary-for C (0x410324c0)
      subvttidx=4u
    A (0x41032540) 8 virtual
        vbaseoffset=-0x0000000000000000c

Class D
   size=1 align=1
   base size=1 base align=1
D (0x41032880) 0

Class E
   size=4 align=4
   base size=4 base align=4
E (0x41032980) 0

Vtable for F
F::_ZTV1F: 5u entries
0     12u
4     10u
8     0u
12    (int (*)(...))(&_ZTI1F)
16    F::f

Construction vtable for C (0x41032a80 instance) in F
F::_ZTC1F0_1C: 4u entries
0     10u
4     0u
8     (int (*)(...))(&_ZTI1C)
12    C::f

Construction vtable for B (0x41032ac0 instance) in F
F::_ZTC1F0_1B: 3u entries
0     10u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for F
F::_ZTT1F: 3u entries
0     (const void*)((void*)((&F::_ZTV1F) + 16u))
4     (const void*)((void*)((&F::_ZTC1F0_1C) + 12u))
8     (const void*)((void*)((&F::_ZTC1F0_1B) + 12u))

Class F
   size=16 align=4
   base size=10 base align=4
F (0x41032a40) 0
    vptridx=0u vptr=((&F::_ZTV1F) + 16u)
  C (0x41032a80) 0
      primary-for F (0x41032a40)
      subvttidx=4u
    B (0x41032ac0) 0 nearly-empty
        primary-for C (0x41032a80)
        subvttidx=8u
      A (0x41032b00) 10 virtual
          vbaseoffset=-0x0000000000000000c
  E (0x41032b40) 12 virtual
      vbaseoffset=-0x00000000000000010
  D (0x41032b80) 8


[-- Attachment #3: temp4.g++33.class --]
[-- Type: application/octet-stream, Size: 1744 bytes --]

Class A
   size=1 align=1
A (0x40673cc0) 0

Vtable for B
B::_ZTV1B: 3 entries
0     4
4     0
8     &_ZTI1B

VTT for B
B::_ZTT1B: 1 entries
0     ((&B::_ZTV1B) + 12)

Class B
   size=8 align=4
B (0x40673e40) 0 nearly-empty
    vptridx=0 vptr=((&B::_ZTV1B) + 12)
  A (0x40673e80) 4 virtual canonical
      vbaseoffset=-12

Vtable for C
C::_ZTV1C: 4 entries
0     8
4     0
8     &_ZTI1C
12    C::f()

Construction vtable for B (0x40675380 instance) in C
C::_ZTC1C0_1B: 3 entries
0     8
4     0
8     &_ZTI1B

VTT for C
C::_ZTT1C: 2 entries
0     ((&C::_ZTV1C) + 12)
4     ((&C::_ZTC1C0_1B) + 12)

Class C
   size=12 align=4
C (0x40675340) 0
    vptridx=0 vptr=((&C::_ZTV1C) + 12)
  B (0x40675380) 0 nearly-empty
      primary-for C (0x40675340)
      subvttidx=4
    A (0x406753c0) 8 virtual canonical
        vbaseoffset=-12

Class D
   size=1 align=1
D (0x40675940) 0

Class E
   size=4 align=4
E (0x40675a80) 0

Vtable for F
F::_ZTV1F: 5 entries
0     16
4     12
8     0
12    &_ZTI1F
16    F::f()

Construction vtable for C (0x40675bc0 instance) in F
F::_ZTC1F0_1C: 4 entries
0     12
4     0
8     &_ZTI1C
12    C::f()

Construction vtable for B (0x40675c00 instance) in F
F::_ZTC1F0_1B: 3 entries
0     12
4     0
8     &_ZTI1B

VTT for F
F::_ZTT1F: 3 entries
0     ((&F::_ZTV1F) + 16)
4     ((&F::_ZTC1F0_1C) + 12)
8     ((&F::_ZTC1F0_1B) + 12)

Class F
   size=20 align=4
F (0x40675b80) 0
    vptridx=0 vptr=((&F::_ZTV1F) + 16)
  C (0x40675bc0) 0
      primary-for F (0x40675b80)
      subvttidx=4
    B (0x40675c00) 0 nearly-empty
        primary-for C (0x40675bc0)
        subvttidx=8
      A (0x40675c40) 12 virtual canonical
          vbaseoffset=-12
  E (0x40675c80) 16 virtual canonical
      vbaseoffset=-16
  D (0x40675cc0) 8


[-- Attachment #4: temp4.C.g++34_32.class --]
[-- Type: application/octet-stream, Size: 2200 bytes --]

Class A
   size=1 align=1
   base size=1 base align=1
A (0x4013ff80) 0

Vtable for B
B::_ZTV1B: 3u entries
0     4u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for B
B::_ZTT1B: 1u entries
0     (const void*)((void*)((&B::_ZTV1B) + 12u))

Class B
   size=8 align=4
   base size=4 base align=4
B (0x40140280) 0 nearly-empty
    vptridx=0u vptr=((&B::_ZTV1B) + 12u)
  A (0x401402c0) 4 virtual
      vbaseoffset=-0x0000000000000000c

Vtable for C
C::_ZTV1C: 4u entries
0     8u
4     0u
8     (int (*)(...))(&_ZTI1C)
12    C::f

Construction vtable for B (0x401407c0 instance) in C
C::_ZTC1C0_1B: 3u entries
0     8u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for C
C::_ZTT1C: 2u entries
0     (const void*)((void*)((&C::_ZTV1C) + 12u))
4     (const void*)((void*)((&C::_ZTC1C0_1B) + 12u))

Class C
   size=12 align=4
   base size=8 base align=4
C (0x40140780) 0
    vptridx=0u vptr=((&C::_ZTV1C) + 12u)
  B (0x401407c0) 0 nearly-empty
      primary-for C (0x40140780)
      subvttidx=4u
    A (0x40140800) 8 virtual
        vbaseoffset=-0x0000000000000000c

Class D
   size=1 align=1
   base size=1 base align=1
D (0x40140d40) 0

Class E
   size=1 align=1
   base size=1 base align=1
E (0x4014b000) 0

Vtable for F
F::_ZTV1F: 5u entries
0     11u
4     10u
8     0u
12    (int (*)(...))(&_ZTI1F)
16    F::f

Construction vtable for C (0x4014b2c0 instance) in F
F::_ZTC1F0_1C: 4u entries
0     10u
4     0u
8     (int (*)(...))(&_ZTI1C)
12    C::f

Construction vtable for B (0x4014b300 instance) in F
F::_ZTC1F0_1B: 3u entries
0     10u
4     0u
8     (int (*)(...))(&_ZTI1B)

VTT for F
F::_ZTT1F: 3u entries
0     (const void*)((void*)((&F::_ZTV1F) + 16u))
4     (const void*)((void*)((&F::_ZTC1F0_1C) + 12u))
8     (const void*)((void*)((&F::_ZTC1F0_1B) + 12u))

Class F
   size=12 align=4
   base size=10 base align=4
F (0x4014b280) 0
    vptridx=0u vptr=((&F::_ZTV1F) + 16u)
  C (0x4014b2c0) 0
      primary-for F (0x4014b280)
      subvttidx=4u
    B (0x4014b300) 0 nearly-empty
        primary-for C (0x4014b2c0)
        subvttidx=8u
      A (0x4014b340) 10 virtual
          vbaseoffset=-0x0000000000000000c
  E (0x4014b380) 11 virtual
      vbaseoffset=-0x00000000000000010
  D (0x4014b3c0) 8


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: question on class layout with virtual base classes
  2004-08-31 19:55 question on class layout with virtual base classes Yan Liu
@ 2004-09-01 15:27 ` Giovanni Bajo
  0 siblings, 0 replies; 2+ messages in thread
From: Giovanni Bajo @ 2004-09-01 15:27 UTC (permalink / raw)
  To: Yan Liu; +Cc: gcc

Yan Liu wrote:

> I found that g++ 3.3, 3.4 and 3.5 have different class layout for the
> following testcase:

I can't help you myself understanding the ABI issue, but would you please
file a bugreport in Bugzilla about this bug? The same information provided
in this mail are sufficient.

Thanks
Giovanni Bajo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-09-01 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31 19:55 question on class layout with virtual base classes Yan Liu
2004-09-01 15:27 ` Giovanni Bajo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).