This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Updates to readelf


Hi Guys,

  I have checked in the following patch to readelf to allow it to
  decode the new values that were recenetly added to
  include/elf/common.h.

Cheers
	Nick


1999-12-28  Nick Clifton  <nickc@cygnus.com>

	* readelf.c: Update with new constants added by Oct 4, 1999
	ELF ABI draft.
	(guess_is_rela): Add new machine codes, but leave
	rel type undetermined.
	(get_machine_name): Add new machine codes.
	(get_section_type_name): Add new section types.
	(get_elf_section_flags): New funciton: Decode section flags.
	(process_section_headers): Call get_elf_section_flags() in
	order to decode flags in section header.
	(get_dynamic_flags): New function: Decode dynamic section
	flags.
	(process_dynamic_section): Display flags (if present).
	(get_symbol_type): Add STT_COMMON.
	(get_symbol_visibility): New function: Decode a symbol's
	visibility.
	(process_symbol_table): Call get_symbol_visibility().
	(get_note_type): Add NT_PRXFPREGS.

Index: readelf.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/readelf.c,v
retrieving revision 1.34
diff -p -r1.34 readelf.c
*** readelf.c	1999/12/10 18:32:57	1.34
--- readelf.c	1999/12/28 20:13:53
*************** static const char *       get_segment_ty
*** 158,165 ****
  static const char *       get_mips_section_type_name  PARAMS ((unsigned int));
  static const char *       get_parisc_section_type_name PARAMS ((unsigned int));
  static const char *       get_section_type_name       PARAMS ((unsigned int));
! static char *             get_symbol_binding          PARAMS ((unsigned int));
! static char *             get_symbol_type             PARAMS ((unsigned int));
  static void               usage                       PARAMS ((void));
  static void               parse_args                  PARAMS ((int, char **));
  static int                process_file_header         PARAMS ((void));
--- 158,168 ----
  static const char *       get_mips_section_type_name  PARAMS ((unsigned int));
  static const char *       get_parisc_section_type_name PARAMS ((unsigned int));
  static const char *       get_section_type_name       PARAMS ((unsigned int));
! static const char *       get_symbol_binding          PARAMS ((unsigned int));
! static const char *       get_symbol_type             PARAMS ((unsigned int));
! static const char *       get_symbol_visibility       PARAMS ((unsigned int));
! static const char *       get_symbol_index_type       PARAMS ((unsigned int));
! static const char *       get_dynamic_flags 	      PARAMS ((bfd_vma));
  static void               usage                       PARAMS ((void));
  static void               parse_args                  PARAMS ((int, char **));
  static int                process_file_header         PARAMS ((void));
*************** static void               process_file  
*** 174,180 ****
  static int                process_relocs              PARAMS ((FILE *));
  static int                process_version_sections    PARAMS ((FILE *));
  static char *             get_ver_flags               PARAMS ((unsigned int));
- static char *             get_symbol_index_type       PARAMS ((unsigned int));
  static int                get_32bit_section_headers   PARAMS ((FILE *));
  static int                get_64bit_section_headers   PARAMS ((FILE *));
  static int		  get_32bit_program_headers   PARAMS ((FILE *, Elf_Internal_Phdr *));
--- 177,182 ----
*************** guess_is_rela (e_machine)
*** 565,570 ****
--- 567,590 ----
      case EM_MCORE:
        return TRUE;
  
+     case EM_MMA:
+     case EM_PCP:
+     case EM_NCPU:
+     case EM_NDR1:
+     case EM_STARCORE:
+     case EM_ME16:
+     case EM_ST100:
+     case EM_TINYJ:
+     case EM_FX66:
+     case EM_ST9PLUS:
+     case EM_ST7:
+     case EM_68HC16:
+     case EM_68HC11:
+     case EM_68HC08:
+     case EM_68HC05:
+     case EM_SVX:
+     case EM_ST19:
+     case EM_VAX:
      default:
        warn (_("Don't know about relocations on this machine architecture\n"));
        return FALSE;
*************** get_dynamic_type (type)
*** 1037,1042 ****
--- 1057,1067 ----
      case DT_FINI_ARRAY: return "FINI_ARRAY";
      case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
      case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
+     case DT_RUNPATH:    return "RUNPATH";
+     case DT_FLAGS:      return "FLAGS";
+     case DT_ENCODING:   return "ENCODING";
+     case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
+     case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
  
      case DT_PLTPADSZ:	return "PLTPADSZ";
      case DT_MOVEENT:	return "MOVEENT";
*************** static char *
*** 1142,1148 ****
  get_machine_name (e_machine)
       unsigned e_machine;
  {
!   static char buff [32];
  
    switch (e_machine)
      {
--- 1167,1173 ----
  get_machine_name (e_machine)
       unsigned e_machine;
  {
!   static char buff [64]; /* XXX */
  
    switch (e_machine)
      {
*************** get_machine_name (e_machine)
*** 1154,1160 ****
      case EM_88K:         	return "MC88000";
      case EM_486:         	return "Intel 80486";
      case EM_860:         	return "Intel 80860";
!     case EM_MIPS:        	return "MIPS R3000 big-endian";
      case EM_S370:        	return "Amdahl";
      case EM_MIPS_RS4_BE: 	return "MIPS R4000 big-endian";
      case EM_OLD_SPARCV9:	return "Sparc v9 (old)";
--- 1179,1185 ----
      case EM_88K:         	return "MC88000";
      case EM_486:         	return "Intel 80486";
      case EM_860:         	return "Intel 80860";
!     case EM_MIPS:        	return "MIPS R3000";
      case EM_S370:        	return "Amdahl";
      case EM_MIPS_RS4_BE: 	return "MIPS R4000 big-endian";
      case EM_OLD_SPARCV9:	return "Sparc v9 (old)";
*************** get_machine_name (e_machine)
*** 1191,1196 ****
--- 1216,1239 ----
      case EM_CYGNUS_MN10200:	return "mn10200";
      case EM_CYGNUS_FR30:	return "Fujitsu FR30";
      case EM_PJ:                 return "picoJava";
+     case EM_MMA:      		return "Fujitsu Multimedia Accelerator";
+     case EM_PCP:      		return "Siemens PCP";
+     case EM_NCPU:     		return "Sony nCPU embedded RISC processor";
+     case EM_NDR1:     		return "Denso NDR1 microprocesspr";
+     case EM_STARCORE: 		return "Motorola Star*Core processor";
+     case EM_ME16:     		return "Toyota ME16 processor";
+     case EM_ST100:    		return "STMicroelectronics ST100 processor";
+     case EM_TINYJ:    		return "Advanced Logic Corp. TinyJ embedded processor";
+     case EM_FX66:     		return "Siemens FX66 microcontroller";
+     case EM_ST9PLUS:  		return "STMicroelectronics ST9+ 8/16 bit microcontroller";
+     case EM_ST7:      		return "STMicroelectronics ST7 8-bit microcontroller";
+     case EM_68HC16:   		return "Motorola MC68HC16 Microcontroller";
+     case EM_68HC11:   		return "Motorola MC68HC11 Microcontroller";
+     case EM_68HC08:   		return "Motorola MC68HC08 Microcontroller";
+     case EM_68HC05:   		return "Motorola MC68HC05 Microcontroller";
+     case EM_SVX:      		return "Silicon Graphics SVx";
+     case EM_ST19:     		return "STMicroelectronics ST19 8-bit microcontroller";
+     case EM_VAX:      		return "Digital VAX";
      default:
        sprintf (buff, _("<unknown>: %x"), e_machine);
        return buff;
*************** get_machine_flags (e_flags, e_machine)
*** 1205,1210 ****
--- 1248,1254 ----
    static char buf [1024];
  
    buf[0] = '\0';
+   
    if (e_flags)
      {
        switch (e_machine)
*************** get_section_type_name (sh_type)
*** 1545,1550 ****
--- 1589,1597 ----
      case SHT_REL:		return "REL";
      case SHT_SHLIB:		return "SHLIB";
      case SHT_DYNSYM:		return "DYNSYM";
+     case SHT_INIT_ARRAY:	return "INIT_ARRAY";
+     case SHT_FINI_ARRAY:	return "FINI_ARRAY";
+     case SHT_PREINIT_ARRAY:	return "PREINIT_ARRAY";
      case SHT_GNU_verdef:	return "VERDEF";
      case SHT_GNU_verneed:	return "VERNEED";
      case SHT_GNU_versym:	return "VERSYM";
*************** get_64bit_elf_symbols (file, offset, num
*** 2389,2394 ****
--- 2436,2487 ----
    return isyms;
  }
  
+ static const char *
+ get_elf_section_flags (sh_flags)
+      bfd_vma sh_flags;
+ {
+   static char buff [32];
+ 
+   * buff = 0;
+   
+   while (sh_flags)
+     {
+       bfd_vma flag;
+ 
+       flag = sh_flags & - sh_flags;
+       sh_flags &= ~ flag;
+       
+       switch (flag)
+ 	{
+ 	case SHF_WRITE:            strcat (buff, "W"); break;
+ 	case SHF_ALLOC:            strcat (buff, "A"); break;
+ 	case SHF_EXECINSTR:        strcat (buff, "X"); break;
+ 	case SHF_MERGE:            strcat (buff, "M"); break;
+ 	case SHF_STRINGS:          strcat (buff, "S"); break;
+ 	case SHF_INFO_LINK:        strcat (buff, "I"); break;
+ 	case SHF_LINK_ORDER:       strcat (buff, "L"); break;
+ 	case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
+ 	  
+ 	default:
+ 	  if (flag & SHF_MASKOS)
+ 	    {
+ 	      strcat (buff, "o");
+ 	      sh_flags &= ~ SHF_MASKOS;
+ 	    }
+ 	  else if (flag & SHF_MASKPROC)
+ 	    {
+ 	      strcat (buff, "p");
+ 	      sh_flags &= ~ SHF_MASKPROC;
+ 	    }
+ 	  else
+ 	    strcat (buff, "x");
+ 	  break;
+ 	}
+     }
+   
+   return buff;
+ }
+ 
  static int
  process_section_headers (file)
       FILE * file;
*************** process_section_headers (file)
*** 2488,2493 ****
--- 2581,2587 ----
      return 1;
  
    printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
+   
    if (is_32bit_elf)
      printf
        (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
*************** process_section_headers (file)
*** 2514,2524 ****
  		   (unsigned long) section->sh_offset,
  		   (unsigned long) section->sh_size,
  		   (unsigned long) section->sh_entsize);
! 	  
! 	  printf (" %c%c%c %2ld %3lx %ld\n",
! 		  (section->sh_flags & SHF_WRITE ? 'W' : ' '),
! 		  (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
! 		  (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
  		  (unsigned long) section->sh_link,
  		  (unsigned long) section->sh_info,
  		  (unsigned long) section->sh_addralign);
--- 2608,2617 ----
  		   (unsigned long) section->sh_offset,
  		   (unsigned long) section->sh_size,
  		   (unsigned long) section->sh_entsize);
! 
! 	  printf (" %3s ", get_elf_section_flags (section->sh_flags));
! 		  
! 	  printf (" %2ld %3lx %ld\n",
  		  (unsigned long) section->sh_link,
  		  (unsigned long) section->sh_info,
  		  (unsigned long) section->sh_addralign);
*************** process_section_headers (file)
*** 2532,2543 ****
  	  print_vma (section->sh_size, LONG_HEX);
  	  printf ("  ");
  	  print_vma (section->sh_entsize, LONG_HEX);
- 	  
- 	  printf (" %c%c%c",
- 		  (section->sh_flags & SHF_WRITE ? 'W' : ' '),
- 		  (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
- 		  (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '));
  	  
  	  printf ("     %2ld   %3lx     %ld\n",
  		  (unsigned long) section->sh_link,
  		  (unsigned long) section->sh_info,
--- 2625,2633 ----
  	  print_vma (section->sh_size, LONG_HEX);
  	  printf ("  ");
  	  print_vma (section->sh_entsize, LONG_HEX);
  	  
+ 	  printf (" %3s ", get_elf_section_flags (section->sh_flags));
+ 		  
  	  printf ("     %2ld   %3lx     %ld\n",
  		  (unsigned long) section->sh_link,
  		  (unsigned long) section->sh_info,
*************** process_section_headers (file)
*** 2545,2550 ****
--- 2635,2644 ----
  	}
      }
  
+   printf (_("Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
+   printf (_("              I (info), L (link order), O (extra OS processing required)\n"));
+   printf (_("              o (os specific), p (processor specific) x (unknown)\n"));
+ 
    return 1;
  }
  
*************** get_64bit_dynamic_segment (file)
*** 2886,2891 ****
--- 2980,3008 ----
    return 1;
  }
  
+ static const char *
+ get_dynamic_flags (flags)
+      bfd_vma flags;
+ {
+   static char buff [64];
+   while (flags)
+     {
+       bfd_vma flag;
+ 
+       flag = flags & - flags;
+       flags &= ~ flag;
+ 
+       switch (flag)
+ 	{
+ 	case DF_ORIGIN:   strcat (buff, "ORIGIN "); break;
+ 	case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
+ 	case DF_TEXTREL:  strcat (buff, "TEXTREL "); break;
+ 	case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
+ 	default:          strcat (buff, "unknown "); return;
+ 	}
+     }
+ }
+ 
  /* Parse and display the contents of the dynamic segment.  */
  static int
  process_dynamic_segment (file)
*************** process_dynamic_segment (file)
*** 3058,3063 ****
--- 3175,3185 ----
  
        switch (entry->d_tag)
  	{
+ 	case DT_FLAGS:
+ 	  if (do_dynamic)
+ 	    printf (get_dynamic_flags (entry->d_un.d_val));
+ 	  break;
+ 	  
  	case DT_AUXILIARY:
  	case DT_FILTER:
  	  if (do_dynamic)
*************** process_version_sections (file)
*** 3854,3860 ****
    return 1;
  }
  
! static char *
  get_symbol_binding (binding)
       unsigned int binding;
  {
--- 3976,3982 ----
    return 1;
  }
  
! static const char *
  get_symbol_binding (binding)
       unsigned int binding;
  {
*************** get_symbol_binding (binding)
*** 3876,3882 ****
      }
  }
  
! static char *
  get_symbol_type (type)
       unsigned int type;
  {
--- 3998,4004 ----
      }
  }
  
! static const char *
  get_symbol_type (type)
       unsigned int type;
  {
*************** get_symbol_type (type)
*** 3889,3894 ****
--- 4011,4017 ----
      case STT_FUNC:     return "FUNC";
      case STT_SECTION:  return "SECTION";
      case STT_FILE:     return "FILE";
+     case STT_COMMON:   return "COMMON";
      default:
        if (type >= STT_LOPROC && type <= STT_HIPROC)
  	{
*************** get_symbol_type (type)
*** 3921,3927 ****
      }
  }
  
! static char *
  get_symbol_index_type (type)
       unsigned int type;
  {
--- 4044,4064 ----
      }
  }
  
! static const char *
! get_symbol_visibility (visibility)
!      unsigned int visibility;
! {
!   switch (visibility)
!     {
!     case STV_DEFAULT:   return "DEFAULT";
!     case STV_INTERNAL:  return "INTERNAL";
!     case STV_HIDDEN:    return "HIDDEN";
!     case STV_PROTECTED: return "PROTECTED";
!     default: abort ();
!     }
! }
! 
! static const char *
  get_symbol_index_type (type)
       unsigned int type;
  {
*************** get_symbol_index_type (type)
*** 3947,3953 ****
      }
  }
  
- 
  static int *
  get_dynamic_data (file, number)
       FILE *       file;
--- 4084,4089 ----
*************** process_symbol_table (file)
*** 4042,4050 ****
  
        printf (_("\nSymbol table for image:\n"));
        if (is_32bit_elf)
! 	printf (_("  Num Buc:    Value  Size   Type   Bind Ot Ndx Name\n"));
        else
! 	printf (_("  Num Buc:    Value          Size   Type   Bind Ot Ndx Name\n"));
  
        for (hn = 0; hn < nbuckets; hn++)
  	{
--- 4178,4186 ----
  
        printf (_("\nSymbol table for image:\n"));
        if (is_32bit_elf)
! 	printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ot Ndx Name\n"));
        else
! 	printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ot Ndx Name\n"));
  
        for (hn = 0; hn < nbuckets; hn++)
  	{
*************** process_symbol_table (file)
*** 4060,4074 ****
  	      printf ("  %3d %3d: ", si, hn);
  	      print_vma (psym->st_value, LONG_HEX);
  	      putchar (' ' );
! 	      print_vma (psym->st_size,  DEC_5);
  		      
! 	      printf ("  %6s %6s %2d ",
! 		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
! 		      get_symbol_binding (ELF_ST_BIND (psym->st_info)),
! 		      psym->st_other);
! 
! 	      printf ("%3.3s", get_symbol_index_type (psym->st_shndx));
! 
  	      printf (" %s\n", dynamic_strings + psym->st_name);
  	    }
  	}
--- 4196,4208 ----
  	      printf ("  %3d %3d: ", si, hn);
  	      print_vma (psym->st_value, LONG_HEX);
  	      putchar (' ' );
! 	      print_vma (psym->st_size, DEC_5);
  		      
! 	      printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
! 	      printf (" %6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
! 	      printf (" %3s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
! 	      printf (" %2d",  ELF_ST_OTHER (psym->st_other));
! 	      printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
  	      printf (" %s\n", dynamic_strings + psym->st_name);
  	    }
  	}
*************** process_symbol_table (file)
*** 4095,4103 ****
  		  SECTION_NAME (section),
  		  (unsigned long) (section->sh_size / section->sh_entsize));
  	  if (is_32bit_elf)
! 	    printf (_("   Num:    Value  Size Type    Bind   Ot  Ndx Name\n"));
  	  else
! 	    printf (_("   Num:    Value          Size Type    Bind   Ot  Ndx Name\n"));
  
  	  symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
  				    section->sh_size / section->sh_entsize);
--- 4229,4237 ----
  		  SECTION_NAME (section),
  		  (unsigned long) (section->sh_size / section->sh_entsize));
  	  if (is_32bit_elf)
! 	    printf (_("   Num:    Value  Size Type    Bind   Vis      Ot Ndx Name\n"));
  	  else
! 	    printf (_("   Num:    Value          Size Type    Bind   Vis      Ot  Ndx Name\n"));
  
  	  symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
  				    section->sh_size / section->sh_entsize);
*************** process_symbol_table (file)
*** 4124,4136 ****
  	      print_vma (psym->st_value, LONG_HEX);
  	      putchar (' ');
  	      print_vma (psym->st_size, DEC_5);
! 	      printf (" %-7s %-6s %2d ",
! 		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
! 		      get_symbol_binding (ELF_ST_BIND (psym->st_info)),
! 		      psym->st_other);
! 
! 	      printf ("%4s", get_symbol_index_type (psym->st_shndx));
! 
  	      printf (" %s", strtab + psym->st_name);
  
  	      if (section->sh_type == SHT_DYNSYM &&
--- 4258,4268 ----
  	      print_vma (psym->st_value, LONG_HEX);
  	      putchar (' ');
  	      print_vma (psym->st_size, DEC_5);
! 	      printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
! 	      printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
! 	      printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
! 	      printf (" %2d", ELF_ST_OTHER (psym->st_other));
! 	      printf (" %4s", get_symbol_index_type (psym->st_shndx));
  	      printf (" %s", strtab + psym->st_name);
  
  	      if (section->sh_type == SHT_DYNSYM &&
*************** process_mips_specific (file)
*** 6541,6547 ****
    if (options_offset != 0)
      {
        Elf_External_Options * eopt;
!       Elf_Internal_Shdr * sect = section_headers;
        Elf_Internal_Options * iopt;
        Elf_Internal_Options * option;
        size_t offset;
--- 6673,6679 ----
    if (options_offset != 0)
      {
        Elf_External_Options * eopt;
!       Elf_Internal_Shdr *    sect = section_headers;
        Elf_Internal_Options * iopt;
        Elf_Internal_Options * option;
        size_t offset;
*************** process_mips_specific (file)
*** 6549,6555 ****
  
        /* Find the section header so that we get the size.  */
        while (sect->sh_type != SHT_MIPS_OPTIONS)
! 	++sect;
  
        GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
  		      Elf_External_Options *, "options");
--- 6681,6687 ----
  
        /* Find the section header so that we get the size.  */
        while (sect->sh_type != SHT_MIPS_OPTIONS)
! 	++ sect;
  
        GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
  		      Elf_External_Options *, "options");
*************** process_mips_specific (file)
*** 6564,6569 ****
--- 6696,6702 ----
  
        offset = cnt = 0;
        option = iopt;
+       
        while (offset < sect->sh_size)
  	{
  	  Elf_External_Options * eoption;
*************** process_mips_specific (file)
*** 6576,6581 ****
--- 6709,6715 ----
  	  option->info = BYTE_GET (eoption->info);
  
  	  offset += option->size;
+ 	  
  	  ++option;
  	  ++cnt;
  	}
*************** process_mips_specific (file)
*** 6584,6589 ****
--- 6718,6724 ----
  	      string_table + sect->sh_name, cnt);
  
        option = iopt;
+       
        while (cnt-- > 0)
  	{
  	  size_t len;
*************** get_note_type (e_type)
*** 6799,6804 ****
--- 6934,6940 ----
      case NT_FPREGSET:	return _("NT_FPREGSET (floating point registers)");
      case NT_PRPSINFO:   return _("NT_PRPSINFO (prpsinfo structure)");
      case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
+     case NT_PRXFPREG:   return _("NT_PRXFPREG (user_xfpregs structure)");
      case NT_PSTATUS:	return _("NT_PSTATUS (pstatus structure)");
      case NT_FPREGS:	return _("NT_FPREGS (floating point registers)");
      case NT_PSINFO:	return _("NT_PSINFO (psinfo structure)");

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]