[Dwarf-Discuss] EXTERNAL: Corner-cases with bitfields

Pedro Alves alves.ped@gmail.com
Mon May 9 20:18:50 GMT 2022


Hi,

(using my subscribed gmail address until my main address, CCed, is approved to also join the list.)

On 2022-05-09 16:48, Ron Brender via Dwarf-Discuss wrote:
> It seems to me that the problem here is not so much in the DWARF standard, as in the DWARF that is produced.
> 
> The DWARF representation generally serves to capture all the semantic information needed to properly represent
> the source program. In the example discussed here it appears that GCC does that (by including the bit field information) and
> CLANG does not (by erroneously omitting the bit field information).
> 
> It is probably the case that in most languages char a; and char a:8; are semantically equivalent IN ALL RESPECTS.
> For such languages,the producer/compiler is probably justified (or at least can be forgiven) for omitting the bit field information
> for char a:8. But evidently for "AMDGP-Lang" the two are not the same--while the storage layout may be the same, other
> subtle but critical aspects of the language and its ABI are quite different in the two cases.

Agreed so far.

> 
> One might have a philosophical debate about whether this difference is appropriate or not. But as Lancelot says, the ABI is
> what it is and any change is unlikely nearterm so such a debate is moot. The only issue is whether DWARF is able to
> convey the needed information. I think DWARF is able, if only the producer/compiler would do it properly.
> 

Agreed.

> So my suggestion is to file a bug report with CLANG, requesting they correct their DWARF output to reflect all details needed
> by your language.

An issue here is that DWARF does say this, in (DWARF 5, 5.7.6 Data Member Entries, page 119):

 "If the size of a data member is not the same as the size of the type given for the
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 data member, the data member has either a DW_AT_byte_size or a
 ^^^^^^^^^^^
 DW_AT_bit_size attribute whose integer constant value (see Section 2.19 on
 page 55) is the amount of storage needed to hold the value of the data member."

Note the part I underlined.  In Lancelot's case, the size of the data member
IS the same as the size of the type given for the data member.  So Clang could well pedantically
claim that they _are_ following the spec.  Shouldn't the spec be clarified here?

This then raises the question of whether a debugger can assume that the presence of a DW_AT_bit_size
attribute indicates that the field is a bit field at the C/C++ source level.  GDB is assuming that
today, as there's really no other way to tell, but I don't think the spec explicitly says so.

Pedro Alves



More information about the Dwarf-discuss mailing list