From 20cfcaae7be9de914b81b35ff98317e33695a60c Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 26 Nov 1999 09:52:23 +0000 Subject: Add support for target specific processing of ELF segments --- bfd/ChangeLog | 19 +++++++++++++++ bfd/elf-bfd.h | 8 +++++++ bfd/elf.c | 68 ++++++++++++++++++++++++++++++++++++++++-------------- bfd/elfxx-target.h | 4 ++++ 4 files changed, 82 insertions(+), 17 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e3cf879..d82166a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,22 @@ +1999-11-26 Fred Fish + + * 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. + 1999-11-25 Nick Clifton * coff-arm.c (bfd_arm_get_bfd_for_interworking): Add diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 8256b2f..2be74c1 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -388,6 +388,12 @@ struct elf_backend_data 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. */ @@ -945,6 +951,8 @@ extern boolean bfd_elf_mkcorefile PARAMS ((bfd *)); 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 diff --git a/bfd/elf.c b/bfd/elf.c index ccfb00e..d957476 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -53,6 +53,7 @@ static boolean assign_section_numbers PARAMS ((bfd *)); 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 @@ -1387,31 +1388,20 @@ _bfd_elf_new_section_hook (abfd, sec) */ boolean -bfd_section_from_phdr (abfd, hdr, index) +_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 *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) @@ -1467,6 +1457,52 @@ bfd_section_from_phdr (abfd, hdr, index) 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. */ @@ -5308,6 +5344,8 @@ elfcore_read_notes (abfd, offset, size) } +/* 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) @@ -5318,10 +5356,6 @@ _bfd_elfcore_section_from_phdr (abfd, phdr, sec_num) 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; } diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 2e7579b..0a69dd8 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -237,6 +237,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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 @@ -358,6 +361,7 @@ static CONST struct elf_backend_data elfNN_bed = 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, -- cgit v1.1