[binutils-gdb] Use gdb::span in elfread.c

Tom Tromey tromey@sourceware.org
Tue Dec 1 21:06:40 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f7a01642da45fbffba40f63edc74f402852fa5df

commit f7a01642da45fbffba40f63edc74f402852fa5df
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Nov 26 01:50:17 2026 -0700

    Use gdb::span in elfread.c
    
    I noticed that elf_symtab_read could accept a gdb::span rather than an
    explicit pointer and length.  While changing this, I saw that
    elf_read_minimal_symbols could be cleaned up a little as well, by
    using a gdb::def_vector rather than a unique pointer.
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/elfread.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/gdb/elfread.c b/gdb/elfread.c
index cb213291841..335cdb2e2a2 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -251,12 +251,10 @@ record_minimal_symbol (minimal_symbol_reader &reader,
 static void
 elf_symtab_read (minimal_symbol_reader &reader,
 		 struct objfile *objfile, int type,
-		 long number_of_symbols, asymbol **symbol_table,
+		 gdb::span<asymbol *> symbol_table,
 		 bool copy_names)
 {
   struct gdbarch *gdbarch = objfile->arch ();
-  asymbol *sym;
-  long i;
   CORE_ADDR symaddr;
   enum minimal_symbol_type ms_type;
   /* Name of the last file symbol.  This is either a constant string or is
@@ -266,9 +264,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
   int elf_make_msymbol_special_p
     = gdbarch_elf_make_msymbol_special_p (gdbarch);
 
-  for (i = 0; i < number_of_symbols; i++)
+  for (asymbol *sym : symbol_table)
     {
-      sym = symbol_table[i];
       if (sym->name == NULL || *sym->name == '\0')
 	{
 	  /* Skip names that don't exist (shouldn't happen), or names
@@ -1110,8 +1107,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
   gdb::span<asymbol *> symbol_table
     = gdb_bfd_canonicalize_symtab (objfile->obfd.get ());
 
-  elf_symtab_read (reader, objfile, ST_REGULAR, symbol_table.size (),
-		   symbol_table.data (), false);
+  elf_symtab_read (reader, objfile, ST_REGULAR, symbol_table, false);
 
   /* Add the dynamic symbols.  */
 
@@ -1136,8 +1132,9 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 	       bfd_get_filename (objfile->obfd.get ()),
 	       bfd_errmsg (bfd_get_error ()));
 
-      elf_symtab_read (reader, objfile, ST_DYNAMIC, dynsymcount,
-		       dyn_symbol_table, false);
+      elf_symtab_read (reader, objfile, ST_DYNAMIC,
+		       gdb::make_span (dyn_symbol_table, dynsymcount),
+		       false);
 
       elf_rel_plt_read (reader, objfile, dyn_symbol_table);
     }
@@ -1167,14 +1164,11 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 					 &synthsyms);
   if (synthcount > 0)
     {
-      long i;
-
-      std::unique_ptr<asymbol *[]>
-	synth_symbol_table (new asymbol *[synthcount]);
-      for (i = 0; i < synthcount; i++)
+      gdb::def_vector<asymbol *> synth_symbol_table (synthcount);
+      for (long i = 0; i < synthcount; i++)
 	synth_symbol_table[i] = synthsyms + i;
-      elf_symtab_read (reader, objfile, ST_SYNTHETIC, synthcount,
-		       synth_symbol_table.get (), true);
+      elf_symtab_read (reader, objfile, ST_SYNTHETIC, synth_symbol_table,
+		       true);
 
       xfree (synthsyms);
       synthsyms = NULL;


More information about the Gdb-cvs mailing list