]> git.feebdaed.xyz Git - 0xmirror/binutils-gdb.git/commit
gdb: replace msym_bunch with deque
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Dec 2025 04:31:39 +0000 (23:31 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Dec 2025 20:11:17 +0000 (15:11 -0500)
commitdac3dbbf5e244c01d45bd1aa14e1e5cea7d5a63e
tree6606031d542fb21414c1ce6eb9928678a4157f40
parente607549f2495ed68da314642d5c4c51bdd470933
gdb: replace msym_bunch with deque

This patch replaces the msym_bunch implementation with an std::deque.

I initially tried to replace it with a vector.  However, that doesn't
work, because minimal_symbol references need to stay valid across calls
to minimal_symbol_reader::record_full in at least one spot.
elf_symtab_read calls minimal_symbol_reader::record_full (through
function record_minimal_symbol) to record a minimal symbol for a PLT
entry and then uses a previously added minimal symbol to set the size of
the PLT minimal symbol.  If we used a vector, a re-allocation could
happen which would invalidate the reference to the previous minimal
symbol (luckily this was caught by ASan).

An std::deque implementation typically uses a sequence of fixed-sized
arrays, much like our current msym_bunch implementation.  So adding an
item at the end will not invalidate existing references.  But unlike our
msym_bunch, we don't have to worry about memory management.

I was a bit puzzled about this code in
minimal_symbol_reader::record_full:

  /* If we already read minimal symbols for this objfile, then don't
     ever allocate a new one.  */
  if (!m_objfile->per_bfd->minsyms_read)
    {
      m_msym_bunch_index++;
      m_objfile->per_bfd->n_minsyms++;
    }

From what I understand, this "feature" gets used when you have
ECOFF debug info in an ELF executable.  We first parse the ELF minimal
symbols in elf_symfile_read, then go into elfmdebug_build_psymtabs.
elfmdebug_build_psymtabs has the capability to generate minimal symbols
(useful when you use ECOFF debug info in an ECOFF executable I guess),
but in this case we already have the ELF ones, so we don't want to
record the ECOFF minimal symbols.  Hence this mechanism to suppress new
minimal symbols.

The consequence of this patch, I believe, is that
minimal_symbol_reader::record_full will unnecessarily allocate minimal
symbols in this case.  These minimal symbols won't be installed, because
of the check in minimal_symbol_reader::install.  The minimal symbols
will be freed when the minimal_symbol_reader gets destroyed.  That means
a higher temporary memory usage when reading an ECOFF-in-ELF file, but
no change in behavior.  See discussion at [1].

[1] https://inbox.sourceware.org/gdb-patches/85958fad-17e1-4593-b842-d60a6610f149@polymtl.ca/T/#meaf9b53da296e7f6872b441ec97038d172ca907f

Change-Id: I7d10c6aca42cc9dcf80b483394e1e56351a9465f
Approved-By: Tom Tromey <tom@tromey.com>
gdb/minsyms.c
gdb/minsyms.h