readelf: Handle signedness of DW_FORM_implicit_const and DW_AT_const_value.
authorMark Wielaard <mark@klomp.org>
Wed, 13 Jun 2018 12:03:24 +0000 (14:03 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 15 Jun 2018 21:48:26 +0000 (23:48 +0200)
commit1e3c7b55cfc91ed80b743daad7517ad3e51b99e1
tree08ec91de1667c60731b8a3b2b61f16ad77a31a9f
parent7a1fd63a74e456f0ad9ab954bc381050e702eeb6
readelf: Handle signedness of DW_FORM_implicit_const and DW_AT_const_value.

We only handles DW_FORM_sdata as a signed form, but DW_FORM_implicit_const
is also signed by default. For DW_AT_const_value we can do a little better.
GCC encodes some const_values with signed forms, even though the type
is unsigned. Lookup the (base) type of the DIE and display the const value
as their (signed) type/size (if we can determine that).

Add a new testcase run-readelf-const-values.sh that shows that.
With the new testcase the const values would come out as follows:

  name                 (string) "i"
  const_value          (implicit_const) 18446744073709551615
  name                 (string) "j"
  const_value          (implicit_const) 18446744073709551615

  name                 (string) "sc"
  const_value          (sdata) -2
  name                 (string) "uc"
  const_value          (sdata) -2
  name                 (string) "ss"
  const_value          (sdata) -16
  name                 (string) "us"
  const_value          (sdata) -16
  name                 (string) "si"
  const_value          (sdata) -3
  name                 (string) "ui"
  const_value          (sdata) -94967296
  name                 (string) "sl"
  const_value          (sdata) -1
  name                 (string) "ul"
  const_value          (sdata) -1

With this patch they show up as:

  name                 (string) "i"
  const_value          (implicit_const) -1
  name                 (string) "j"
  const_value          (implicit_const) -1

  name                 (string) "sc"
  const_value          (sdata) -2
  name                 (string) "uc"
  const_value          (sdata) 254 (-2)
  name                 (string) "ss"
  const_value          (sdata) -16
  name                 (string) "us"
  const_value          (sdata) 65520 (-16)
  name                 (string) "si"
  const_value          (sdata) -3
  name                 (string) "ui"
  const_value          (sdata) 4200000000 (-94967296)
  name                 (string) "sl"
  const_value          (sdata) -1
  name                 (string) "ul"
  const_value          (sdata) 18446744073709551615 (-1)

(for signed/unsigned int char, short and long)

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/Makefile.am
tests/run-readelf-const-values.sh [new file with mode: 0755]
tests/run-readelf-zdebug-rel.sh
tests/testfile-const-values.debug.bz2 [new file with mode: 0755]