linux, dump_syms: Filter module entries outside specified ranges

Partitioned libraries generated with lld and llvm-objcopy currently
contain a superset of debug information, beyond what applies to the
library itself. This is because objcopy cannot split up debug
information by partition - instead, it places a copy of all debug
information into each partition.

In lieu of potential future support for lld or objcopy becoming able to
split up debug information, let dump_syms do the next best thing:

- Find the address ranges of all PT_LOAD segments in the lib.
- Supply these to the Module being generated.
- Filter additions to the Module based on these ranges.

Bug: 990190
Change-Id: Ib5f279f42e3f6ea79eed9665efbcc23c3c5d25dc
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/1884699
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Christopher Grant 2019-10-29 14:56:38 -04:00 committed by Joshua Peraza
parent 17958ef62c
commit 862c9f47ef
4 changed files with 120 additions and 0 deletions

View file

@ -205,6 +205,14 @@ class Module {
// Write is used.
void SetLoadAddress(Address load_address);
// Sets address filtering on elements added to the module. This allows
// libraries with extraneous debug symbols to generate symbol files containing
// only relevant symbols. For example, an LLD-generated partition library may
// contain debug information pertaining to all partitions derived from a
// single "combined" library. Filtering applies only to elements added after
// this method is called.
void SetAddressRanges(const vector<Range>& ranges);
// Add FUNCTION to the module. FUNCTION's name must not be empty.
// This module owns all Function objects added with this function:
// destroying the module destroys them as well.
@ -302,6 +310,10 @@ class Module {
// if an error occurs, return false, and leave errno set.
static bool WriteRuleMap(const RuleMap &rule_map, std::ostream &stream);
// Returns true of the specified address resides with an specified address
// range, or if no ranges have been specified.
bool AddressIsInModule(Address address) const;
// Module header entries.
string name_, os_, architecture_, id_, code_id_;
@ -310,6 +322,10 @@ class Module {
// address.
Address load_address_;
// The set of valid address ranges of the module. If specified, attempts to
// add elements residing outside these ranges will be silently filtered.
vector<Range> address_ranges_;
// Relation for maps whose keys are strings shared with some other
// structure.
struct CompareStringPtrs {