[Dwarf-Discuss] Proposal to add DW_AT_alignment

Mark Wielaard mjw at redhat.com
Wed May 28 07:26:12 PDT 2014


On Thu, 2014-05-15 at 15:29 +0200, Mark Wielaard wrote:
> Another thing added in C11 is the _Alignas specifier through which a
> user can request to have a type or object that is stricter than the
> default alignment for the type of object. Existing compilers like GCC
> already allow users to specify the alignment of types and variables
> through implementation specific attributes.
> 
> It is useful for debuggers to know the alignment used for an data object
> in case they need to create an object for use with some expressions to
> be evaluated in the inferior and for type analyzers to know whether two
> types are compatible.
> 
> The _Alignas request may be zero, which means the object will have the
> default alignment. In which case I think the DWARF should not contain
> the attribute. But we could also explicitly specify that an
> DW_AT_alignment of zero means the default alignment. An object can also
> have multiple alignment specifiers in which case the used alignment will
> be the strictest specified. In which case the object or type should just
> have this strictest DW_AT_alignement constant.
> 
> The C11 _Alignas allows both a constant or a type-name (to indicate that
> the object should be aligned as if it was of that type). Since in both
> cases it is the actual constant carries the actual useful information I
> think DW_AT_alignment only needs a positive constant integer form. But
> if people think having a variant that is encoded as type reference form
> is useful then that could of course be added.
> 
> Maybe there is already an existing way to express non-default alignement
> of objects and types that I am missing. If not I will write up a formal
> proposal for an DW_AT_alignment that can be added to types and/or data
> objects.

I saw the submission deadline has officially passed, but I wanted to put
up a formal proposal anyway. If not accepted to DWARF5 I will first
implement it as a GNU extensions. But of course even in that case I
would like feedback to make sure the extension is as close as possible
to what might make it into a future standard.

I realized a better way to describe the extra alignment requirements is
to introduce a new modifier type TAG instead of just adding an attribute
to all types and variables. So that is how I submitted the formal
proposal to http://dwarfstd.org/Comment.php:

Subject:  Add DW_TAG_aligned tag and DW_AT_alignment attribute
Name:  Mark Wielaard
Email:  mjw at redhat.com
Section:  5.2  Page:  80
Type:  Enhancement

Background: As discussed on the DWARF discuss list, it is useful for
debuggers to know the alignment used for an data object in case they
need to create an object for use with some expressions to be evaluated
in the inferior and for type analyzers to know whether two types are
compatible. In C11 (or through GNU attribute extensions) a user can
declare the alignment of a type or variable. The below proposal adds a
new DW_AT_alignment attribute and a DW_TAG_aligned_type type tag that
can be "wrapped around" types. Originally the idea was to have just a
DW_AT_alignment attribute that would be added to all possible type tags,
but that seemed less natural than a new modifier tag.
http://thread.gmane.org/gmane.comp.standards.dwarf/166 Proposal: Figure
1, Tag names add: DW_TAG_aligned_type. Figure 2, Attribute names add:
DW_AT_alignment non-default alignment requirements of type. In 5.2
Unspecified Type Entries add a paragraph: A modified type entry
describing a type with non-default alignment requirement (using
DW_TAG_aligned_type) has a DW_AT_alignment attribute that describes the
(non-default) alignment requirements of the type. DW_AT_alignment has a
positive, non-zero, constant describing the strictest specified
(non-default) alignment of the type. This constant describes the actual
alignment used by the compiler (if there are multiple specified by the
user, or if the user specified an alignment the compiler couldn't
satisfy, then only the strictest alignment will be added through a
DW_TAG_aligned_type). Figure 15 Type modifier tags add:
DW_TAG_aligned_type non-default alignment requirements of type. Figure
18, Tag encodings add: DW_TAG_aligned_type 0xXX Figure 20, Attribute
encodings add: DW_AT_alignment 0xXX constant Figure 42, Attributes by
tag value add: DW_TAG_aligned_type DW_AT_alignment DW_AT_name
DW_AT_sibling DW_AT_type 7.27 Type Signature Computation.
DW_AT_alignment should be added under point 4.

(Sorry, formatting seems to have been lost somewhere.)

Comments welcome.

Thanks,

Mark




More information about the Dwarf-Discuss mailing list