Re: linker debug info editing

Daniel Jacobowitz
2006-03-12T18:15:42Z

On Fri, Mar 10, 2006 at 11:19:21PM +1030, Alan Modra wrote:
> /* This file implements removal of DIEs for discarded link-once sections.
> Such DIEs are detected by parsing debug sections to find DIE boundaries,
> then examining relocations for each DIE. Any DIE containing a field
> with a relocation against a symbol in a discarded section is marked for
> removal. A removed DIE in .debug_info results in all of its children
> and associated data in .debug_loc and .debug_ranges being removed too.
> A removed CIE in .debug_frame results in all FDEs using that CIE
> being removed, but no attempt is made to remove usused CIEs (as can
> happen when all of a CIE's FDEs are removed). Likewise, other unused
> shared info, ie. .debug_abbrev and .debug_str entries, are not removed.
>
> We assume that
> a) debug section relocations are sorted by r_offset,
> b) .debug_info location lists (references to .debug_loc) occur
> in increasing order of offset into .debug_loc,
> c) .debug_info ranges (references to .debug_ranges) occur
> in increasing order of offset into .debug_ranges,
> d) entries in .debug_loc and .debug_ranges are not shared,
> e) FDEs always occur at higher offsets than their associated CIEs
> in .debug_frame.
>
> ld -r using perverse linker scripts can break the first three
> assumptions. */

Jim mentioned references to DIEs. I'm also concerned by deleting just
the DIEs containing discarded relocations and their children; that's
not necessarily a logical place to cut the DIE tree. In general, this
will work for you, because the relocations you're interested in are
those on DW_AT_high_pc and DW_AT_low_pc; but if the function uses
.debug_ranges instead I guess you won't find it. And there's probably
some other cases where this is a problem, e.g. if you are cutting
member functions or static variables out of a class type. Removing
the children can affect the interpretation of the parent.

All these complications are a shame; I think it would be useful if the
linker could edit DWARF data. But it may be a bit complicated.

--
Daniel Jacobowitz
CodeSourcery