public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yan Liu <yanliu@ca.ibm.com>
To: gcc@gnu.org
Subject: question on class layout with virtual base classes
Date: Tue, 31 Aug 2004 19:55:00 -0000	[thread overview]
Message-ID: <OF9D7C1C0F.E69DCD53-ON85256F01.0067264F-85256F01.006AE804@ca.ibm.com> (raw)

[-- 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


             reply	other threads:[~2004-08-31 19:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-31 19:55 Yan Liu [this message]
2004-09-01 15:27 ` Giovanni Bajo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OF9D7C1C0F.E69DCD53-ON85256F01.0067264F-85256F01.006AE804@ca.ibm.com \
    --to=yanliu@ca.ibm.com \
    --cc=gcc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).