[llvm-dev] DWARFv5 alignment attribute

Robinson, Paul via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 8 07:35:07 PDT 2016


The DWARF attribute should be attached to whatever entity is over-aligned in the source.  The cppreference.com description says C11's _Alignas applies to object declarations, rather than types, although putting it on a struct member will implicitly propagate to the containing struct type.

In this example, clearly the variable DIE for 'd' needs DW_AT_alignment(2048).  However, that's not sufficient, because if you had some other variable 'struct data x;' without an explicit alignment, you still need to specify that 'x.cacheline' is over-aligned.  That means you also need DW_AT_alignment(128) on the member DIE for 'cacheline'.

It's debatable whether to put DW_AT_alignment(128) on the type DIE for 'struct data' as well, because of the implicit propagation.  The argument against doing that is that consumers have always had to look at the content of the struct to determine its alignment, so putting it on the 'cacheline' member should be sufficient (a DWARF 5 consumer could reasonably be expected to notice the alignment attribute, given that it has to look at the member DIEs anyway).

There's no reason to put DW_AT_alignment on anything related to the array type description or the base type.
--paulr

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Victor Leschuk via llvm-dev
Sent: Thursday, September 08, 2016 1:08 AM
To: LLVM Dev
Subject: [llvm-dev] DWARFv5 alignment attribute

Hello all, I am currently implementing support for DWARFv5 DW_AT_alignment attribute (http://www.dwarfstd.org/ShowIssue.php?issue=140528.1). I am not 100% sure which entities we should mark with this attr.

Consider the following C11 code (sample from http://en.cppreference.com/w/c/language/_Alignas):

// every object of type struct data will be aligned to 128-byte boundary
struct data {
char x;
_Alignas(128) char cacheline[128]; // over-aligned array of char,
// not array of over-aligned chars
};

int main(void)
{
_Alignas(2048) struct data d; // this instance of data is aligned even stricter
return 0;
}

What should be marked as DW_AT_alignment? The link above says that the attribute can be applied to:

DW_TAG_array_type, DW_TAG_atomic_type, DW_TAG_base_type, DW_TAG_class_type,

DW_TAG_coarray_type, DW_TAG_const_type, DW_TAG_dynamic_type,

DW_TAG_enumeration_type, DW_TAG_file_type, DW_TAG_interface_type,

DW_TAG_packed_type, DW_TAG_pointer_type, DW_TAG_pointer_to_member_type,

DW_TAG_reference_type, DW_TAG_restrict_type, DW_TAG_rvalue_reference_type,

DW_TAG_set_type, DW_TAG_shared_type, DW_TAG_string_type, DW_TAG_structure_type,

DW_TAG_subprogram, DW_TAG_subrange_type, DW_TAG_subroutine_type,

DW_TAG_thrown_type, DW_TAG_typedef, DW_TAG_union_type, DW_TAG_variable

 Here we have

* DW_TAG_array_type
* DW_TAG_subrange_type
* DW_TAG_member
* DW_TAG_structure_type
* DW_TAG_basic_type
* DW_TAG_variable

Currently I mark only variable "d" as aligned, however I am not sure, that this is correct? Which of the listed should contain this attribute? What do you think?

--
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160908/985bfa79/attachment.html>


More information about the llvm-dev mailing list