This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

PATCH: Tidy up readelf.c sources


Hi Guys,

  I am checking in the attached patch to perform some small tidying up
  operations on the readelf.c sources.  No bug fixed, just cleaning up
  the sources.

Cheers
  Nick

binutils/ChangeLog
2008-08-17  Nick Clifton  <nickc@redhat.com>

	* readelf.c: Tidy up the sources.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.423
diff -c -3 -p -r1.423 readelf.c
*** binutils/readelf.c	8 Aug 2008 19:24:48 -0000	1.423
--- binutils/readelf.c	17 Aug 2008 20:53:50 -0000
*************** print_symbol (int width, const char *sym
*** 462,468 ****
  	{
  	  if (len > width)
  	    len = width;
! 	  
  	  printf (format_string, len, symbol);
  
  	  width -= len;
--- 462,468 ----
  	{
  	  if (len > width)
  	    len = width;
! 
  	  printf (format_string, len, symbol);
  
  	  width -= len;
*************** print_symbol (int width, const char *sym
*** 486,492 ****
  	{
  	  if (width < 6)
  	    break;
! 	  
  	  printf ("<0x%.2x>", *c);
  
  	  width -= 6;
--- 486,492 ----
  	{
  	  if (width < 6)
  	    break;
! 
  	  printf ("<0x%.2x>", *c);
  
  	  width -= 6;
*************** dump_relocations (FILE *file,
*** 1272,1278 ****
  			       && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
  			sec_name = "ANSI_COM";
  		      else if (elf_header.e_machine == EM_IA_64
! 			       && (elf_header.e_ident[EI_OSABI] 
  				   == ELFOSABI_OPENVMS)
  			       && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
  			sec_name = "VMS_SYMVEC";
--- 1272,1278 ----
  			       && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
  			sec_name = "ANSI_COM";
  		      else if (elf_header.e_machine == EM_IA_64
! 			       && (elf_header.e_ident[EI_OSABI]
  				   == ELFOSABI_OPENVMS)
  			       && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
  			sec_name = "VMS_SYMVEC";
*************** get_machine_name (unsigned e_machine)
*** 1823,1829 ****
      case EM_ALTERA_NIOS2:	return "Altera Nios II";
      case EM_XC16X:		return "Infineon Technologies xc16x";
      case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
!     case EM_CR16:		
      case EM_CR16_OLD:		return "National Semiconductor's CR16";
      default:
        snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
--- 1823,1829 ----
      case EM_ALTERA_NIOS2:	return "Altera Nios II";
      case EM_XC16X:		return "Infineon Technologies xc16x";
      case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
!     case EM_CR16:
      case EM_CR16_OLD:		return "National Semiconductor's CR16";
      default:
        snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
*************** process_section_headers (FILE *file)
*** 4279,4286 ****
        else if (section->sh_type == SHT_RELA)
  	CHECK_ENTSIZE (section, i, Rela);
        else if ((do_debugging || do_debug_info || do_debug_abbrevs
! 		|| do_debug_lines || do_debug_lines_decoded || do_debug_pubnames 
! 		|| do_debug_aranges || do_debug_frames || do_debug_macinfo 
  		|| do_debug_str || do_debug_loc || do_debug_ranges)
  	       && (const_strneq (name, ".debug_")
                     || const_strneq (name, ".zdebug_")))
--- 4279,4286 ----
        else if (section->sh_type == SHT_RELA)
  	CHECK_ENTSIZE (section, i, Rela);
        else if ((do_debugging || do_debug_info || do_debug_abbrevs
! 		|| do_debug_lines || do_debug_lines_decoded || do_debug_pubnames
! 		|| do_debug_aranges || do_debug_frames || do_debug_macinfo
  		|| do_debug_str || do_debug_loc || do_debug_ranges)
  	       && (const_strneq (name, ".debug_")
                     || const_strneq (name, ".zdebug_")))
*************** process_section_headers (FILE *file)
*** 4293,4299 ****
  	  if (do_debugging
  	      || (do_debug_info     && streq (name, "info"))
  	      || (do_debug_abbrevs  && streq (name, "abbrev"))
! 	      || ((do_debug_lines || do_debug_lines_decoded) 
  		  && streq (name, "line"))
  	      || (do_debug_pubnames && streq (name, "pubnames"))
  	      || (do_debug_aranges  && streq (name, "aranges"))
--- 4293,4299 ----
  	  if (do_debugging
  	      || (do_debug_info     && streq (name, "info"))
  	      || (do_debug_abbrevs  && streq (name, "abbrev"))
! 	      || ((do_debug_lines || do_debug_lines_decoded)
  		  && streq (name, "line"))
  	      || (do_debug_pubnames && streq (name, "pubnames"))
  	      || (do_debug_aranges  && streq (name, "aranges"))
*************** is_32bit_abs_reloc (unsigned int reloc_t
*** 8027,8033 ****
        return reloc_type == 1; /* R_ARC_32.  */
      case EM_ARM:
        return reloc_type == 2; /* R_ARM_ABS32 */
!     case EM_AVR_OLD: 
      case EM_AVR:
        return reloc_type == 1;
      case EM_BLACKFIN:
--- 8027,8033 ----
        return reloc_type == 1; /* R_ARC_32.  */
      case EM_ARM:
        return reloc_type == 2; /* R_ARM_ABS32 */
!     case EM_AVR_OLD:
      case EM_AVR:
        return reloc_type == 1;
      case EM_BLACKFIN:
*************** is_16bit_abs_reloc (unsigned int reloc_t
*** 8255,8261 ****
  }
  
  /* Uncompresses a section that was compressed using zlib, in place.
!  * This is a copy of bfd_uncompress_section_contents, in bfd/compress.c  */
  
  static int
  uncompress_section_contents (unsigned char **buffer, dwarf_size_type *size)
--- 8255,8261 ----
  }
  
  /* Uncompresses a section that was compressed using zlib, in place.
!    This is a copy of bfd_uncompress_section_contents, in bfd/compress.c.  */
  
  static int
  uncompress_section_contents (unsigned char **buffer, dwarf_size_type *size)
*************** uncompress_section_contents (unsigned ch
*** 8267,8275 ****
    return FALSE;
  #else
    dwarf_size_type compressed_size = *size;
!   unsigned char* compressed_buffer = *buffer;
    dwarf_size_type uncompressed_size;
!   unsigned char* uncompressed_buffer;
    z_stream strm;
    int rc;
    dwarf_size_type header_size = 12;
--- 8267,8275 ----
    return FALSE;
  #else
    dwarf_size_type compressed_size = *size;
!   unsigned char * compressed_buffer = *buffer;
    dwarf_size_type uncompressed_size;
!   unsigned char * uncompressed_buffer;
    z_stream strm;
    int rc;
    dwarf_size_type header_size = 12;
*************** uncompress_section_contents (unsigned ch
*** 8277,8284 ****
    /* Read the zlib header.  In this case, it should be "ZLIB" followed
       by the uncompressed section size, 8 bytes in big-endian order.  */
    if (compressed_size < header_size
!       || ! streq ((char*) compressed_buffer, "ZLIB"))
      return 0;
    uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
    uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
    uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
--- 8277,8285 ----
    /* Read the zlib header.  In this case, it should be "ZLIB" followed
       by the uncompressed section size, 8 bytes in big-endian order.  */
    if (compressed_size < header_size
!       || ! streq ((char *) compressed_buffer, "ZLIB"))
      return 0;
+ 
    uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
    uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
    uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
*************** uncompress_section_contents (unsigned ch
*** 8294,8316 ****
    strm.zfree = NULL;
    strm.opaque = NULL;
    strm.avail_in = compressed_size - header_size;
!   strm.next_in = (Bytef*) compressed_buffer + header_size;
    strm.avail_out = uncompressed_size;
    uncompressed_buffer = xmalloc (uncompressed_size);
  
!   rc = inflateInit (&strm);
    while (strm.avail_in > 0)
      {
        if (rc != Z_OK)
          goto fail;
!       strm.next_out = ((Bytef*) uncompressed_buffer
                         + (uncompressed_size - strm.avail_out));
        rc = inflate (&strm, Z_FINISH);
        if (rc != Z_STREAM_END)
          goto fail;
!       rc = inflateReset (&strm);
      }
!   rc = inflateEnd (&strm);
    if (rc != Z_OK
        || strm.avail_out != 0)
      goto fail;
--- 8295,8317 ----
    strm.zfree = NULL;
    strm.opaque = NULL;
    strm.avail_in = compressed_size - header_size;
!   strm.next_in = (Bytef *) compressed_buffer + header_size;
    strm.avail_out = uncompressed_size;
    uncompressed_buffer = xmalloc (uncompressed_size);
  
!   rc = inflateInit (& strm);
    while (strm.avail_in > 0)
      {
        if (rc != Z_OK)
          goto fail;
!       strm.next_out = ((Bytef *) uncompressed_buffer
                         + (uncompressed_size - strm.avail_out));
        rc = inflate (&strm, Z_FINISH);
        if (rc != Z_STREAM_END)
          goto fail;
!       rc = inflateReset (& strm);
      }
!   rc = inflateEnd (& strm);
    if (rc != Z_OK
        || strm.avail_out != 0)
      goto fail;
*************** debug_apply_relocations (void *file,
*** 8435,8441 ****
  	    }
  
  	  addend = is_rela ? rp->r_addend : byte_get (loc, reloc_size);
! 	  
  	  if (is_32bit_pcrel_reloc (reloc_type))
  	    byte_put (loc, (addend + sym->st_value) - rp->r_offset,
  		      reloc_size);
--- 8436,8442 ----
  	    }
  
  	  addend = is_rela ? rp->r_addend : byte_get (loc, reloc_size);
! 
  	  if (is_32bit_pcrel_reloc (reloc_type))
  	    byte_put (loc, (addend + sym->st_value) - rp->r_offset,
  		      reloc_size);
*************** display_arm_attribute (unsigned char *p)
*** 8767,8773 ****
    tag = read_uleb128 (p, &len);
    p += len;
    attr = NULL;
!   for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags); i++)
      {
        if (arm_attr_public_tags[i].tag == tag)
  	{
--- 8768,8774 ----
    tag = read_uleb128 (p, &len);
    p += len;
    attr = NULL;
!   for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
      {
        if (arm_attr_public_tags[i].tag == tag)
  	{
*************** display_arm_attribute (unsigned char *p)
*** 8801,8811 ****
  	      val = read_uleb128 (p, &len);
  	      p += len;
  	      printf ("flag = %d, vendor = %s\n", val, p);
! 	      p += strlen((char *)p) + 1;
  	      break;
  
  	    default:
! 	      abort();
  	    }
  	  return p;
  
--- 8802,8812 ----
  	      val = read_uleb128 (p, &len);
  	      p += len;
  	      printf ("flag = %d, vendor = %s\n", val, p);
! 	      p += strlen ((char *) p) + 1;
  	      break;
  
  	    default:
! 	      abort ();
  	    }
  	  return p;
  
*************** display_arm_attribute (unsigned char *p)
*** 8838,8844 ****
    if (type == 1)
      {
        printf ("\"%s\"\n", p);
!       p += strlen((char *)p) + 1;
      }
    else
      {
--- 8839,8845 ----
    if (type == 1)
      {
        printf ("\"%s\"\n", p);
!       p += strlen ((char *) p) + 1;
      }
    else
      {
*************** get_file_header (FILE *file)
*** 10254,10261 ****
    /* Determine how to read the rest of the header.  */
    switch (elf_header.e_ident[EI_DATA])
      {
!     default: /* fall through */
!     case ELFDATANONE: /* fall through */
      case ELFDATA2LSB:
        byte_get = byte_get_little_endian;
        byte_put = byte_put_little_endian;
--- 10255,10262 ----
    /* Determine how to read the rest of the header.  */
    switch (elf_header.e_ident[EI_DATA])
      {
!     default:
!     case ELFDATANONE:
      case ELFDATA2LSB:
        byte_get = byte_get_little_endian;
        byte_put = byte_put_little_endian;
*************** process_archive (char *file_name, FILE *
*** 10575,10581 ****
  	  size -= index_num * SIZEOF_AR_INDEX_NUMBERS;
  
  	  /* Convert the index numbers into the host's numeric format.  */
! 	  index_array = malloc (index_num * sizeof (* index_array));	  
  	  if (index_array == NULL)
  	    {
  	      free (index_buffer);
--- 10576,10582 ----
  	  size -= index_num * SIZEOF_AR_INDEX_NUMBERS;
  
  	  /* Convert the index numbers into the host's numeric format.  */
! 	  index_array = malloc (index_num * sizeof (* index_array));
  	  if (index_array == NULL)
  	    {
  	      free (index_buffer);
*************** process_archive (char *file_name, FILE *
*** 10609,10615 ****
  	      error (_("%s: failed to read archive index symbol table\n"), file_name);
  	      ret = 1;
  	      goto out;
! 	    }	  
    	}
        else
  	{
--- 10610,10616 ----
  	      error (_("%s: failed to read archive index symbol table\n"), file_name);
  	      ret = 1;
  	      goto out;
! 	    }
    	}
        else
  	{
*************** process_archive (char *file_name, FILE *
*** 10724,10737 ****
  		      while ((elf_name[j] != '/') && (j < 16))
  			j++;
  		      elf_name[j] = '\0';
! 		      printf(_("Binary %s contains:\n"), elf_name);
  		    }
  		}
  	      if (l >= sym_size)
  		{
  		  error (_("%s: end of the symbol table reached before the end of the index\n"),
  			 file_name);
! 		  break;			 
  		}
  	      printf ("\t%s\n", sym_table + l);
  	      l += strlen (sym_table + l) + 1;
--- 10725,10738 ----
  		      while ((elf_name[j] != '/') && (j < 16))
  			j++;
  		      elf_name[j] = '\0';
! 		      printf (_("Binary %s contains:\n"), elf_name);
  		    }
  		}
  	      if (l >= sym_size)
  		{
  		  error (_("%s: end of the symbol table reached before the end of the index\n"),
  			 file_name);
! 		  break;
  		}
  	      printf ("\t%s\n", sym_table + l);
  	      l += strlen (sym_table + l) + 1;

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