000519.1 I Brender/Walker Representation Factored offset

Replaced by revised 000519.1.


Proposal
--------

In Section 6.4.2, change "offset" to "factored offset" in the descriptions
of DW_CFA_def_cfa and DW_CFA_def_cfa_offset.


Problem Statement
-----------------

Section 6.4.1 defines "data_alignment_facter" as

    "A signed LEB128 constant that is factored out of all offset
    instruction (see below)".

Later, four DW_CFA instructions that involve offsets are defined, namely:

[ 2.] "DW_CFA_offset
      takes two arguments: an unsigned LEB128 constant representing a
      factored offset and a register number."

[ 8.] "DW_CFA_offset_extended
      takes two unsigned LEB128 arguments representing a register number
      and a factored offset."

[15.] "DW_CFA_def_cfa
      takes two unsigned LEB128 arguments representing a register number
      and an offset."

[17.] "DW_CFA_def_cfa_offset
      takes a single unsigned LEB128 argument representing an offset."


Note that the first two of these, DW_CFA_offset and DW_CFA_offset_extended,
use the phrase "factored offset" in their description while the latter two,
DW_CFA_def_cfa and DW_CFA_def_cfa_offset, use only "offset" (omitting
the word "factored").

This difference in wording has lead to divergent implementations.

    - Some implementions treat all four instructions as using factored
      offsets. Known examples are ARM's compiler for ARM, TI's compiler
      for ARM, SGI's compiler(s) for MIPS, Aonix's ObjectAda compiler.

    - Some implementation treat only DW_CFA_offset and DW_CFA_offset_extended
      as using factored offsets, which unfactored offsets are used for
      DW_CFA_def_cfa and DW_CFA_def_cfa_offset. Know examples are gcc
      and Compaq's compilers for Alpha.

At issue is whether the difference in wording is intentional and intended
to define different handling or whether the difference in wording is
accidental and there should be no difference in handling.


Discussion/Rationale
--------------------

There appears to be no technical justification for specifying different
handling of the offset in the two pairs of instructions. Using a factored
offset for DW_CFA_def_cfa and DW_CFA_def_cfa_offset is desirable for the
same (potential space saving) reasons as it is for DW_CFA_offset and
DW_CFA_offset_extended.

Moreover, those implementations that do not use factoring for DW_CFA_def_cfa
and DW_CFA_def_cfa_offset have not taken into account the fact that
the data_alignment_factor is a signed value and the offset values stored in
the call frame instructions are unsigned values. Therefore if the offset
that is required is a negative value (which it normally is on architectures
which use a descending stack) then the only way of represending such a
value is to use a negative data_alignment_factor.

Finally, later in Appendix 5, we find the following line in the example FDE:

    fde+17     DW_CFA_def_cfa_offset(<fsize>/4) ; assuming <fsize> < 512

The operand <fsize>/4 clearly shows the use of factoring (using the
data_alignment_factor of 4 defined at cie+11). This seems clearly to
imply that factoring is intended for DW_CFA_def_cfa_offset (and by
extension, also to DW_CFA_def_cfa).

    NOTE: A separate issue is whether the data_alignment_factor should
    be -4 instead of 4; that issue is independent of this one and need
    not be consided here.

All of these considerations clearly lead to the conclusion that all
four instructions should use factored offsets.


Wording Changes
---------------

Resolve the ambiguity by adding the word "factored" in the descriptions
of DW_CFA_def_cfa and DW_CFA_def_cfa_offset, so that they read:

[15.] "DW_CFA_def_cfa
      takes two unsigned LEB128 arguments representing a register number
      and a factored offset."
          ^^^^^^^^^^

[17.] "DW_CFA_def_cfa_offset
      takes a single unsigned LEB128 argument representing a factored
                                                           ^^^^^^^^^^
      offset."