relocs: smart reader

Roland McGrath roland at redhat.com
Mon Mar 30 02:39:16 UTC 2009


DwarfTasks 4.3 says "relocatable values: smart reader".
Here's the brain dump on what that means.

Right now, the libdw code is completely ignorant of the relocatability of
the DWARF data.  It reads straight DWARF encoding, and expects the values
it gets that way to make sense.  The libdwfl/relocate.c machinery does full
relocation of all the data (blind to its formats) before libdw looks at it.
This will change in libdw internals.  (I don't think the libdw.h interface
will change for this, thought some details in libdwfl and C++ will.)

The first step is to find each place in libdw that decodes a relocatable
quantity.  This is anything that is offset-size or address-size.  (The
dwarflint reloc work has recently enumerated all the spots not to forget.)
The libdw code has lots of things like:

  if (attrp->cu->offset_size == 8)
    off = read_8ubyte_unaligned (dbg, attrp->valp);
  else
    off = read_4ubyte_unaligned (dbg, attrp->valp);

Replace these with calls to new helpers, one for offset and one for address.
Of each, also a *_inc variant.  These will take the Dwarf * and also a size
selection argument (either offset/address size, or bool of == 8).  The
offset decoders take an IDX_debug_* argument saying which section the offset
points into.  They need to be able to signal errors (e.g. return a bool
saying they've done __libdw_seterrno).  Perhaps also both (offset and
address flavors) should take an IDX_debug_* argument saying where the
decoded data comes from (that's probably just for debugging).

To start with, just make the helpers trivial inlines wrapping
read_[48]ubyte_unaligned so nothing changes.  Next, lift the offset validity
checks from existing code into these helpers.  If there are cases that are
offset/address sized lengths instead of offsets/addrs, then we'll need
variants of the helpers for that.

A good testing hack would be to make the wrappers emit somewhere (stderr,
whatever) the idx:offset where each offset/address was decoded.  Then you
could walk the data with a eu-readelf run or whatnot, sort -u that log and
compare it to what places dwarflint thinks relocs might be.  Once we have
the right calls to these helpers in all the right places, we can fill them
in with hooks into reloc support.

I'll write more later on what the reloc support will be.  For offset relocs
in ET_REL, they are always resolvable inside the file.  For addresses the
idea is that it will do libdwfl for libdwfl-made Dwarf handles, old-fashioned
dwarf_formaddr et al will fail with "needs relocation", and new C++ reloc-savvy
interfaces will do something else.


Thanks,
Roland


More information about the elfutils-devel mailing list