]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd_elf_sym_name_raw
authorAlan Modra <amodra@gmail.com>
Fri, 4 Oct 2024 07:07:35 +0000 (16:37 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 4 Oct 2024 08:17:21 +0000 (17:47 +0930)
Many uses of bfd_elf_sym_name report errors.  They ought to not return
a NULL, as was the case prior to commit 68bbe1183379.  Introduce a new
function for cases where we'd like to know there is a problem with a
symbol st_name.

* elf-bfd.h  (bfd_elf_sym_name_raw): Declare.
* elf.c (bfd_elf_sym_name_raw): New function.
(bfd_elf_sym_name): Revert to behaviour prior to 68bbe1183379,
but returning "<null>" rather than "(null)" for st_name errors.
(group_signature): Use bfd_elf_sym_name_raw.
* elfcode.h (elf_slurp_symbol_table): Likewise.
* elf32-i386.c (elf_i386_scan_relocs): Whitespace.

bfd/elf-bfd.h
bfd/elf.c
bfd/elf32-i386.c
bfd/elfcode.h

index b89d3dda05d337e7134dd93a30c4dc79c29a9e98..cb147b4eb84fa5860c3cb4b27cd6e3cdffe434d1 100644 (file)
@@ -2277,6 +2277,8 @@ extern Elf_Internal_Sym *bfd_elf_get_elf_syms
   (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
    Elf_External_Sym_Shndx *);
 extern char * bfd_elf_get_str_section (bfd *, unsigned int);
+extern const char *bfd_elf_sym_name_raw
+  (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *);
 extern const char *bfd_elf_sym_name
   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
 
index 7d3d2063130bd3d5bd988207ca68b15f76ac85c8..38bfb1c2064d06d6ae70a1c47dd9db4abea01da0 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -531,12 +531,10 @@ bfd_elf_get_elf_syms (bfd *ibfd,
 
 /* Look up a symbol name.  */
 const char *
-bfd_elf_sym_name (bfd *abfd,
-                 Elf_Internal_Shdr *symtab_hdr,
-                 Elf_Internal_Sym *isym,
-                 asection *sym_sec)
+bfd_elf_sym_name_raw (bfd *abfd,
+                     Elf_Internal_Shdr *symtab_hdr,
+                     Elf_Internal_Sym *isym)
 {
-  const char *name;
   unsigned int iname = isym->st_name;
   unsigned int shindex = symtab_hdr->sh_link;
 
@@ -548,8 +546,19 @@ bfd_elf_sym_name (bfd *abfd,
       shindex = elf_elfheader (abfd)->e_shstrndx;
     }
 
-  name = bfd_elf_string_from_elf_section (abfd, shindex, iname);
-  if (sym_sec && name && *name == '\0')
+  return bfd_elf_string_from_elf_section (abfd, shindex, iname);
+}
+
+const char *
+bfd_elf_sym_name (bfd *abfd,
+                 Elf_Internal_Shdr *symtab_hdr,
+                 Elf_Internal_Sym *isym,
+                 asection *sym_sec)
+{
+  const char *name = bfd_elf_sym_name_raw (abfd, symtab_hdr, isym);
+  if (name == NULL)
+    name = "<null>";
+  else if (sym_sec && *name == '\0')
     name = bfd_section_name (sym_sec);
 
   return name;
@@ -581,7 +590,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
                            &isym, esym, &eshndx) == NULL)
     return NULL;
 
-  return bfd_elf_sym_name (abfd, hdr, &isym, NULL);
+  return bfd_elf_sym_name_raw (abfd, hdr, &isym);
 }
 
 static bool
index f27c0621a9317b32524e1b197318578d42e36e53..2e8d59518aca123c17cec8c792f008728ee3a3cd 100644 (file)
@@ -1723,7 +1723,7 @@ elf_i386_scan_relocs (bfd *abfd,
                      name = h->root.root.string;
                    else
                      name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
-                                            NULL);
+                                              NULL);
                    _bfd_error_handler
                      /* xgettext:c-format */
                      (_("%pB: `%s' accessed both as normal and "
index 3dcba4c4fd7728db09684f75a77804dc8ab507e4..6aebcc6e60230f72bac8b8aba84b5d703f731a2b 100644 (file)
@@ -1355,7 +1355,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
            sym->symbol.name = (elf_tdata (abfd)->dt_strtab
                                + isym->st_name);
          else
-           sym->symbol.name = bfd_elf_sym_name (abfd, hdr, isym, NULL);
+           sym->symbol.name = bfd_elf_sym_name_raw (abfd, hdr, isym);
          sym->symbol.value = isym->st_value;
 
          if (isym->st_shndx == SHN_UNDEF)