[binutils-gdb] Minor stabs-related cleanups in elfread.c
Tom Tromey
tromey@sourceware.org
Tue Dec 1 21:06:45 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7b35b04b2f4ad406f0ba0adfda37bc7f2b4d1461
commit 7b35b04b2f4ad406f0ba0adfda37bc7f2b4d1461
Author: Tom Tromey <tom@tromey.com>
Date: Mon Nov 30 13:01:06 2026 -0700
Minor stabs-related cleanups in elfread.c
A while back I noticed that elfread.c will skip minsym reuse if the
stabs section exists. This made sense (well, it was a convenient
workaround) when stabs were supported, but now this code doesn't make
sense.
This patch removes the check: neither stabs nor mdebug are read at all
any more, and CTF will not create minimal symbols.
I applied a few other little code cleanups here while working on this.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diff:
---
gdb/elfread.c | 68 ++++++++++++++++++-----------------------------------------
1 file changed, 21 insertions(+), 47 deletions(-)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 335cdb2e2a2..1db280b0256 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -70,11 +70,14 @@ show_debug_gnu_ifunc (struct ui_file *file, int from_tty,
It's local to elf_symfile_read. */
struct elfinfo
- {
- asection *stabsect; /* Section pointer for .stab section */
- asection *mdebugsect; /* Section pointer for .mdebug section */
- asection *ctfsect; /* Section pointer for .ctf section */
- };
+{
+ /* Section pointer for .stab section */
+ asection *stabsect = nullptr;
+ /* Section pointer for .mdebug section */
+ asection *mdebugsect = nullptr;
+ /* Section pointer for .ctf section */
+ asection *ctfsect = nullptr;
+};
/* Type for per-BFD data. */
@@ -178,31 +181,17 @@ elf_symfile_segments (bfd *abfd)
line number sections from matching their section names. The
ELF definition is no real help here since it has no direct
knowledge of DWARF (by design, so any debugging format can be
- used).
-
- We also recognize the ".stab" sections used by the Sun compilers
- released with Solaris 2.
-
- FIXME: The section names should not be hardwired strings (what
- should they be? I don't think most object file formats have enough
- section flags to specify what kind of debug section it is.
- -kingdon). */
+ used). */
static void
elf_locate_sections (asection *sectp, struct elfinfo *ei)
{
if (streq (sectp->name, ".stab"))
- {
- ei->stabsect = sectp;
- }
+ ei->stabsect = sectp;
else if (streq (sectp->name, ".mdebug"))
- {
- ei->mdebugsect = sectp;
- }
+ ei->mdebugsect = sectp;
else if (streq (sectp->name, ".ctf"))
- {
- ei->ctfsect = sectp;
- }
+ ei->ctfsect = sectp;
}
static struct minimal_symbol *
@@ -236,13 +225,7 @@ record_minimal_symbol (minimal_symbol_reader &reader,
Given an objfile, a symbol table, and a flag indicating whether the
symbol table contains regular, dynamic, or synthetic symbols, add all
- the global function and data symbols to the minimal symbol table.
-
- In stabs-in-ELF, as implemented by Sun, there are some local symbols
- defined in the ELF symbol table, which can be used to locate
- the beginnings of sections from each ".o" file that was linked to
- form the executable objfile. We gather any such info and record it
- in data structures hung off the objfile's private data. */
+ the global function and data symbols to the minimal symbol table. */
#define ST_REGULAR 0
#define ST_DYNAMIC 1
@@ -1075,8 +1058,7 @@ elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b)
symbols. */
static void
-elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
- const struct elfinfo *ei)
+elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags)
{
bfd *synth_abfd, *abfd = objfile->obfd.get ();
long dynsymcount = 0, synthcount;
@@ -1086,15 +1068,8 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
symtab_create_debug_printf ("reading minimal symbols of objfile %s",
objfile_name (objfile));
- /* If we already have minsyms, then we can skip some work here.
- However, if there were stabs or mdebug sections, we go ahead and
- redo all the work anyway, because the psym readers for those
- kinds of debuginfo need extra information found here. This can
- go away once all types of symbols are in the per-BFD object. */
- if (objfile->per_bfd->minsyms_read
- && ei->stabsect == NULL
- && ei->mdebugsect == NULL
- && ei->ctfsect == NULL)
+ /* If we already have minsyms, then we can skip some work here. */
+ if (objfile->per_bfd->minsyms_read)
{
symtab_create_debug_printf ("minimal symbols were previously read");
return;
@@ -1249,14 +1224,13 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
bfd *abfd = objfile->obfd.get ();
struct elfinfo ei;
- memset ((char *) &ei, 0, sizeof (ei));
if (!(objfile->flags & OBJF_READNEVER))
{
for (asection *sect : gdb_bfd_sections (abfd))
elf_locate_sections (sect, &ei);
}
- elf_read_minimal_symbols (objfile, symfile_flags, &ei);
+ elf_read_minimal_symbols (objfile, symfile_flags);
/* ELF debugging information is inserted into the psymtab in the
order of least informative first - most informative last. Since
@@ -1270,20 +1244,20 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
we don't do this then the XCOFF info is found first - for code in
an included file XCOFF info is useless. */
- if (ei.mdebugsect)
+ if (ei.mdebugsect != nullptr)
warning (_("mdebug debug information is not supported."));
- if (ei.stabsect)
+ if (ei.stabsect != nullptr)
warning (_("stabs debug information is not supported."));
/* Read the CTF section only if there is no DWARF info. */
- if (always_read_ctf && ei.ctfsect)
+ if (always_read_ctf && ei.ctfsect != nullptr)
elfctf_build_symtabs (objfile);
bool has_dwarf2 = elf_symfile_read_dwarf2 (objfile, symfile_flags);
/* Read the CTF section only if there is no DWARF info. */
- if (!always_read_ctf && !has_dwarf2 && ei.ctfsect)
+ if (!always_read_ctf && !has_dwarf2 && ei.ctfsect != nullptr)
elfctf_build_symtabs (objfile);
/* Copy relocations are used by some ABIs using the ELF format, so
More information about the Gdb-cvs
mailing list