This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: incorrect signed data


On 02/04/2014 03:12 PM, Josh Stone wrote:
> There are only a few internal dwarf_formsdata calls: for the decls as I
> mentioned, and in array_size() for DW_AT_lower/upper_bound.  AFAICS the
> spec doesn't explicitly call bounds signed or unsigned, but only
> unsigned makes sense to me, so these also ought to use dwarf_formudata.

http://www.dwarfstd.org/ShowIssue.php?issue=020702.1

So Fortran allows negative bounds, yay, and this is the origin of the
standard's vague statements about data[1248] context.

Here's a little experiment with gcc-gfortran-4.8.2-7.fc20.x86_64:
(and forgive my fortran ignorance, but at least this compiles)

     PROGRAM main
       INTEGER A(10:199)
       INTEGER B(-20:-10)
       A(10) = B(-10)
     END

yields:

 [    67]    array_type
             type                 (ref4) [    7f]
             sibling              (ref4) [    78]
 [    70]      subrange_type
               type                 (ref4) [    78]
               lower_bound          (data1) 10
               upper_bound          (data1) 199
 [    78]    base_type
             byte_size            (data1) 8
             encoding             (data1) signed (5)
             name                 (strp) "integer(kind=8)"
 [    7f]    base_type
             byte_size            (data1) 4
             encoding             (data1) signed (5)
             name                 (strp) "integer(kind=4)"
 [    86]    array_type
             type                 (ref4) [    7f]
             sibling              (ref4) [    a5]
 [    8f]      subrange_type
               type                 (ref4) [    78]
               lower_bound          (data8) 18446744073709551596
               upper_bound          (data8) 18446744073709551606

Thus gfortran appears to support the current elfutils behavior - read it
as unsigned and cast it without sign extension.  It happily put 199 in
data1, and went all the way to data8 for negative values.  It could have
been more compact with sdata instead of data8 though.

Also, apparently eu-readelf is not using dwarf_formsdata for bounds, and
it should.  Binutils readelf prints those as hex, no better.

FWIW, libdwarf's dwarfdump just reveals its indecision:
  DW_AT_lower_bound           10
  DW_AT_upper_bound           199(as signed = -57)
and
  DW_AT_lower_bound           18446744073709551596(as signed = -20)
  DW_AT_upper_bound           18446744073709551606(as signed = -10)


So now I'm not sure anything needs to change.  At least dwarf_formsdata
should stay as-is for gcc.  We could conceivably use dwarf_formudata for
DW_AT_decl_file/line/column, since those really are specified unsigned,
but this is unlikely to ever make a difference.  The values for
dwarf_decl_line/column are asserted 0..INT_MAX, and people with more
than INT64_MAX files are already insane.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]