diff options
author | Tom de Vries <tdevries@suse.de> | 2018-12-28 03:43:56 +0000 |
---|---|---|
committer | Tom de Vries <vries@gcc.gnu.org> | 2018-12-28 03:43:56 +0000 |
commit | eb33bf0a0a4914eb2a88614cf4041069843018d6 (patch) | |
tree | eed07881def123f46b43c853f4f33d03c6a06f79 /libbacktrace | |
parent | d9aa0961ea1b37aa2159761b147e9668422925ba (diff) | |
download | gcc-eb33bf0a0a4914eb2a88614cf4041069843018d6.zip gcc-eb33bf0a0a4914eb2a88614cf4041069843018d6.tar.gz gcc-eb33bf0a0a4914eb2a88614cf4041069843018d6.tar.bz2 |
[libbacktrace] Reduce memory usage in build_address_map
In build_address_map we allocate a unit, and then look for addresses in the
unit, which we store in the addrs vector, with the elements pointing to the
unit. However, if we cannot find addresses in the unit, the allocated unit is
not used.
Fix this by detecting if the allocated unit has been used, and reusing it
otherwise.
Bootstrapped and reg-tested on x86_64.
2018-12-28 Tom de Vries <tdevries@suse.de>
* dwarf.c (build_address_map): Reuse unused units.
From-SVN: r267445
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/ChangeLog | 4 | ||||
-rw-r--r-- | libbacktrace/dwarf.c | 14 |
2 files changed, 18 insertions, 0 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index ee31ef0..c8ddf43 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,5 +1,9 @@ 2018-12-28 Tom de Vries <tdevries@suse.de> + * dwarf.c (build_address_map): Reuse unused units. + +2018-12-28 Tom de Vries <tdevries@suse.de> + * dwarf.c (build_address_map): Simplify by removing local variable abbrevs. diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c index 7ef99bd..733da19 100644 --- a/libbacktrace/dwarf.c +++ b/libbacktrace/dwarf.c @@ -1436,9 +1436,11 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address, size_t units_count; size_t i; struct unit **pu; + size_t prev_addrs_count; memset (&addrs->vec, 0, sizeof addrs->vec); addrs->count = 0; + prev_addrs_count = 0; /* Read through the .debug_info section. FIXME: Should we use the .debug_aranges section? gdb and addr2line don't use it, but I'm @@ -1534,6 +1536,18 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address, if (unit_buf.reported_underflow) goto fail; + + if (addrs->count > prev_addrs_count) + prev_addrs_count = addrs->count; + else + { + /* Unit was not used; remove it from the vector. */ + --units_count; + units.size -= sizeof (u); + units.alc += sizeof (u); + free_abbrevs (state, &u->abbrevs, error_callback, data); + backtrace_free (state, u, sizeof *u, error_callback, data); + } } if (info.reported_underflow) goto fail; |