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: Print out bits of SOM headers


In investigating a problem on PA HP-UX, I added some code to som.c to
print out some bits from the SOM headers.  In particular, we can now
get accurate information about the "Exec Auxililary Header".  I've
tested this code lightly.

I'm not terribly attached to this patch, but, having done it, I'm
posting it.  OK to commit?

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

2004-11-08  Mark Mitchell  <mark@codesourcery.com>

	* som.c (som_bfd_print_private_bfd_data): New function.
	(som_object_setup): Save the auxiliary header.  Don't assume that
	zero is an invalid entry point for a shared library.
	(som_object_p): Allocate the auxiliary header on the heap.

Index: som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.48
diff -c -5 -p -r1.48 som.c
*** som.c	9 Oct 2004 02:51:31 -0000	1.48
--- som.c	8 Nov 2004 22:14:05 -0000
*************** static bfd_boolean som_bfd_copy_private_
*** 194,203 ****
--- 194,205 ----
    PARAMS ((bfd *, bfd *));
  #define som_bfd_copy_private_header_data \
    _bfd_generic_bfd_copy_private_header_data
  #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
  #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
+ static bfd_boolean som_bfd_print_private_bfd_data
+   PARAMS ((bfd *, void *));
  static bfd_boolean som_bfd_is_local_label_name
    PARAMS ((bfd *, const char *));
  static bfd_boolean som_set_section_contents
    PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
  static bfd_boolean som_get_section_contents
*************** som_object_setup (abfd, file_hdrp, aux_h
*** 1770,1780 ****
       struct header *file_hdrp;
       struct som_exec_auxhdr *aux_hdrp;
       unsigned long current_offset;
  {
    asection *section;
-   int found;
  
    /* som_mkobject will set bfd_error if som_mkobject fails.  */
    if (! som_mkobject (abfd))
      return 0;
  
--- 1772,1781 ----
*************** som_object_setup (abfd, file_hdrp, aux_h
*** 1808,1817 ****
--- 1809,1821 ----
  
      default:
        break;
      }
  
+   /* Save the auxiliary header.  */
+   obj_som_exec_hdr (abfd) = aux_hdrp;
+ 
    /* Allocate space to hold the saved exec header information.  */
    obj_som_exec_data (abfd) = (struct som_exec_data *)
      bfd_zalloc (abfd, (bfd_size_type) sizeof (struct som_exec_data));
    if (obj_som_exec_data (abfd) == NULL)
      return NULL;
*************** som_object_setup (abfd, file_hdrp, aux_h
*** 1822,1857 ****
       apparently the latest HPUX linker is using NEW_VERSION_ID now.
  
       It's about time, OSF has used the new id since at least 1992;
       HPUX didn't start till nearly 1995!.
  
!      The new approach examines the entry field.  If it's zero or not 4
!      byte aligned then it's not a proper code address and we guess it's
!      really the executable flags.  */
!   found = 0;
!   for (section = abfd->sections; section; section = section->next)
      {
!       bfd_vma entry;
  
!       if ((section->flags & SEC_CODE) == 0)
! 	continue;
!       entry = aux_hdrp->exec_entry;
!       if (entry >= section->vma
! 	  && entry < section->vma + section->size)
! 	found = 1;
!     }
!   if (aux_hdrp->exec_entry == 0
!       || (aux_hdrp->exec_entry & 0x3) != 0
!       || ! found)
!     {
!       bfd_get_start_address (abfd) = aux_hdrp->exec_flags;
!       obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_entry;
!     }
!   else
!     {
!       bfd_get_start_address (abfd) = aux_hdrp->exec_entry + current_offset;
!       obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_flags;
      }
  
    obj_som_exec_data (abfd)->version_id = file_hdrp->version_id;
  
    bfd_default_set_arch_mach (abfd, bfd_arch_hppa, pa10);
--- 1826,1869 ----
       apparently the latest HPUX linker is using NEW_VERSION_ID now.
  
       It's about time, OSF has used the new id since at least 1992;
       HPUX didn't start till nearly 1995!.
  
!      The new approach examines the entry field for an executable.  If
!      it is not 4-byte aligned then it's not a proper code address and
!      we guess it's really the executable flags.  For a main program,
!      we also consider zero to be indicative of a buggy linker, since
!      that is not a valid entry point.  The entry point for a shared
!      library, however, can be zero so we do not consider that to be
!      indicative of a buggy linker.  */
!   if (aux_hdrp)
      {
!       int found = 0;
  
!       for (section = abfd->sections; section; section = section->next)
! 	{
! 	  bfd_vma entry;
! 
! 	  if ((section->flags & SEC_CODE) == 0)
! 	    continue;
! 	  entry = aux_hdrp->exec_entry + aux_hdrp->exec_tmem;
! 	  if (entry >= section->vma
! 	      && entry < section->vma + section->size)
! 	    found = 1;
! 	}
!       if ((aux_hdrp->exec_entry == 0 && !(abfd->flags & DYNAMIC))
! 	  || (aux_hdrp->exec_entry & 0x3) != 0
! 	  || ! found)
! 	{
! 	  bfd_get_start_address (abfd) = aux_hdrp->exec_flags;
! 	  obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_entry;
! 	}
!       else
! 	{
! 	  bfd_get_start_address (abfd) = aux_hdrp->exec_entry + current_offset;
! 	  obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_flags;
! 	}
      }
  
    obj_som_exec_data (abfd)->version_id = file_hdrp->version_id;
  
    bfd_default_set_arch_mach (abfd, bfd_arch_hppa, pa10);
*************** setup_sections (abfd, file_hdr, current_
*** 2181,2191 ****
  static const bfd_target *
  som_object_p (abfd)
       bfd *abfd;
  {
    struct header file_hdr;
!   struct som_exec_auxhdr aux_hdr;
    unsigned long current_offset = 0;
    struct lst_header lst_header;
    struct som_entry som_entry;
    bfd_size_type amt;
  #define ENTRY_SIZE sizeof (struct som_entry)
--- 2193,2203 ----
  static const bfd_target *
  som_object_p (abfd)
       bfd *abfd;
  {
    struct header file_hdr;
!   struct som_exec_auxhdr *aux_hdr = NULL;
    unsigned long current_offset = 0;
    struct lst_header lst_header;
    struct som_entry som_entry;
    bfd_size_type amt;
  #define ENTRY_SIZE sizeof (struct som_entry)
*************** som_object_p (abfd)
*** 2293,2307 ****
      }
  
    /* If the aux_header_size field in the file header is zero, then this
       object is an incomplete executable (a .o file).  Do not try to read
       a non-existant auxiliary header.  */
-   memset (&aux_hdr, 0, sizeof (struct som_exec_auxhdr));
    if (file_hdr.aux_header_size != 0)
      {
        amt = AUX_HDR_SIZE;
!       if (bfd_bread ((PTR) &aux_hdr, amt, abfd) != amt)
  	{
  	  if (bfd_get_error () != bfd_error_system_call)
  	    bfd_set_error (bfd_error_wrong_format);
  	  return 0;
  	}
--- 2305,2323 ----
      }
  
    /* If the aux_header_size field in the file header is zero, then this
       object is an incomplete executable (a .o file).  Do not try to read
       a non-existant auxiliary header.  */
    if (file_hdr.aux_header_size != 0)
      {
+       aux_hdr = ((struct som_exec_auxhdr *)
+ 		 bfd_zalloc (abfd, 
+ 			     (bfd_size_type) sizeof (struct som_exec_auxhdr)));
+       if (aux_hdr == NULL)
+ 	return NULL;
        amt = AUX_HDR_SIZE;
!       if (bfd_bread ((PTR) aux_hdr, amt, abfd) != amt)
  	{
  	  if (bfd_get_error () != bfd_error_system_call)
  	    bfd_set_error (bfd_error_wrong_format);
  	  return 0;
  	}
*************** som_object_p (abfd)
*** 2313,2323 ****
        bfd_set_error (bfd_error_bad_value);
        return 0;
      }
  
    /* This appears to be a valid SOM object.  Do some initialization.  */
!   return som_object_setup (abfd, &file_hdr, &aux_hdr, current_offset);
  }
  
  /* Create a SOM object.  */
  
  static bfd_boolean
--- 2329,2339 ----
        bfd_set_error (bfd_error_bad_value);
        return 0;
      }
  
    /* This appears to be a valid SOM object.  Do some initialization.  */
!   return som_object_setup (abfd, &file_hdr, aux_hdr, current_offset);
  }
  
  /* Create a SOM object.  */
  
  static bfd_boolean
*************** som_bfd_copy_private_bfd_data (ibfd, obf
*** 5240,5249 ****
--- 5256,5310 ----
  	  sizeof (struct som_exec_data));
  
    return TRUE;
  }
  
+ /* Display the SOM header.  */
+ 
+ static bfd_boolean
+ som_bfd_print_private_bfd_data (abfd, farg)
+      bfd *abfd;
+      void *farg;
+ {
+   struct som_exec_auxhdr *exec_header;
+   struct aux_id* auxhdr;
+   FILE *f;
+ 
+   f = (FILE *) farg;
+ 
+   exec_header = obj_som_exec_hdr (abfd);
+   if (exec_header)
+     {
+       fprintf (f, _("\nExec Auxiliary Header\n"));
+       fprintf (f, "  flags              ");
+       auxhdr = &exec_header->som_auxhdr;
+       if (auxhdr->mandatory)
+ 	fprintf (f, "mandatory ");
+       if (auxhdr->copy)
+ 	fprintf (f, "copy ");
+       if (auxhdr->append)
+ 	fprintf (f, "append ");
+       if (auxhdr->ignore)
+ 	fprintf (f, "ignore ");
+       fprintf (f, "\n");
+       fprintf (f, "  type               %#x\n", auxhdr->type);
+       fprintf (f, "  length             %#x\n", auxhdr->length);
+       fprintf (f, "  text size          %#x\n", exec_header->exec_tsize);
+       fprintf (f, "  text memory offset %#x\n", exec_header->exec_tmem);
+       fprintf (f, "  text file offset   %#x\n", exec_header->exec_tfile);
+       fprintf (f, "  data size          %#x\n", exec_header->exec_dsize);
+       fprintf (f, "  data memory offset %#x\n", exec_header->exec_dmem);
+       fprintf (f, "  data file offset   %#x\n", exec_header->exec_dfile);
+       fprintf (f, "  bss size           %#x\n", exec_header->exec_bsize);
+       fprintf (f, "  entry point        %#x\n", exec_header->exec_entry);
+       fprintf (f, "  loader flags       %#x\n", exec_header->exec_flags);
+       fprintf (f, "  bss initializer    %#x\n", exec_header->exec_bfill);
+     }
+ 
+   return TRUE;
+ }
+ 
  /* Set backend info for sections which can not be described
     in the BFD data structures.  */
  
  bfd_boolean
  bfd_som_set_section_attributes (section, defined, private, sort_key, spnum)
*************** som_bfd_link_split_section (abfd, sec)
*** 6398,6408 ****
  #define som_truncate_arname		bfd_bsd_truncate_arname
  #define som_slurp_extended_name_table	_bfd_slurp_extended_name_table
  #define som_construct_extended_name_table \
    _bfd_archive_coff_construct_extended_name_table
  #define som_update_armap_timestamp	bfd_true
- #define som_bfd_print_private_bfd_data  _bfd_generic_bfd_print_private_bfd_data
  
  #define som_bfd_is_target_special_symbol \
    ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  #define som_get_lineno			_bfd_nosymbols_get_lineno
  #define som_bfd_make_debug_symbol	_bfd_nosymbols_bfd_make_debug_symbol
--- 6459,6468 ----


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