]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf.c and elflink.c fixes for commit 68bbe1183379
authorAlan Modra <amodra@gmail.com>
Sat, 5 Oct 2024 01:09:17 +0000 (10:39 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 5 Oct 2024 01:28:37 +0000 (10:58 +0930)
Plus some tidies to swap_out_syms.

* elf.c (swap_out_syms): Handle NULL sym name.  Use correct type
for return of _bfd_elf_strtab_add.  Simplify.
* elflink.c (bfd_elf_match_symbols_in_sections): Handle NULL
sym name.

bfd/elf.c
bfd/elflink.c

index 4012d994272183f3c30aae46f1d2a54afcfed6de..c68d7373b8fe974e310b7106e73d728e97dcaed7 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8734,21 +8734,21 @@ swap_out_syms (bfd *abfd,
       Elf_Internal_Sym sym;
 
       flagword flags = syms[idx]->flags;
-      if (!name_local_sections
-         && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
+      if (syms[idx]->name == NULL
+         || (!name_local_sections
+             && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM))
        {
          /* Local section symbols have no name.  */
-         sym.st_name = (unsigned long) -1;
+         sym.st_name = 0;
        }
       else
        {
          /* Call _bfd_elf_strtab_offset after _bfd_elf_strtab_finalize
             to get the final offset for st_name.  */
-         sym.st_name
-           = (unsigned long) _bfd_elf_strtab_add (stt, syms[idx]->name,
-                                                  false);
-         if (sym.st_name == (unsigned long) -1)
+         size_t stridx = _bfd_elf_strtab_add (stt, syms[idx]->name, false);
+         if (stridx == (size_t) -1)
            goto error_return;
+         sym.st_name = stridx;
        }
 
       bfd_vma value = syms[idx]->value;
@@ -8959,9 +8959,7 @@ Unable to handle section index %x in ELF symbol.  Using ABS instead."),
   for (idx = 0; idx < outbound_syms_index; idx++)
     {
       struct elf_sym_strtab *elfsym = &symstrtab[idx];
-      if (elfsym->sym.st_name == (unsigned long) -1)
-       elfsym->sym.st_name = 0;
-      else
+      if (elfsym->sym.st_name != 0)
        elfsym->sym.st_name = _bfd_elf_strtab_offset (stt,
                                                      elfsym->sym.st_name);
       if (info && info->callbacks->ctf_new_symbol)
index 9eb1122d5133259254c0d8899e1452558bd4e128..a498dbb12a6ae4ff7b65a2976b4fb9883c91c6f4 100644 (file)
@@ -8819,6 +8819,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
            symp->name = bfd_elf_string_from_elf_section (bfd1,
                                                          hdr1->sh_link,
                                                          ssym->st_name);
+           if (symp->name == NULL)
+             goto done;
            symp++;
          }
 
@@ -8832,6 +8834,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
            symp->name = bfd_elf_string_from_elf_section (bfd2,
                                                          hdr2->sh_link,
                                                          ssym->st_name);
+           if (symp->name == NULL)
+             goto done;
            symp++;
          }
 
@@ -8878,14 +8882,22 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
     goto done;
 
   for (i = 0; i < count1; i++)
-    symtable1[i].name
-      = bfd_elf_string_from_elf_section (bfd1, hdr1->sh_link,
-                                        symtable1[i].u.isym->st_name);
+    {
+      symtable1[i].name
+       = bfd_elf_string_from_elf_section (bfd1, hdr1->sh_link,
+                                          symtable1[i].u.isym->st_name);
+      if (symtable1[i].name == NULL)
+       goto done;
+    }
 
   for (i = 0; i < count2; i++)
-    symtable2[i].name
-      = bfd_elf_string_from_elf_section (bfd2, hdr2->sh_link,
-                                        symtable2[i].u.isym->st_name);
+    {
+      symtable2[i].name
+       = bfd_elf_string_from_elf_section (bfd2, hdr2->sh_link,
+                                          symtable2[i].u.isym->st_name);
+      if (symtable2[i].name == NULL)
+       goto done;
+    }
 
   /* Sort symbol by name.  */
   qsort (symtable1, count1, sizeof (struct elf_symbol),