FreeBSD/contrib/binutils/binutils/readelf.c
/* Process one ELF object file according to the command line options.
   This file may actually be stored in an archive.  The file is
   positioned at the start of the ELF object.  */
Process one ELF object file according to the command line options.
This file may actually be stored in an archive.  The file is
positioned at the start of the ELF object.
Process one ELF object file according to the command line options . This file may actually be stored in an archive . The file is positioned at the start of the ELF object .
static int
process_object (char *file_name, FILE *file)
{
  unsigned int i;
  if (! get_file_header (file))
    {
      error (_("%s: Failed to read file header\n"), file_name);
      return 1;
    }
  for (i = NUM_ELEM (version_info); i--;)
    version_info[i] = 0;
  for (i = NUM_ELEM (dynamic_info); i--;)
    dynamic_info[i] = 0;
  if (show_name)
    printf (_("\nFile: %s\n"), file_name);
  if (num_dump_sects > num_cmdline_dump_sects)
    memset (dump_sects, 0, num_dump_sects);
  if (num_cmdline_dump_sects > 0)
    {
      if (num_dump_sects == 0)
	request_dump (num_cmdline_dump_sects, 0);
      assert (num_dump_sects >= num_cmdline_dump_sects);
      memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
    }
  if (! process_file_header ())
    return 1;
  if (! process_section_headers (file))
    {
      do_unwind = do_version = do_dump = do_arch = 0;
      if (! do_using_dynamic)
	do_syms = do_reloc = 0;
    }
  if (! process_section_groups (file))
    {
      do_unwind = 0;
    }
  if (process_program_headers (file))
    process_dynamic_section (file);
  process_relocs (file);
  process_unwind (file);
  process_symbol_table (file);
  process_syminfo (file);
  process_version_sections (file);
  process_section_contents (file);
  process_notes (file);
  process_gnu_liblist (file);
  process_arch_specific (file);
  if (program_headers)
    {
      free (program_headers);
      program_headers = NULL;
    }
  if (section_headers)
    {
      free (section_headers);
      section_headers = NULL;
    }
  if (string_table)
    {
      free (string_table);
      string_table = NULL;
      string_table_length = 0;
    }
  if (dynamic_strings)
    {
      free (dynamic_strings);
      dynamic_strings = NULL;
      dynamic_strings_length = 0;
    }
  if (dynamic_symbols)
    {
      free (dynamic_symbols);
      dynamic_symbols = NULL;
      num_dynamic_syms = 0;
    }
  if (dynamic_syminfo)
    {
      free (dynamic_syminfo);
      dynamic_syminfo = NULL;
    }
  if (section_headers_groups)
    {
      free (section_headers_groups);
      section_headers_groups = NULL;
    }
  if (section_groups)
    {
      struct group_list *g, *next;
      for (i = 0; i < group_count; i++)
	{
	  for (g = section_groups [i].root; g != NULL; g = next)
	    {
	      next = g->next;
	      free (g);
	    }
	}
      free (section_groups);
      section_groups = NULL;
    }
  free_debug_memory ();
  return 0;
}
static int process_object ( char * file_name , FILE * file ) { unsigned int i ; if ( ! get_file_header ( file ) ) { error ( _ ( " \n " ) , file_name ) ; return 1 ; } for ( i = NUM_ELEM ( version_info ) ; i -- ; ) version_info [ i ] = 0 ; for ( i = NUM_ELEM ( dynamic_info ) ; i -- ; ) dynamic_info [ i ] = 0 ; if ( show_name ) printf ( _ ( " \n \n " ) , file_name ) ; if ( num_dump_sects > num_cmdline_dump_sects ) memset ( dump_sects , 0 , num_dump_sects ) ; if ( num_cmdline_dump_sects > 0 ) { if ( num_dump_sects == 0 ) request_dump ( num_cmdline_dump_sects , 0 ) ; assert ( num_dump_sects >= num_cmdline_dump_sects ) ; memcpy ( dump_sects , cmdline_dump_sects , num_cmdline_dump_sects ) ; } if ( ! process_file_header ( ) ) return 1 ; if ( ! process_section_headers ( file ) ) { do_unwind = do_version = do_dump = do_arch = 0 ; if ( ! do_using_dynamic ) do_syms = do_reloc = 0 ; } if ( ! process_section_groups ( file ) ) { do_unwind = 0 ; } if ( process_program_headers ( file ) ) process_dynamic_section ( file ) ; process_relocs ( file ) ; process_unwind ( file ) ; process_symbol_table ( file ) ; process_syminfo ( file ) ; process_version_sections ( file ) ; process_section_contents ( file ) ; process_notes ( file ) ; process_gnu_liblist ( file ) ; process_arch_specific ( file ) ; if ( program_headers ) { free ( program_headers ) ; program_headers = NULL ; } if ( section_headers ) { free ( section_headers ) ; section_headers = NULL ; } if ( string_table ) { free ( string_table ) ; string_table = NULL ; string_table_length = 0 ; } if ( dynamic_strings ) { free ( dynamic_strings ) ; dynamic_strings = NULL ; dynamic_strings_length = 0 ; } if ( dynamic_symbols ) { free ( dynamic_symbols ) ; dynamic_symbols = NULL ; num_dynamic_syms = 0 ; } if ( dynamic_syminfo ) { free ( dynamic_syminfo ) ; dynamic_syminfo = NULL ; } if ( section_headers_groups ) { free ( section_headers_groups ) ; section_headers_groups = NULL ; } if ( section_groups ) { struct group_list * g , * next ; for ( i = 0 ; i < group_count ; i ++ ) { for ( g = section_groups [ i ] . root ; g != NULL ; g = next ) { next = g -> next ; free ( g ) ; } } free ( section_groups ) ; section_groups = NULL ; } free_debug_memory ( ) ; return 0 ; }
Process one ELF object file according to the command line options.
Process one ELF object file according to the command line options .
/* Initialise per file variables.  */ /* Process the file.  */ /* Initialise the dump_sects array from the cmdline_dump_sects array.
     Note we do this even if cmdline_dump_sects is empty because we
     must make sure that the dump_sets array is zeroed out before each
     object file is processed.  */ /* A sneaky way of allocating the dump_sects array.  */ /* Without loaded section headers we cannot process lots of
	 things.  */ /* Without loaded section groups we cannot process unwind.  */