[PATCH] readelf: When highpc is in constant form also print as address.

Mark Wielaard mjw at redhat.com
Tue Mar 26 08:30:03 UTC 2013


On Tue, 2013-03-26 at 07:58 +0100, Jan Kratochvil wrote:
> On Mon, 25 Mar 2013 21:23:26 +0100, Mark Wielaard wrote:
> > @@ -5437,7 +5438,19 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
> >        if (cbargs->silent)
> >  	break;
> >  
> > -      if (valuestr == NULL)
> > +      /* When highpc is in constant form it is relative to lowpc.
> > +	 In that case also show the address.  */
> > +      Dwarf_Addr highpc;
> > +      if (attr == DW_AT_high_pc && (dwarf_highpc (cbargs->die, &highpc) == 0))
> > +	{
> > +	  char *a = format_dwarf_addr (cbargs->dwflmod, cbargs->addrsize,
> > +				       highpc - 1, highpc);
> 
> That "- 1" is a bug:
> 
> DWARF-4.0:
> If the value of the DW_AT_high_pc is of class address, it is the relocated
> address of the first location past the last instruction associated with the
> entity; if it is of class constant, the value is an unsigned integer offset
> which when added to the low PC gives the address of the first location past
> the last instruction associated with the entity.

Right, so it isn't a bug, but was a deliberately choice because high_pc
is "one to high". Normally when readelf displays ranges it displays them
"inclusive". That way you get the proper symbols/offsets associated with
the last byte of a code range. Otherwise readelf has to display a symbol
associated with the "next" symbol, if any. If you want "uninterpreted"
values you can always use -N or -U.

But it is inconsistent with how we display high_pc if it is a
DW_FORM_addr, or when it is displayed on its own, not as a
low_pc..high_pc range. So lets go for consistent and always display it
as a "raw" single address instead of a range.

I also fixed the parens issue Roland noticed before pushing the
attached.

Cheers,

Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: readelf-highpc.patch
Type: text/x-patch
Size: 5815 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/elfutils-devel/attachments/20130326/a8af09d9/attachment-0001.bin>


More information about the elfutils-devel mailing list