Chapter 6. C++ Class Representations

6.1. C++ Data Representation

Support for the C++ language shall be as specified in Itanium™ C++ ABI.

Note: This document, although containing a few architecture specific matters, is written as a generic specification, to be usable by C++ implementations on a variety of architectures.

This section provides additional information to supplement Itanium™ C++ ABI. Many of the definitions in that document are made in terms of C++. This section provides addition explanations using C terms to avoid self-referential problems.

6.1.1. Class Representation

An object file generated by the compilation process for a C++ program shall contain several closely related internal objects, or Class Components, to represent each C++ Class. Such objects are not a visible part of the source code. Table 6-1 describes these Class Components at a high level.

Table 6-1. Class Components

ObjectContains
Class DataAll non-static Class members
Virtual TableInformation needed to dispatch virtual functions, access virtual base class subobjects and to access the RTTI information
RTTIRun-Time Type Information used by the typeid and dynamic_cast operators, and exception handlers
Typeinfo NameString representation of Class name
Construction Virtual TableInformation needed during construction and destruction of Classes with non-trivial inheritance relationships.
VTTA table of virtual table pointers which holds the addresses of construction and non-construction virtual tables.

6.1.1.1. Virtual Table

Virtual tables are specified in Section 2.5.3 of Itanium™ C++ ABI.

Of the various categories of virtual table described in that specification, Category 1 (Leaf) is further described in Figure 6-1 and Category 2 (Non-virtual bases only) is further described in Figure 6-2. LSB conforming systems shall support these categories.

struct {
        ptrdiff_t       baseobject;
        const char      *typeinfo;
        fptr            virtfuncs[0];
};

Figure 6-1. Category 1 Virtual Table

struct {
        unsigned long   vcalloffset;
        ptrdiff_t       baseobject;
        const char      *typeinfo;
        fptr            virtfuncs[0];
};

Figure 6-2. Category 2 Virtual Table

This specification describes requirements for virtual tables of C++ classes using tables of the following form:

Table 6-2. Primary vtable for K (example)

Base Offset0
Virtual Base Offset0
RTTItypeinfo for K
vfunc[0]:K::~K()
vfunc[1]:K::~K()
vfunc[2]:K::m1(int*)
vfunc[3]:X::m2()
vfunc[4]:__cxa_pure_virtual()
vfunc[5]:NULL or X::m4(int)

Each row starting from 'vfunc[i]:' refers to a vtable entry 'vfunc[i]' of a class K, which is an entry for a virtual function A::m, where A is a base class of the class K as described in the Itanium™ C++ ABI. This specification requires implementations to interpret the vtable entry information in the following way:

  1. A conforming implementation shall contain a vtable of the class K in the specified shared library;

  2. The corresponding entry of this vtable 'vfunc[i]' shall be an entry for the virtual function A::m;

  3. If the second column of the row contains __cxa_pure_virtual() the corresponding vtable entry of a LSB-conforming implementation shall contain __cxa_pure_virtual() or 'Y::m', where Y is the class K, the class A or a base class of the class K derived from the class A. [1]

  4. If the second column of the row contains 'X::m' the corresponding vtable entry of a LSB-conforming implementation shall contain 'Y::m', where Y is the class K, the class X or a base class of the class K derived from the class X.

  5. If the second column of the row contains 'NULL or X::m' the corresponding vtable entry of a LSB-conforming implementation shall contain NULL or 'Y::m', where Y is the class K, the class X or a base class of the class K derived from the class X. [2]

An application may use any non-pure virtual function specified in this specification, and can expect the specified behavior irrespective of which particular method implements this functionality. An application may not use inline virtual functions at the binary level since its vtable entry may be NULL.

6.1.1.2. Run-Time Type Information

Each type used in a C++ program has a data structure associated with it that provide information about the type which is used at runtime. This Run Time Type Information (RTTI) is defined in section 2.9.5 in Itanium™ C++ ABI. Additional details about the layout of this data is provided here.

struct {
       void      *basevtable;
       char      *name;
};

Figure 6-3. Run-Time Type Information Prefix

struct {
       void      *basevtable;
       char      *name;
       void      *basetypeinfo[0];
};

Figure 6-4. Run-Time Type Information For Classes with no base class

struct {
       void      *basevtable;
       char      *name;
       void      *basetype;
       void      *basetypeinfo[0];
};

Figure 6-5. Run-Time Type Information for Classes with a single base class

struct base_type_info {
       char    *base_type;
       unsigned long   offset_flags;
};

struct {
       void    *basevtable;
       char    *name;
       unsigned int    flags;
       unsigned int    base_count;
       struct base_type_info base_info[0];
};

Figure 6-6. Run-Time Type Information for classes with multiple inheritance

struct {
       void    *basevtable;
       char    *name;
       unsigned int    flags;
       void    *pointee;
       void    *basetypeinfo[0];
};

Figure 6-7. Run-Time Type Information for pointer types

struct {
       void    *basevtable;
       char    *name;
       unsigned int    flags;
       void    *pointee;
       void    *context;
       void    *basetypeinfo[0];
};

Figure 6-8. Run-Time Type Information for pointer to member types

Notes

[1]

In this case virtual function A::m in class K is considered to be specified as pure virtual by this specification.

[2]

In this case virtual function A::m in class K is considered to be specified as inline by this specification.