public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/8054: Object layout: excess padding bytes
@ 2002-09-26 3:26 grigory
0 siblings, 0 replies; only message in thread
From: grigory @ 2002-09-26 3:26 UTC (permalink / raw)
To: gcc-gnats
>Number: 8054
>Category: c++
>Synopsis: Object layout: excess padding bytes
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Sep 26 03:26:07 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Grigory Zagorodnev
>Release: 3.2
>Organization:
>Environment:
IA-32 Red Hat Linux
IA-64 Red Hat Linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 (Red Hat Linux Rawhide 3.2-1)
>Description:
For the given class (most_derived) G++ compiler gives wrong data layout.
Test-case
---------
struct base {
short m;
base() { m = 0x1111; };
};
struct derived: virtual base {
};
struct most_derived: derived {
short m;
most_derived() { m = 0x2222; };
};
#include <stdio.h>
int main() // Run-time checking
{
most_derived obj;
if( ((size_t) &(((base *)&obj)->m) - (size_t) &obj) != sizeof(void *) + sizeof(obj.m) ){
puts("Failed");
return 1;
}
puts("Passed");
return 0;
}
Layout
------
According to the C++ ABI, the generalized data layout of class 'most_derived' should be:
[0] Virtual table entry pointer
[x] most_derived::m
[y] base::m
Where offset 'x' is equal to size of pointer, and 'y' = x + sizeof(most_derived::m).
For ia32 architecture, the expected layout is:
[0] Virtual table entry pointer
[4] most_derived::m
[6] base::m
However, G++ compiler gives different layout:
[0] Virtual table entry pointer
[4] most_derived::m
[8] base::m
I.e. g++ emits extra padding bytes after most_derived::m, thus breaking the ABI rules.
There is a class layout obtained by "g++ -fdump-class-hierarchy ...":
Class most_derived
size=12 align=4
most_derived (0x402222c0) 0
vptridx=0 vptr=((&most_derived::_ZTV12most_derived) + 12)
derived (0x40222300) 0 nearly-empty
primary-for most_derived (0x402222c0)
subvttidx=4
base (0x40222340) 8 virtual canonical
vbaseoffset=-12
>How-To-Repeat:
You can run listed test-case for run-time validation.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-09-26 10:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-26 3:26 c++/8054: Object layout: excess padding bytes grigory
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).