Issue 110120.1: address computation overflow (seen in Location List Entries)

Author: Joel Brobecker
Champion: Michael Eager
Date submitted: 2011-01-20
Date revised:
Date closed:
Type: Clarification
Status: Rejected
DWARF Version: 5
Section 2.6.2 Location Lists, pg 30
This is a suggestion that was made while discussing the following DWARF 
data about a variable declared as global inside a C unit (the variable was 
not declared static):

 <1><143010>: Abbrev Number: 135 (DW_TAG_variable)
    <143012>   DW_AT_decl_line   : 166
    <143014>   DW_AT_decl_file   : 26
    <143016>   DW_AT_type        : <0xe6e1>
    <14301a>   DW_AT_external    : 1
    <14301b>   DW_AT_location    : 0x90068      (location list)
    <14301f>   DW_AT_name        : blablabla

The location list contains only one entry (besides the end-of-list terminator), 
and the offsets are: 0x0, and 0xffffffff.  The CU address size is 32bits.

After adding the base address, which in this case is the CU base address, 
readelf interprets this location as follow (there is an overflow/wrap-around 
that happens):

    Offset   Begin    End      Expression
    00090068 0009f7c4 0009f7c3 (DW_OP_addr: 4000d120)
    00090068 <End of list>

As discussed on the dwarf-discuss mailing-list, a location should have been 
used in the first place.  However, it has also been suggested that it would be 
helpful for DWARF to be more explicit on how to treat such an entry.

Suggestion by Roland McGrath:
> I think it would be
> helpful for DWARF to say explicitly that such calculations should not
> overflow/wrap.  That is, if the base address plus a list entry address
> exceeds the maximum address representable by the CU's address_size (as in
> this example), the list entry is invalid.

Michael Eager said:

> The end offset should be the highest address where the address
> is valid, perhaps the end of the compilation unit.
>
> To again quote the DWARF 4 standard:
>
>  2.6.2 Location Lists
>
>  Location lists are used in place of location expressions
>  whenever the object whose location is being described can
>  change location during its lifetime.
>
> Since there is no intent that the object's location can change
> during it's lifetime, use of a location list is inappropriate.
> As this paragraph suggests, and as Roland said, a location
> expression should be used when the location of an object
> does not change during it's lifetime.


---

1/15/2013 - Rejected.  This is incorrect DWARF, since it uses a Loc List
to attempt to describe an object whose location does not change during
it's lifetime.