Issue 210208.2: Standardize DW_AT_GNU_numerator and DW_AT_GNU_denominator

Author: Tom Tromey
Champion: Cary Coutant
Date submitted: 2021-02-08
Date revised: 2022-04-04
Date closed: 2022-05-02
Type: Enhancement
Status: Accepted with modifications
DWARF Version: 6
Background:

Currently, we can describe scale factors that are a (positive or
negative) power of 2 with DW_AT_binary_scale, and scale factors that
are a (positive or negative) power of 10 with DW_AT_decimal_scale.
Both of these attributes provide an integer constant directly in the
attribute, giving the logarithm of the scale factor.

For other scale factors, we have DW_AT_small, which takes a reference
class value that points to a DW_TAG_constant DIE, which allows that
constant to provide an arbitrary scale factor as either a
floating-point or integer constant. In order to provide a rational
number as the scale factor, GCC currently implements an extension,
which adds DW_AT_numerator and DW_AT_denominator attributes
to the constant DIE.

It seems to me that this is unnecessarily complex and wasteful of
space. The only reason to put the constant in a separate DIE was
inability to represent a floating-point number directly in an
attribute, using a form code. A rational number has no such problem,
and I think it would be better to provide two additional scale
attributes that can be added directly to the type in question.

Proposed Change:

Add the following to Section 5.1.1.3 (Scaled Encodings)
on page 106.

"""
For a data type with a rational scale factor, one or both of the
following attributes may be used:

- DW_AT_scale_multiplier. This attribute is an integer constant value
that represents a multiplicative scale factor to be applied to an
instance of the type.

- DW_AT_scale_divisor. This attribute is an integer constant value
that represents the reciprocal of a multiplicative scale factor to be
applied to an instance of the type.

If both attributes are present, both are applied, with the result
being equivalent to a rational scale factor x/y, where x is the
DW_AT_scale_multiplier, and y is the DW_AT_scale_divisor.
"""

On line 14, where it says "For a data type with a non-decimal and
non-binary scale factor...", I suggest changing it to "For a data type
with a non-rational scale factor...".

At the end of Section 5.1.1.3, add the following:

"""
If a type entry has attributes that describe more than one kind of scale
factor, the resulting scale factor for the type is the product of the
individual scale factors.
"""

--
2021-03-25:  Revised.
2022-04-04:  Revised.  Add paragraph to clarify multiple scale factors.
2022-05-02:  Accepted with modification: Change "non-rational" to 
  "floating point".