Issue 250501.1: Dynamic DW_AT_data_bit_offset
| Author: | Tom Tromey |
|---|---|
| Champion: | Simon Marchi |
| Date submitted: | 2025-05-01 |
| Date revised: | |
| Date closed: | 2025-08-15 |
| Type: | Enhancement |
| Status: | Rejected |
| DWARF version: | 6 |
Consider the following Ada program:
procedure Exam is
type Small is range -7 .. -4;
for Small'Size use 2;
type Packed_Array is array (Integer range <>) of Small;
pragma pack (Packed_Array);
subtype Range_Int is Natural range 0 .. 7;
type Some_Packed_Record (Discr : Range_Int := 3) is record
Array_Field : Packed_Array (1 .. Discr);
Field : Small;
case Discr is
when 3 =>
Another_Field : Small;
when others =>
null;
end case;
end record;
pragma Pack (Some_Packed_Record);
pragma No_Component_Reordering (Some_Packed_Record);
SPR : Some_Packed_Record :=
(Discr => 3,
Field => -4,
Another_Field => -6,
Array_Field => (-5, -6, -7));
begin
null;
end Exam;
The offset to the field "Another_Field" is non-constaint and
non-byte-aligned. There is no good way to represent this with DWARF 5:
DW_AT_data_member_location: can't yield a non-byte-aligned memory locationDW_AT_data_bit_offset: is defined to be constant only
Proposal
Allow DW_AT_data_bit_offset to have a value of the class "exprval".
-
Section 5.7.6 (Data Member Entries)
In this paragraph:
For a
DW_AT_data_bit_offsetattribute, the value is an integer constant (see Section 2.19 on page 61) that specifies the number of bits from the beginning of the containing entity to the beginning of the data member. This value must be greater than or equal to zero, but is not limited to less than the number of bits per byte.... remove the word "constant".
-
Section 7.5.4 (Attribute Encodings)
For
DW_AT_data_bit_offset, add classes "exprval" and "reference".
Notes
-
The value of
DW_AT_bit_sizecan be of the reference class, which is why I propose adding reference toDW_AT_data_bit_offsettoo. -
With the "DWARF locations on the stack proposal", it seems to me like the
DW_AT_data_member_locationandDW_AT_data_bit_offsetattribute become somewhat redundant.One will be able to use
DW_AT_data_member_location, which pushes the location of the enclosing object on the stack, compute the runtime bit offset, and useDW_AT_data_bit_offsetto yield the location of the field.With the current proposal, one could also use an expression with
DW_AT_data_bit_offsetto yield the runtime bit offset, giving the same result.Should we deprecate the use of one or the other on data members, to have just one "official" way of representing this notion? We need to consider offsets to base classes too, which are similar to data members.
2025-08-15: Rejected.
The locations on the stack proposal, 230524.1, will address this issue
by allowing a DW_AT_bit_offset operator to add the bit offset
to an arbitrary location.
A new proposal, 250815.1, to clarify the ways of describing a data
member's location, has been proposed.