* readelf.c (dump_relocations): Print "bad symbol index" if
authorAlan Modra <amodra@gmail.com>
Mon, 25 Jun 2001 03:30:26 +0000 (03:30 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 25 Jun 2001 03:30:26 +0000 (03:30 +0000)
symtab == NULL with non-zero symtab_index.
(process_relocs): Don't bomb if reloc section has no symsec.

binutils/ChangeLog
binutils/readelf.c

index f6d421337a6d9966c6d754b126f4f962e2b3f0f2..2ac4de719072be40841a182d50dc02970b7f91ca 100644 (file)
@@ -1,3 +1,9 @@
+2001-06-25  Alan Modra  <amodra@bigpond.net.au>
+
+       * readelf.c (dump_relocations): Print "bad symbol index" if
+       symtab == NULL with non-zero symtab_index.
+       (process_relocs): Don't bomb if reloc section has no symsec.
+
 2001-06-24  H.J. Lu  <hjl@gnu.org>
 
        * objcopy.c (strip_main): Revert the change made on 2001-05-30
index 39e90d142c38c6c7c37fb2676932ab18be9cb630..53ca41a9689acca7a619374498e460bea79d27f8 100644 (file)
@@ -964,31 +964,28 @@ dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
 
       if (symtab_index)
        {
-         if (symtab != NULL)
+         if (symtab == NULL || symtab_index >= nsyms)
+           printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
+         else
            {
-             if (symtab_index >= nsyms)
-               printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
-             else
-               {
-                 Elf_Internal_Sym * psym;
+             Elf_Internal_Sym * psym;
 
-                 psym = symtab + symtab_index;
+             psym = symtab + symtab_index;
 
-                 printf (" ");
-                 print_vma (psym->st_value, LONG_HEX);
-                 printf ("  ");
+             printf (" ");
+             print_vma (psym->st_value, LONG_HEX);
+             printf ("  ");
 
-                 if (psym->st_name == 0)
-                   printf ("%-25.25s",
-                           SECTION_NAME (section_headers + psym->st_shndx));
-                 else if (strtab == NULL)
-                   printf (_("<string table index %3ld>"), psym->st_name);
-                 else
-                   printf ("%-25.25s", strtab + psym->st_name);
+             if (psym->st_name == 0)
+               printf ("%-25.25s",
+                       SECTION_NAME (section_headers + psym->st_shndx));
+             else if (strtab == NULL)
+               printf (_("<string table index %3ld>"), psym->st_name);
+             else
+               printf ("%-25.25s", strtab + psym->st_name);
 
-                 if (is_rela)
-                   printf (" + %lx", (unsigned long) relas [i].r_addend);
-               }
+             if (is_rela)
+               printf (" + %lx", (unsigned long) relas [i].r_addend);
            }
        }
       else if (is_rela)
@@ -3073,7 +3070,6 @@ process_relocs (file)
          if (rel_size)
            {
              Elf32_Internal_Shdr * strsec;
-             Elf32_Internal_Shdr * symsec;
              Elf_Internal_Sym *    symtab;
              char *                strtab;
              int                   is_rela;
@@ -3089,25 +3085,34 @@ process_relocs (file)
              printf (_(" at offset 0x%lx contains %lu entries:\n"),
                 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
 
-             symsec = section_headers + section->sh_link;
-
-             nsyms = symsec->sh_size / symsec->sh_entsize;
-             symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
+             symtab = NULL;
+             strtab = NULL;
+             nsyms = 0;
+             if (section->sh_link)
+               {
+                 Elf32_Internal_Shdr * symsec;
 
-             if (symtab == NULL)
-               continue;
+                 symsec = section_headers + section->sh_link;
+                 nsyms = symsec->sh_size / symsec->sh_entsize;
+                 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
 
-             strsec = section_headers + symsec->sh_link;
+                 if (symtab == NULL)
+                   continue;
 
-             GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
-                             char *, "string table");
+                 strsec = section_headers + symsec->sh_link;
 
+                 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
+                                 char *, "string table");
+               }
              is_rela = section->sh_type == SHT_RELA;
 
-             dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
+             dump_relocations (file, rel_offset, rel_size,
+                               symtab, nsyms, strtab, is_rela);
 
-             free (strtab);
-             free (symtab);
+             if (strtab)
+               free (strtab);
+             if (symtab)
+               free (symtab);
 
              found = 1;
            }