DWARF Standard


141215.1 Cary Coutant Identify whether a type should be passed by value or implicit reference Enhancement Accepted Cary Coutant


Compare these two ways of declaring a destructor:

struct S {
   ~S() {}

struct T {
   ~T() = default;

DWARF currently provides no way to distinguish these, but in the
Itanium C++ ABI, there is a difference, and the debugger needs to
know. In the first case, with a user-defined destructor, S is not
trivially copyable, and the calling convention for a function
that returns S requires the caller to pass the address of a
buffer for the return value as an implicit first parameter
("return by invisible reference"). In the second case, with a
default destructor, T is trivially copyable, and the calling
convention allows it to return the value on the stack.

The rules in the C++ ABI for determining whether a class must be
passed or returned by invisible reference can depend on more
details of the class than a consumer can gather from the DWARF
information, and may vary from one version of the standard and
ABI to the next. In order to give the consumer an explicit
indication of how to pass an object of the class, we can allow a
type to have a DW_AT_calling_convention attribute, with one of
the following values:


If the attribute is DW_CC_normal, the consumer may attempt to
deduce the convention based on the knowledge it has of the class
structure and of the target ABI.

To allow the producer to represent this attributes as compactly
as possible, this attribute may use the new FORM code
DW_FORM_implicit_const, which encodes a constant value directly
in the abbreviation declaration. (See separate issue 141003.1c.)

Proposed Changes to the Spec

In Section 3.3.1 ("General Subroutine and Entry Point
Information"), in the paragraph beginning "A subroutine entry may
contain a DW_AT_calling_convention attribute", change "The set of
calling convention codes..." to "The set of calling convention
codes for subroutines...", and make the same change to the
caption for Table 3.3.

Add the following non-normative paragraph to Section 5.7
("Structure, Union, Class and Interface Type Entries"):

    C++ has the notion of a "trivial" class, whose objects can be
    bitwise copied. Trivial classes may have different rules for
    passing objects of that type as parameters or return values.

Add the following paragraph to Section 5.7.1 ("Structure, Union
and Class Type Entries"):

    A structure type, union type or class type entry may have a
    DW_AT_calling_convention attribute, whose value indicates
    whether should be passed by reference or by value. The set of
    calling convention codes for use with types is given in Table

        Table 3.X Calling Convention Codes for Types


    If this attribute is not present, or its value is
    DW_CC_normal, the convention to be used for object of the
    given type is assumed to be unspecified.

    If unspecified, a consumer may be able to deduce the calling
    convention based on its knowledge of the type and the ABI. 

In Section 7.15 ("Calling Convention Encodings"), add the following rows
to Table 7.19:

        Calling convention name    Value
        ----------------           -----
        DW_CC_call_by_reference    0x04
        DW_CC_call_by_value        0x05

In Appendix A, Table A.1 ("Attributes by tag value"), add
DW_AT_calling_convention to DW_TAG_class_type,
DW_TAG_struct_type, and DW_TAG_union_type.

2014/12/15 -- Replacement for 141003.1
2015/01/23 -- Accepted

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2007-2017 by DWARF Standards Committee.