linker debug info editing

Alan Modra
2006-03-10T12:50:00Z

[-- Attachment #1: Type: text/plain, Size: 2272 bytes --]

This is a first pass at debug info editing to remove bogus entries for
link-once functions. I'm not going to commit it just yet as the only
testing I've done is linking a current libstdc++ and examining the
results with readelf, and there are some as yet unresolved issues.

I'm posting now because I'd like some feedback/review, particularly on
the overall design assumptions as detailed in the following comment.
Another thing I'm unsure of at this point is whether I should remove
the CU header when all following info is removed in .debug_info,
.debug_line, and .debug_aranges sections. I know one consumer (readelf)
became confused when .debug_aranges had an empty unit. Perhaps other
consumers expect some relationship between the number of CUs in
different debug sections?

One known issue is that .debug_pubnames and .debug_pubtypes have a
debug_info_length field, and I guess I need to edit this when shrinking
.debug_info.

/* 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. */

--
Alan Modra
IBM OzLabs - Linux Technology Centre

[-- Attachment #2: debug.diff.gz --]
[-- Type: application/x-gunzip, Size: 15823 bytes --]