[cxx-abi-dev] Question about tail padding

Nathan Sidwell nathan at acm.org
Fri Aug 16 13:38:50 UTC 2002


scott douglass wrote:

> >dsize for a class is measured in bytes, so bit-fields shouldn't make a
> >difference.
> 
> I don't think the implicit copy assignment for B can copy all dsize bytes in this case:
> 
> struct B {
>     virtual void f(); // B is non-POD
>     int bf1:3;
> };
> 
> struct D : B {
>     D();
>     int bf2:3;
> };
> 
> Won't bf1 & bf2 be in the same byte?  And doing this:
no, they will be in different bytes. dsize (B) is 5, D::bf2 can be inserted
into the int allocation unit that starts at offset 4, and it will be at bit
8 of that unit (i.e. byte offset 5 from the base).


> A related thought:  I think constructors, including copy constructors, don't have to worrry about preseving tail padding because after they finish none of the derived fields are valid anyway.

Ah, I had thought the answer was no, they must not touch the tail padding, because
an (already constructed) virtual base might be in that padding. However the ABI
doc is unclear on this too. One part implies that virtual bases may be in
tail padding, but the algorithm does not place them there.
	struct A { char c;
		   A () :c(5) {}};
	struct B { virtual void f ();
		   int i;
		   char c; };
	struct D  : B, virtual A {
		};
GCC makes it 16, with the A base allocated at offset 12. (When A is non-virtual,
the size is 12).

from the ABI doc, 2.1
	nvsize(O): the non-virtual size of an object, which intuitively is dsize(O)
	minus the size of virtual bases. It is always equal to dsize(O) for types
	without virtual bases.
this implies that nvsize (B) should be 9. and A allocated there.
but, 2.4 II says
	After all such components have been allocated, set nvalign(C) = align(C), and
	set nvsize(C) to the least multiple of nvalign(C) that is greater than or
	equal to dsize(C). The values of nvalign(C) and nvsize(C) will not change
	during virtual base allocation. 
which would make nvsize 12.

This is a different problem to the one Mark brought up.
The spec is inconsistent, GCC does one thing, what do HP & intel do?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
           The voices in my head told me to say this
nathan at acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan at cs.bris.ac.uk



More information about the cxx-abi-dev mailing list