Chapter 7. C++ Class Representations

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

7.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 7-1 describes these Class Components at a high level.

Table 7-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.

7.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 7-1 and Category 2 (Non-virtual bases only) is further described in Figure 7-2. LSB conforming systems shall support these categories.

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

Figure 7-1. Category 1 Virtual Table

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

Figure 7-2. Category 2 Virtual Table

7.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 7-3. Run-Time Type Information Prefix

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

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

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

Figure 7-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 7-6. Run-Time Type Information for classes with multiple inheritance

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

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

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

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