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

PATCH: Improve .note section handling in readelf


At present, readelf only dumps PT_NOTE segments in ET_CORE files.
This patch allows it to dump SHT_NOTE sections in object files.  

OK to commit?

Also, I see that obj-elf.c in GAS is emitting bogus entries when
processing ".version".  In particular, it sets the name in the note to
the version.  The name in the note should be the toolchain that
created the note, probably "GNU" in our case.  The version itself
should go in the description field.  And, the "namesz" field in the
ELF note is bogus; it's being rounded up to a wordsize boundary, but
the correct thing to is just to pad the entry itself, not round the
"namesz" field.  Would a patch to fix these problems be acceptable?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-10-25  Mark Mitchell  <mark@codesourcery.com>

	* readelf.c (get_note_type): Handle notes not in core files.
	(process_note_sections): New function.
	(process_corefile_contents): Rename to ...
	(process_notes): ... this.
	(process_object): Call process_notes, not
	process_corefile_contents.
	* doc/binutils.texi: Update readelf -n documentation.

Index: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.258
diff -c -5 -p -r1.258 readelf.c
*** readelf.c	19 Oct 2004 19:30:33 -0000	1.258
--- readelf.c	26 Oct 2004 02:11:27 -0000
*************** process_gnu_liblist (FILE *file)
*** 10341,10368 ****
  static const char *
  get_note_type (unsigned e_type)
  {
    static char buff[64];
  
!   switch (e_type)
!     {
!     case NT_AUXV: 	return _("NT_AUXV (auxiliary vector)");
!     case NT_PRSTATUS:	return _("NT_PRSTATUS (prstatus structure)");
!     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)");
!     case NT_LWPSTATUS:	return _("NT_LWPSTATUS (lwpstatus_t structure)");
!     case NT_LWPSINFO:	return _("NT_LWPSINFO (lwpsinfo_t structure)");
!     case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
!     default:
!       sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
!       return buff;
!     }
  }
  
  static const char *
  get_netbsd_elfcore_note_type (unsigned e_type)
  {
--- 10341,10393 ----
  static const char *
  get_note_type (unsigned e_type)
  {
    static char buff[64];
  
!   if (elf_header.e_type == ET_CORE)
!     switch (e_type)
!       {
!       case NT_AUXV: 	
! 	return _("NT_AUXV (auxiliary vector)");
!       case NT_PRSTATUS:	
! 	return _("NT_PRSTATUS (prstatus structure)");
!       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)");
!       case NT_LWPSTATUS:	
! 	return _("NT_LWPSTATUS (lwpstatus_t structure)");
!       case NT_LWPSINFO:	
! 	return _("NT_LWPSINFO (lwpsinfo_t structure)");
!       case NT_WIN32PSTATUS: 
! 	return _("NT_WIN32PSTATUS (win32_pstatus structure)");
!       default:
! 	break;
!       }
!   else
!     switch (e_type)
!       {
!       case NT_VERSION:
! 	return _("NT_VERSION (version)");
!       case NT_ARCH:
! 	return _("NT_ARCH (architecture)");
!       default:
! 	break;
!       }
! 
!   sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
!   return buff;
  }
  
  static const char *
  get_netbsd_elfcore_note_type (unsigned e_type)
  {
*************** process_corefile_note_segments (FILE *fi
*** 10563,10590 ****
  
    return res;
  }
  
  static int
! process_corefile_contents (FILE *file)
  {
    /* If we have not been asked to display the notes then do nothing.  */
    if (! do_notes)
      return 1;
  
!   /* If file is not a core file then exit.  */
!   if (elf_header.e_type != ET_CORE)
!     return 1;
! 
!   /* No program headers means no NOTE segment.  */
!   if (elf_header.e_phnum == 0)
      {
!       printf (_("No note segments present in the core file.\n"));
!       return 1;
!    }
! 
!   return process_corefile_note_segments (file);
  }
  
  static int
  process_arch_specific (FILE *file)
  {
--- 10588,10633 ----
  
    return res;
  }
  
  static int
! process_note_sections (FILE *file)
! {
!   Elf_Internal_Shdr *section;
!   unsigned long i;
!   int res = 1;
! 
!   for (i = 0, section = section_headers;
!        i < elf_header.e_shnum;
!        i++, section++)
!     if (section->sh_type == SHT_NOTE)
!       res &= process_corefile_note_segment (file,
! 					    (bfd_vma) section->sh_offset,
! 					    (bfd_vma) section->sh_size);
! 
!   return res;
! }
! 
! static int
! process_notes (FILE *file)
  {
    /* If we have not been asked to display the notes then do nothing.  */
    if (! do_notes)
      return 1;
  
!   if (elf_header.e_type == ET_CORE)
      {
!       /* No program headers means no NOTE segment.  */
!       if (elf_header.e_phnum == 0)
! 	{
! 	  printf (_("No note segments present in the core file.\n"));
! 	  return 1;
! 	}
!       return process_corefile_note_segments (file);
!     }
!   else
!     return process_note_sections (file);
  }
  
  static int
  process_arch_specific (FILE *file)
  {
*************** process_object (char *file_name, FILE *f
*** 10749,10759 ****
  
    process_version_sections (file);
  
    process_section_contents (file);
  
!   process_corefile_contents (file);
  
    process_gnu_liblist (file);
  
    process_arch_specific (file);
  
--- 10792,10802 ----
  
    process_version_sections (file);
  
    process_section_contents (file);
  
!   process_notes (file);
  
    process_gnu_liblist (file);
  
    process_arch_specific (file);
  
Index: doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.58
diff -c -5 -p -r1.58 binutils.texi
*** doc/binutils.texi	8 Oct 2004 14:54:04 -0000	1.58
--- doc/binutils.texi	26 Oct 2004 02:11:29 -0000
*************** Displays the entries in symbol table sec
*** 3223,3234 ****
  @itemx --headers
  Display all the headers in the file.  Equivalent to @option{-h -l -S}.
  
  @item -n
  @itemx --notes
! @cindex ELF core notes
! Displays the contents of the NOTE segment, if it exists.
  
  @item -r
  @itemx --relocs
  @cindex ELF reloc information
  Displays the contents of the file's relocation section, if it has one.
--- 3223,3234 ----
  @itemx --headers
  Display all the headers in the file.  Equivalent to @option{-h -l -S}.
  
  @item -n
  @itemx --notes
! @cindex ELF notes
! Displays the contents of the NOTE segments and/or sections, if any.
  
  @item -r
  @itemx --relocs
  @cindex ELF reloc information
  Displays the contents of the file's relocation section, if it has one.


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