Fix test case gdb.base/valgrind-bt.exp.
[deliverable/binutils-gdb.git] / binutils / readelf.c
index 8ffca057a8af06c72f176654e8d4022437acdfc1..e63deaf96363735ffeebb9004bf04f6f53ad802f 100644 (file)
@@ -44,9 +44,7 @@
 #include <assert.h>
 #include <time.h>
 #include <zlib.h>
-#ifdef HAVE_WCHAR_H
 #include <wchar.h>
-#endif
 
 #if __GNUC__ >= 2
 /* Define BFD64 here, even if our default architecture is 32 bit ELF
@@ -240,6 +238,7 @@ static bool do_not_show_symbol_truncation = false;
 static bool do_demangle = false;       /* Pretty print C++ symbol names.  */
 static bool process_links = false;
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
+static int sym_base = 0;
 
 static char *dump_ctf_parent_name;
 static char *dump_ctf_symtab_name;
@@ -294,7 +293,7 @@ typedef struct filedata
   bfd_vma *            gnuchains;
   bfd_vma *            mipsxlat;
   bfd_vma              gnusymidx;
-  char                 program_interpreter[PATH_MAX];
+  char *               program_interpreter;
   bfd_vma              dynamic_info[DT_ENCODING];
   bfd_vma              dynamic_info_DT_GNU_HASH;
   bfd_vma              dynamic_info_DT_MIPS_XHASH;
@@ -314,12 +313,17 @@ typedef struct filedata
 typedef enum print_mode
 {
   HEX,
+  HEX_5,
   DEC,
   DEC_5,
   UNSIGNED,
+  UNSIGNED_5,
   PREFIX_HEX,
+  PREFIX_HEX_5,
   FULL_HEX,
-  LONG_HEX
+  LONG_HEX,
+  OCTAL,
+  OCTAL_5
 }
 print_mode;
 
@@ -531,18 +535,34 @@ print_vma (bfd_vma vma, print_mode mode)
     case HEX:
       return nc + printf ("%" BFD_VMA_FMT "x", vma);
 
+    case PREFIX_HEX_5:
+      nc = printf ("0x");
+      /* Fall through.  */
+    case HEX_5:
+      return nc + printf ("%05" BFD_VMA_FMT "x", vma);
+
     case DEC:
       return printf ("%" BFD_VMA_FMT "d", vma);
 
     case UNSIGNED:
       return printf ("%" BFD_VMA_FMT "u", vma);
 
+    case UNSIGNED_5:
+      return printf ("%5" BFD_VMA_FMT "u", vma);
+
+    case OCTAL:
+      return printf ("%" BFD_VMA_FMT "o", vma);
+
+    case OCTAL_5:
+      return printf ("%5" BFD_VMA_FMT "o", vma);
+
     default:
       /* FIXME: Report unrecognised mode ?  */
       return 0;
     }
 }
 
+
 /* Display a symbol on stdout.  Handles the display of control characters and
    multibye characters (assuming the host environment supports them).
 
@@ -4525,7 +4545,8 @@ enum long_option_values
   OPTION_WITH_SYMBOL_VERSIONS,
   OPTION_RECURSE_LIMIT,
   OPTION_NO_RECURSE_LIMIT,
-  OPTION_NO_DEMANGLING
+  OPTION_NO_DEMANGLING,
+  OPTION_SYM_BASE
 };
 
 static struct option options[] =
@@ -4582,6 +4603,7 @@ static struct option options[] =
   {"ctf-strings",      required_argument, 0, OPTION_CTF_STRINGS},
   {"ctf-parent",       required_argument, 0, OPTION_CTF_PARENT},
 #endif
+  {"sym-base",        optional_argument, 0, OPTION_SYM_BASE},
 
   {0,                 no_argument, 0, 0}
 };
@@ -4605,6 +4627,9 @@ usage (FILE * stream)
      --symbols           An alias for --syms\n\
      --dyn-syms          Display the dynamic symbol table\n\
      --lto-syms          Display LTO symbol tables\n\
+     --sym-base=[0|8|10|16] \n\
+                         Force base for symbol sizes.  The options are \n\
+                         mixed (the default), octal, decimal, hexadecimal.\n\
   -C --demangle[=STYLE]  Decode low-level symbol names into user-level names\n\
                           The STYLE, if specified, can be `auto' (the default),\n\
                           `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
@@ -4964,6 +4989,26 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
          /* Ignored for backward compatibility.  */
          break;
 
+       case OPTION_SYM_BASE:
+         sym_base = 0;
+         if (optarg != NULL)
+           {
+             sym_base = strtoul (optarg, NULL, 0);
+             switch (sym_base)
+               {
+                 case 0:
+                 case 8:
+                 case 10:
+                 case 16:
+                   break;
+
+                 default:
+                   sym_base = 0;
+                   break;
+               }
+           }
+         break;
+
        default:
          /* xgettext:c-format */
          error (_("Invalid option '-%c'\n"), c);
@@ -5540,22 +5585,21 @@ the .dynamic section is not the same as the dynamic segment\n"));
          break;
 
        case PT_INTERP:
-         if (fseek (filedata->handle,
-                    filedata->archive_file_offset + (long) segment->p_offset,
-                    SEEK_SET))
+         if (segment->p_offset >= filedata->file_size
+             || segment->p_filesz > filedata->file_size - segment->p_offset
+             || segment->p_filesz - 1 >= (size_t) -2
+             || fseek (filedata->handle,
+                       filedata->archive_file_offset + (long) segment->p_offset,
+                       SEEK_SET))
            error (_("Unable to find program interpreter name\n"));
          else
            {
-             char fmt [32];
-             int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
-
-             if (ret >= (int) sizeof (fmt) || ret < 0)
-               error (_("Internal error: failed to create format string to display program interpreter\n"));
-
-             filedata->program_interpreter[0] = 0;
-             if (fscanf (filedata->handle, fmt,
-                         filedata->program_interpreter) <= 0)
-               error (_("Unable to read program interpreter name\n"));
+             size_t len = segment->p_filesz;
+             free (filedata->program_interpreter);
+             filedata->program_interpreter = xmalloc (len + 1);
+             len = fread (filedata->program_interpreter, 1, len,
+                          filedata->handle);
+             filedata->program_interpreter[len] = 0;
 
              if (do_segments)
                printf (_("      [Requesting program interpreter: %s]\n"),
@@ -6589,8 +6633,8 @@ process_section_headers (Filedata * filedata)
           || do_debug_str || do_debug_str_offsets || do_debug_loc
           || do_debug_ranges
           || do_debug_addr || do_debug_cu_index || do_debug_links)
-         && (const_strneq (name, ".debug_")
-             || const_strneq (name, ".zdebug_")))
+         && (startswith (name, ".debug_")
+             || startswith (name, ".zdebug_")))
        {
           if (name[1] == 'z')
             name += sizeof (".zdebug_") - 1;
@@ -6598,35 +6642,35 @@ process_section_headers (Filedata * filedata)
             name += sizeof (".debug_") - 1;
 
          if (do_debugging
-             || (do_debug_info     && const_strneq (name, "info"))
-             || (do_debug_info     && const_strneq (name, "types"))
-             || (do_debug_abbrevs  && const_strneq (name, "abbrev"))
+             || (do_debug_info     && startswith (name, "info"))
+             || (do_debug_info     && startswith (name, "types"))
+             || (do_debug_abbrevs  && startswith (name, "abbrev"))
              || (do_debug_lines    && strcmp (name, "line") == 0)
-             || (do_debug_lines    && const_strneq (name, "line."))
-             || (do_debug_pubnames && const_strneq (name, "pubnames"))
-             || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
-             || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
-             || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
-             || (do_debug_aranges  && const_strneq (name, "aranges"))
-             || (do_debug_ranges   && const_strneq (name, "ranges"))
-             || (do_debug_ranges   && const_strneq (name, "rnglists"))
-             || (do_debug_frames   && const_strneq (name, "frame"))
-             || (do_debug_macinfo  && const_strneq (name, "macinfo"))
-             || (do_debug_macinfo  && const_strneq (name, "macro"))
-             || (do_debug_str      && const_strneq (name, "str"))
-             || (do_debug_links    && const_strneq (name, "sup"))
-             || (do_debug_str_offsets && const_strneq (name, "str_offsets"))
-             || (do_debug_loc      && const_strneq (name, "loc"))
-             || (do_debug_loc      && const_strneq (name, "loclists"))
-             || (do_debug_addr     && const_strneq (name, "addr"))
-             || (do_debug_cu_index && const_strneq (name, "cu_index"))
-             || (do_debug_cu_index && const_strneq (name, "tu_index"))
+             || (do_debug_lines    && startswith (name, "line."))
+             || (do_debug_pubnames && startswith (name, "pubnames"))
+             || (do_debug_pubtypes && startswith (name, "pubtypes"))
+             || (do_debug_pubnames && startswith (name, "gnu_pubnames"))
+             || (do_debug_pubtypes && startswith (name, "gnu_pubtypes"))
+             || (do_debug_aranges  && startswith (name, "aranges"))
+             || (do_debug_ranges   && startswith (name, "ranges"))
+             || (do_debug_ranges   && startswith (name, "rnglists"))
+             || (do_debug_frames   && startswith (name, "frame"))
+             || (do_debug_macinfo  && startswith (name, "macinfo"))
+             || (do_debug_macinfo  && startswith (name, "macro"))
+             || (do_debug_str      && startswith (name, "str"))
+             || (do_debug_links    && startswith (name, "sup"))
+             || (do_debug_str_offsets && startswith (name, "str_offsets"))
+             || (do_debug_loc      && startswith (name, "loc"))
+             || (do_debug_loc      && startswith (name, "loclists"))
+             || (do_debug_addr     && startswith (name, "addr"))
+             || (do_debug_cu_index && startswith (name, "cu_index"))
+             || (do_debug_cu_index && startswith (name, "tu_index"))
              )
            request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
        }
       /* Linkonce section to be combined with .debug_info at link time.  */
       else if ((do_debugging || do_debug_info)
-              && const_strneq (name, ".gnu.linkonce.wi."))
+              && startswith (name, ".gnu.linkonce.wi."))
        request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
       else if (do_debug_frames && streq (name, ".eh_frame"))
        request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
@@ -6636,7 +6680,7 @@ process_section_headers (Filedata * filedata)
       /* Trace sections for Itanium VMS.  */
       else if ((do_debugging || do_trace_info || do_trace_abbrevs
                 || do_trace_aranges)
-              && const_strneq (name, ".trace_"))
+              && startswith (name, ".trace_"))
        {
           name += sizeof (".trace_") - 1;
 
@@ -6648,8 +6692,8 @@ process_section_headers (Filedata * filedata)
            request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
        }
       else if ((do_debugging || do_debug_links)
-              && (const_strneq (name, ".gnu_debuglink")
-                  || const_strneq (name, ".gnu_debugaltlink")))
+              && (startswith (name, ".gnu_debuglink")
+                  || startswith (name, ".gnu_debugaltlink")))
        request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
     }
 
@@ -7216,7 +7260,7 @@ process_section_groups (Filedata * filedata)
 
   if (filedata->is_separate)
     printf (_("Section groups in linked file '%s'\n"), filedata->file_name);
-      
+
   for (i = 0, section = filedata->section_headers, group = filedata->section_groups;
        i < filedata->file_header.e_shnum;
        i++, section++)
@@ -7667,7 +7711,6 @@ process_relocs (Filedata * filedata)
                printf
                  (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
                   name, rel_offset, rel_size);
-               
 
              dump_relocations (filedata,
                                offset_from_vma (filedata, rel_offset, rel_size),
@@ -8107,7 +8150,7 @@ slurp_ia64_unwind_table (Filedata *                  filedata,
              continue;
            }
 
-         if (! const_strneq (relname, "R_IA64_SEGREL"))
+         if (! startswith (relname, "R_IA64_SEGREL"))
            {
              warn (_("Skipping unexpected relocation type: %s\n"), relname);
              continue;
@@ -8235,8 +8278,8 @@ ia64_process_unwind (Filedata * filedata)
            }
        }
       else if (SECTION_NAME_VALID (unwsec)
-              && strneq (SECTION_NAME (unwsec),
-                         ELF_STRING_ia64_unwind_once, len))
+              && startswith (SECTION_NAME (unwsec),
+                             ELF_STRING_ia64_unwind_once))
        {
          /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
          len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
@@ -8245,8 +8288,8 @@ ia64_process_unwind (Filedata * filedata)
               i < filedata->file_header.e_shnum;
               ++i, ++sec)
            if (SECTION_NAME_VALID (sec)
-               && strneq (SECTION_NAME (sec),
-                          ELF_STRING_ia64_unwind_info_once, len2)
+               && startswith (SECTION_NAME (sec),
+                              ELF_STRING_ia64_unwind_info_once)
                && streq (SECTION_NAME (sec) + len2, suffix))
              break;
        }
@@ -8258,13 +8301,13 @@ ia64_process_unwind (Filedata * filedata)
          len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
          suffix = "";
          if (SECTION_NAME_VALID (unwsec)
-             && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
+             && startswith (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind))
            suffix = SECTION_NAME (unwsec) + len;
          for (i = 0, sec = filedata->section_headers;
               i < filedata->file_header.e_shnum;
               ++i, ++sec)
            if (SECTION_NAME_VALID (sec)
-               && strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
+               && startswith (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)
                && streq (SECTION_NAME (sec) + len2, suffix))
              break;
        }
@@ -8574,7 +8617,7 @@ slurp_hppa_unwind_table (Filedata *                  filedata,
            }
 
          /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
-         if (! const_strneq (relname, "R_PARISC_SEGREL"))
+         if (! startswith (relname, "R_PARISC_SEGREL"))
            {
              warn (_("Skipping unexpected relocation type: %s\n"), relname);
              continue;
@@ -9476,10 +9519,10 @@ decode_arm_unwind (Filedata *                 filedata,
         encoding, starting with one byte giving the number of
         words.  */
       if (procname != NULL
-         && (const_strneq (procname, "__gcc_personality_v0")
-             || const_strneq (procname, "__gxx_personality_v0")
-             || const_strneq (procname, "__gcj_personality_v0")
-             || const_strneq (procname, "__gnu_objc_personality_v0")))
+         && (startswith (procname, "__gcc_personality_v0")
+             || startswith (procname, "__gxx_personality_v0")
+             || startswith (procname, "__gcj_personality_v0")
+             || startswith (procname, "__gnu_objc_personality_v0")))
        {
          remaining = 0;
          more_words = 1;
@@ -11096,7 +11139,8 @@ the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
                    case DT_NEEDED:
                      printf (_("Shared library: [%s]"), name);
 
-                     if (streq (name, filedata->program_interpreter))
+                     if (filedata->program_interpreter
+                         && streq (name, filedata->program_interpreter))
                        printf (_(" program interpreter"));
                      break;
 
@@ -11355,7 +11399,7 @@ process_version_sections (Filedata * filedata)
                                section->sh_info),
                      printable_section_name (filedata, section),
                      section->sh_info);
-             
+
            printf (_(" Addr: 0x"));
            printf_vma (section->sh_addr);
            printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
@@ -11502,7 +11546,7 @@ process_version_sections (Filedata * filedata)
                                section->sh_info),
                      printable_section_name (filedata, section),
                      section->sh_info);
-             
+
            printf (_(" Addr: 0x"));
            printf_vma (section->sh_addr);
            printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
@@ -12374,6 +12418,28 @@ get_symbol_version_string (Filedata *                   filedata,
   return NULL;
 }
 
+/* Display a symbol size on stdout.  Format is based on --sym-base setting.  */
+
+static unsigned int
+print_dynamic_symbol_size (bfd_vma vma, int base)
+{
+  switch (base)
+    {
+    case 8:
+      return print_vma (vma, OCTAL_5);
+
+    case 10:
+      return print_vma (vma, UNSIGNED_5);
+
+    case 16:
+      return print_vma (vma, PREFIX_HEX_5);
+
+    case 0:
+    default:
+      return print_vma (vma, DEC_5);
+    }
+}
+
 static void
 print_dynamic_symbol (Filedata *filedata, unsigned long si,
                      Elf_Internal_Sym *symtab,
@@ -12383,12 +12449,14 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si,
   const char *version_string;
   enum versioned_symbol_info sym_info;
   unsigned short vna_other;
+  bool is_valid;
+  const char * sstr;
   Elf_Internal_Sym *psym = symtab + si;
 
   printf ("%6ld: ", si);
   print_vma (psym->st_value, LONG_HEX);
   putchar (' ');
-  print_vma (psym->st_size, DEC_5);
+  print_dynamic_symbol_size (psym->st_size, sym_base);
   printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
   printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
   if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
@@ -12406,8 +12474,20 @@ print_dynamic_symbol (Filedata *filedata, unsigned long si,
     }
   printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
 
-  bool is_valid = VALID_SYMBOL_NAME (strtab, strtab_size, psym->st_name);
-  const char * sstr = is_valid  ? strtab + psym->st_name : _("<corrupt>");
+  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION
+      && psym->st_shndx < filedata->file_header.e_shnum
+      && psym->st_name == 0)
+    {
+      is_valid = SECTION_NAME_VALID (filedata->section_headers + psym->st_shndx);
+      sstr = is_valid ?
+       SECTION_NAME_PRINT (filedata->section_headers + psym->st_shndx)
+       : _("<corrupt>");
+    }
+  else
+    {
+      is_valid = VALID_SYMBOL_NAME (strtab, strtab_size, psym->st_name);
+      sstr = is_valid  ? strtab + psym->st_name : _("<corrupt>");
+    }
 
   version_string
     = get_symbol_version_string (filedata,
@@ -12528,7 +12608,7 @@ display_lto_symtab (Filedata *           filedata,
       else
        printf (_("\nLTO Symbol table '%s' is empty!\n"),
                printable_section_name (filedata, section));
-      
+
       return true;
     }
 
@@ -15297,7 +15377,7 @@ malformed note encountered in section %s whilst scanning for build-id note\n"),
       /* Check if this is the build-id note. If so then convert the build-id
          bytes to a hex string.  */
       if (inote.namesz > 0
-          && const_strneq (inote.namedata, "GNU")
+          && startswith (inote.namedata, "GNU")
           && inote.type == NT_GNU_BUILD_ID)
         {
           unsigned long j;
@@ -15425,7 +15505,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       return false;
     }
 
-  if (const_strneq (name, ".gnu.linkonce.wi."))
+  if (startswith (name, ".gnu.linkonce.wi."))
     name = ".debug_info";
 
   /* See if we know how to display the contents of this section.  */
@@ -15436,7 +15516,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       struct dwarf_section *           sec = & display->section;
 
       if (streq (sec->uncompressed_name, name)
-         || (id == line && const_strneq (name, ".debug_line."))
+         || (id == line && startswith (name, ".debug_line."))
          || streq (sec->compressed_name, name))
        {
          bool secondary = (section != find_section (filedata, name));
@@ -15444,7 +15524,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
          if (secondary)
            free_debug_section (id);
 
-         if (i == line && const_strneq (name, ".debug_line."))
+         if (i == line && startswith (name, ".debug_line."))
            sec->name = name;
          else if (streq (sec->uncompressed_name, name))
            sec->name = sec->uncompressed_name;
@@ -15524,7 +15604,7 @@ process_section_contents (Filedata * filedata)
 
       if (filedata->is_separate && ! process_links)
        dump &= DEBUG_DUMP;
-      
+
 #ifdef SUPPORT_DISASSEMBLY
       if (dump & DISASS_DUMP)
        {
@@ -19524,7 +19604,6 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
              pnote->descdata);
       return true;
 
-#ifdef   NT_NETBSD_PAX
     case NT_NETBSD_PAX:
       if (pnote->descsz < 1)
        break;
@@ -19537,7 +19616,6 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
              ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""),
              ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
       return true;
-#endif
     }
 
   printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
@@ -19587,15 +19665,11 @@ get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
       /* NetBSD core "procinfo" structure.  */
       return _("NetBSD procinfo structure");
 
-#ifdef NT_NETBSDCORE_AUXV
     case NT_NETBSDCORE_AUXV:
       return _("NetBSD ELF auxiliary vector data");
-#endif
 
-#ifdef NT_NETBSDCORE_LWPSTATUS
     case NT_NETBSDCORE_LWPSTATUS:
       return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
-#endif
 
     default:
       /* As of Jan 2020 there are no other machine-independent notes
@@ -20429,38 +20503,38 @@ process_note (Elf_Internal_Note *  pnote,
        note type strings.  */
     nt = get_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     /* GNU-specific object file notes.  */
     nt = get_gnu_elf_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "FreeBSD"))
+  else if (startswith (pnote->namedata, "FreeBSD"))
     /* FreeBSD-specific core file notes.  */
     nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
+  else if (startswith (pnote->namedata, "NetBSD-CORE"))
     /* NetBSD-specific core file notes.  */
     nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD"))
+  else if (startswith (pnote->namedata, "NetBSD"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (const_strneq (pnote->namedata, "PaX"))
+  else if (startswith (pnote->namedata, "PaX"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (strneq (pnote->namedata, "SPU/", 4))
+  else if (startswith (pnote->namedata, "SPU/"))
     {
       /* SPU-specific core file notes.  */
       nt = pnote->namedata + 4;
       name = "SPU";
     }
 
-  else if (const_strneq (pnote->namedata, "IPF/VMS"))
+  else if (startswith (pnote->namedata, "IPF/VMS"))
     /* VMS/ia64-specific file notes.  */
     nt = get_ia64_vms_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     nt = get_stapsdt_note_type (pnote->type);
 
   else
@@ -20470,7 +20544,7 @@ process_note (Elf_Internal_Note *  pnote,
 
   printf ("  ");
 
-  if (((const_strneq (pnote->namedata, "GA")
+  if (((startswith (pnote->namedata, "GA")
        && strchr ("*$!+", pnote->namedata[2]) != NULL)
        || strchr ("*$!+", pnote->namedata[0]) != NULL)
       && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
@@ -20484,15 +20558,15 @@ process_note (Elf_Internal_Note *  pnote,
   else
     printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
 
-  if (const_strneq (pnote->namedata, "IPF/VMS"))
+  if (startswith (pnote->namedata, "IPF/VMS"))
     return print_ia64_vms_note (pnote);
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     return print_gnu_note (filedata, pnote);
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     return print_stapsdt_note (pnote);
-  else if (const_strneq (pnote->namedata, "CORE"))
+  else if (startswith (pnote->namedata, "CORE"))
     return print_core_note (pnote);
-  else if (((const_strneq (pnote->namedata, "GA")
+  else if (((startswith (pnote->namedata, "GA")
             && strchr ("*$!+", pnote->namedata[2]) != NULL)
            || strchr ("*$!+", pnote->namedata[0]) != NULL)
           && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
@@ -21054,6 +21128,70 @@ get_file_header (Filedata * filedata)
   return true;
 }
 
+static void
+free_filedata (Filedata *filedata)
+{
+  free (filedata->program_interpreter);
+  filedata->program_interpreter = NULL;
+
+  free (filedata->program_headers);
+  filedata->program_headers = NULL;
+
+  free (filedata->section_headers);
+  filedata->section_headers = NULL;
+
+  free (filedata->string_table);
+  filedata->string_table = NULL;
+  filedata->string_table_length = 0;
+
+  free (filedata->dump.dump_sects);
+  filedata->dump.dump_sects = NULL;
+  filedata->dump.num_dump_sects = 0;
+
+  free (filedata->dynamic_strings);
+  filedata->dynamic_strings = NULL;
+  filedata->dynamic_strings_length = 0;
+
+  free (filedata->dynamic_symbols);
+  filedata->dynamic_symbols = NULL;
+  filedata->num_dynamic_syms = 0;
+
+  free (filedata->dynamic_syminfo);
+  filedata->dynamic_syminfo = NULL;
+
+  free (filedata->dynamic_section);
+  filedata->dynamic_section = NULL;
+
+  while (filedata->symtab_shndx_list != NULL)
+    {
+      elf_section_list *next = filedata->symtab_shndx_list->next;
+      free (filedata->symtab_shndx_list);
+      filedata->symtab_shndx_list = next;
+    }
+
+  free (filedata->section_headers_groups);
+  filedata->section_headers_groups = NULL;
+
+  if (filedata->section_groups)
+    {
+      size_t i;
+      struct group_list * g;
+      struct group_list * next;
+
+      for (i = 0; i < filedata->group_count; i++)
+       {
+         for (g = filedata->section_groups [i].root; g != NULL; g = next)
+           {
+             next = g->next;
+             free (g);
+           }
+       }
+
+      free (filedata->section_groups);
+      filedata->section_groups = NULL;
+    }
+}
+
 static void
 close_file (Filedata * filedata)
 {
@@ -21068,6 +21206,7 @@ close_file (Filedata * filedata)
 void
 close_debug_file (void * data)
 {
+  free_filedata ((Filedata *) data);
   close_file ((Filedata *) data);
 }
 
@@ -21281,61 +21420,7 @@ process_object (Filedata * filedata)
   if (! process_arch_specific (filedata))
     res = false;
 
-  free (filedata->program_headers);
-  filedata->program_headers = NULL;
-
-  free (filedata->section_headers);
-  filedata->section_headers = NULL;
-
-  free (filedata->string_table);
-  filedata->string_table = NULL;
-  filedata->string_table_length = 0;
-
-  free (filedata->dump.dump_sects);
-  filedata->dump.dump_sects = NULL;
-  filedata->dump.num_dump_sects = 0;
-
-  free (filedata->dynamic_strings);
-  filedata->dynamic_strings = NULL;
-  filedata->dynamic_strings_length = 0;
-
-  free (filedata->dynamic_symbols);
-  filedata->dynamic_symbols = NULL;
-  filedata->num_dynamic_syms = 0;
-
-  free (filedata->dynamic_syminfo);
-  filedata->dynamic_syminfo = NULL;
-
-  free (filedata->dynamic_section);
-  filedata->dynamic_section = NULL;
-
-  while (filedata->symtab_shndx_list != NULL)
-    {
-      elf_section_list *next = filedata->symtab_shndx_list->next;
-      free (filedata->symtab_shndx_list);
-      filedata->symtab_shndx_list = next;
-    }
-
-  free (filedata->section_headers_groups);
-  filedata->section_headers_groups = NULL;
-
-  if (filedata->section_groups)
-    {
-      struct group_list * g;
-      struct group_list * next;
-
-      for (i = 0; i < filedata->group_count; i++)
-       {
-         for (g = filedata->section_groups [i].root; g != NULL; g = next)
-           {
-             next = g->next;
-             free (g);
-           }
-       }
-
-      free (filedata->section_groups);
-      filedata->section_groups = NULL;
-    }
+  free_filedata (filedata);
 
   free_debug_memory ();
 
@@ -21748,12 +21833,10 @@ main (int argc, char ** argv)
 {
   int err;
 
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
-#if defined (HAVE_SETLOCALE)
   setlocale (LC_CTYPE, "");
-#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
This page took 0.038204 seconds and 4 git commands to generate.