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]

patch for BFD ELF support


Currently BFD provides for ELF targets to have target specific
processing for non-generic type ELF sections.  This patch (which lays
the foundation for some target specific corefile processing) provides
the same functionality for non-generic type ELF segments.

If this patch is accepted, I'll provide another patch that removes
_bfd_elfcore_section_from_phdr, which is now just as stub, as noted
by the FIXME.  Unless of course there is some other non-obvious 
reason to keep it.

-Fred

===================================================================

  1999-10-18  Fred Fish  <fnf@cygnus.com>

	* elf.c (elfcore_read_notes): Add prototype for static function.
	(_bfd_elf_make_section_from_phdr): Renamed from bfd_section_from_phdr.
	(bfd_section_from_phdr): Replacement function that calls
	_bfd_elf_make_section_from_phdr for generic segment types and
	backend fucntion pointed to by elf_backend_section_from_phdr for
	backend specific segment types.
	(_bfd_elfcore_section_from_phdr): Remove call to elfcore_read_notes,
	now called by _bfd_elf_make_section_from_phdr.  Note that this func
	is now just a stub between the caller and bfd_section_from_phdr.
	* elf-bfd.h (struct elf_backend_data): Add new function pointer
	elf_backend_section_from_phdr.
	(elf_backend_section_from_phdr): Add prototype.
	* elfxx-target.h (elf_backend_section_from_phdr): Define default.
	(elfNN_bed): Add elf_backend_section_from_phdr.
	

Index: elf-bfd.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf-bfd.h,v
retrieving revision 1.14
diff -c -p -r1.14 elf-bfd.h
*** elf-bfd.h	1999/09/04 16:26:08	1.14
--- elf-bfd.h	1999/10/18 21:52:17
*************** struct elf_backend_data
*** 400,405 ****
--- 400,411 ----
  						    Elf32_Internal_Shdr *,
  						    char *));
  
+   /* A function to handle unusual program segment types when creating BFD
+      sections from ELF program segments. */
+   boolean (*elf_backend_section_from_phdr) PARAMS ((bfd *,
+ 						    Elf32_Internal_Phdr *,
+ 						    int));
+ 
    /* A function to set up the ELF section header for a BFD section in
       preparation for writing it out.  This is where the flags and type
       fields are set for unusual sections.  */
*************** extern boolean bfd_elf_mkcorefile PARAMS
*** 941,946 ****
--- 947,954 ----
  extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *));
  extern boolean _bfd_elf_make_section_from_shdr
    PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, const char *name));
+ extern boolean _bfd_elf_make_section_from_phdr
+   PARAMS ((bfd *abfd, Elf_Internal_Phdr *hdr, int index, const char *typename));
  extern struct bfd_hash_entry *_bfd_elf_link_hash_newfunc
    PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
  extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
Index: elf.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf.c,v
retrieving revision 1.17
diff -c -p -r1.17 elf.c
*** elf.c	1999/09/24 17:06:35	1.17
--- elf.c	1999/10/18 21:53:14
*************** static boolean assign_section_numbers PA
*** 53,58 ****
--- 53,59 ----
  static INLINE int sym_is_global PARAMS ((bfd *, asymbol *));
  static boolean elf_map_symbols PARAMS ((bfd *));
  static bfd_size_type get_program_header_size PARAMS ((bfd *));
+ static boolean elfcore_read_notes PARAMS ((bfd *, bfd_vma, bfd_vma));
  
  /* Swap version information in and out.  The version information is
     currently size independent.  If that ever changes, this code will
*************** _bfd_elf_new_section_hook (abfd, sec)
*** 1387,1417 ****
   */
  
  boolean
! bfd_section_from_phdr (abfd, hdr, index)
       bfd *abfd;
       Elf_Internal_Phdr *hdr;
       int index;
  {
    asection *newsect;
    char *name;
-   char *typename;
    char namebuf[64];
    int split;
  
    split = ((hdr->p_memsz > 0)
  	    && (hdr->p_filesz > 0)
  	    && (hdr->p_memsz > hdr->p_filesz));
-   switch (hdr->p_type)
-     {
-     case PT_NULL: typename = "null"; break;
-     case PT_LOAD: typename = "load"; break;
-     case PT_DYNAMIC: typename = "dynamic"; break;
-     case PT_INTERP: typename = "interp"; break;
-     case PT_NOTE: typename = "note"; break;
-     case PT_SHLIB: typename = "shlib"; break;
-     case PT_PHDR: typename = "phdr"; break;
-     default: typename = "segment"; break;
-     }
    sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : "");
    name = bfd_alloc (abfd, strlen (namebuf) + 1);
    if (!name)
--- 1388,1407 ----
   */
  
  boolean
! _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename)
       bfd *abfd;
       Elf_Internal_Phdr *hdr;
       int index;
+      const char *typename;
  {
    asection *newsect;
    char *name;
    char namebuf[64];
    int split;
  
    split = ((hdr->p_memsz > 0)
  	    && (hdr->p_filesz > 0)
  	    && (hdr->p_memsz > hdr->p_filesz));
    sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : "");
    name = bfd_alloc (abfd, strlen (namebuf) + 1);
    if (!name)
*************** bfd_section_from_phdr (abfd, hdr, index)
*** 1467,1472 ****
--- 1457,1508 ----
    return true;
  }
  
+ boolean
+ bfd_section_from_phdr (abfd, hdr, index)
+      bfd *abfd;
+      Elf_Internal_Phdr *hdr;
+      int index;
+ {
+   struct elf_backend_data *bed;
+ 
+   switch (hdr->p_type)
+     {
+     case PT_NULL:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "null");
+ 
+     case PT_LOAD:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "load");
+ 
+     case PT_DYNAMIC:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "dynamic");
+ 
+     case PT_INTERP:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "interp");
+ 
+     case PT_NOTE:
+       if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note"))
+ 	return false;
+       if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
+ 	return false;
+       return true;
+ 
+     case PT_SHLIB:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "shlib");
+ 
+     case PT_PHDR:
+       return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "phdr");
+ 
+     default:
+       /* Check for any processor-specific program segment types.
+          If no handler for them, default to making "segment" sections. */
+       bed = get_elf_backend_data (abfd);
+       if (bed->elf_backend_section_from_phdr)
+ 	return (*bed->elf_backend_section_from_phdr) (abfd, hdr, index);
+       else
+ 	return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "segment");
+     }
+ }
+ 
  /* Initialize REL_HDR, the section-header for new section, containing
     relocations against ASECT.  If USE_RELA_P is true, we use RELA
     relocations; otherwise, we use REL relocations.  */
*************** elfcore_read_notes (abfd, offset, size)
*** 5308,5313 ****
--- 5344,5351 ----
  }
  
  
+ /* FIXME: This function is now unnecessary.  Callers can just call
+    bfd_section_from_phdr directly.  */
  
  boolean
  _bfd_elfcore_section_from_phdr (abfd, phdr, sec_num)
*************** _bfd_elfcore_section_from_phdr (abfd, ph
*** 5317,5327 ****
  {
    if (! bfd_section_from_phdr (abfd, phdr, sec_num))
      return false;
- 
-   if (phdr->p_type == PT_NOTE
-       && ! elfcore_read_notes (abfd, phdr->p_offset, phdr->p_filesz))
-     return false;
- 
    return true;
  }
  
--- 5355,5360 ----
Index: elfxx-target.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elfxx-target.h,v
retrieving revision 1.9
diff -c -p -r1.9 elfxx-target.h
*** elfxx-target.h	1999/07/30 21:34:44	1.9
--- elfxx-target.h	1999/10/18 21:53:24
*************** Foundation, Inc., 59 Temple Place - Suit
*** 237,242 ****
--- 237,245 ----
  #ifndef elf_backend_section_from_shdr
  #define elf_backend_section_from_shdr	0
  #endif
+ #ifndef elf_backend_section_from_phdr
+ #define elf_backend_section_from_phdr	0
+ #endif
  #ifndef elf_backend_fake_sections
  #define elf_backend_fake_sections	0
  #endif
*************** static CONST struct elf_backend_data elf
*** 356,361 ****
--- 359,365 ----
    elf_backend_get_symbol_type,
    elf_backend_section_processing,
    elf_backend_section_from_shdr,
+   elf_backend_section_from_phdr,
    elf_backend_fake_sections,
    elf_backend_section_from_bfd_section,
    elf_backend_add_symbol_hook,


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