From 7798f77b62fe6e2c660ce3cbb5a8b4575db3698c Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 12 Feb 2008 11:32:31 +0000 Subject: [PATCH] PR ld/5692 * elf-bfd.h (enum elf_object_id): New enum, used to identify target specific extensions to the elf_obj_tdata structure. (struct elf_obj_tdata): New field 'object_id'. (elf_object_id, elf_program_header_size, elf_symtab_hdr): New macros for accessing fields in the elf_obj_tdata structure. (bfd_elf_mkobject): Rename to bfd_elf_make_generic_object. (bfd_elf_allocate_object): New function. * elf.c (bfd_elf_mkobject): Rename to bfd_elf_make_generic_object and implement by calling bfd_elf_allocate_object. (bfd_elf_allocate_object): New function: Allocates an elf_obj_tdata structure, possibly with a target specific extension. * elfxx-target.h (bfd_elfNN_mkobject): Use bfd_elf_make_generic_object as the default value. * elf32-arm.c (elf32_arm_obj_tdata): Rename to elf_arm_obj_tdata for consistency with other, similar structures. (is_arm_elf): New macro. Checks a BFD to make sure that is an ARM ELF bfd. (elf32_arm_mkobject): Call bfd_elf_allocate_object. (bfd_elf32_arm_vfp11_erratum_scan): Use is_arm_elf macro to check the bfd being processed. (bfd_elf32_arm_vfp11_fix_veneer_locations): Likewise. (bfd_elf32_arm_set_target_relocs): Likewise. (bfd_elf32_arm_final_link_relocate): Likewise. (bfd_elf32_arm_copy_private_bfd_data): Likewise. (bfd_elf32_arm_merge_eabi_attributes): Likewise. (bfd_elf32_arm_merge_private_bfd_data): Likewise. (bfd_elf32_arm_check_relocs): Likewise. (bfd_elf32_arm_gc_mark_extra_sections): Likewise. (bfd_elf32_arm_size_dynamic_sections): Likewise. (bfd_elf32_arm_process_before_allocation): Use elf_symtab_hdr. (bfd_elf32_arm_init_maps): Likewise. (bfd_elf32_arm_final_link_relocate): Likewise. (bfd_elf32_arm_relocate_section): Likewise. (bfd_elf32_arm_gc_sweep_hook): Likewise. (bfd_elf32_arm_check_relocs): Likewise. (bfd_elf32_arm_size_dynamic_sections): Likewise. * elf32-i386.c (elf_i386_mkobject): Call bfd_elf_allocate_object. (is_i386_elf): New macro. Checks a BFD to make sure that is an x86 ELF bfd. (elf_i386_check_relocs): Use is_i386_elf macro to check the bfd being processed. (elf_i386_size_dynamic_sections): Likewise. (elf_i386_relocate_section): Likewise. (elf_i386_check_relocs): Use elf_symtab_hdr. (elf_i386_gc_sweep_hook): Likewise. (elf_i386_size_dynamic_sections): Likewise. (elf_i386_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_mkobject): Call bfd_elf_allocate_object. (elf_create_pointer_linker_section): Use is_ppc_elf_target to verify that the bfd before accessing target specific fields. (ppc_elf_check_relocs): Likewise. (elf_finish_pointer_linker_section): Likewise. (elf_create_pointer_linker_section): Use elf_symtab_hdr. (ppc_elf_check_relocs): Likewise. (ppc_elf_gc_sweep_hook): Likewise. (ppc_elf_tls_optimize): Likewise. (ppc_elf_size_dynamic_sections): Likewise. (ppc_elf_relax_section): Likewise. (ppc_elf_relocate_section): Likewise. * elf32-s390.c (struct elf_s390_obj_tdata): Add a comment reminding programmers to keep this structure in sync with the one defined in elf64-s390.c. (elf_s390_mkobject): Call bfd_elf_allocate_object. (is_s390_elf): New macro. Checks a BFD to make sure that is an s390 ELF bfd. (elf_s390_check_relocs): Use is_s390_elf macro to check the bfd being processed. (elf_s390_size_dynamic_sections): Likewise. (elf_s390_relocate_section): Likewise. (elf_s390_check_relocs): Use elf_symtab_hdr. (elf_s390_gc_sweep_hook): Likewise. (elf_s390_size_dynamic_sections): Likewise. (elf_s390_relocate_section): Likewise. * elf32-sh.c (sh_elf_mkobject): Call bfd_elf_allocate_object. (is_sh_elf): New macro. Checks a BFD to make sure that is an SH ELF bfd. (sh_elf_size_dynamic_sections): Use is_sh_elf macro to check the bfd being processed. (sh_elf_relocate_section): Likewise. (sh_elf_check_relocs): Likewise. (sh_elf_copy_private_data): Likewise. (sh_elf_relax_section): Use elf_symtab_hdr. (sh_elf_size_dynamic_sections): Likewise. (sh_elf_relocate_section): Likewise. (sh_elf_get_relocated_section_contents): Likewise. (sh_elf_gc_sweep_hook): Likewise. (sh_elf_check_relocs): Likewise. * elf64-alpha.c (elf64_alpha_mkobject): Call bfd_elf_allocate_object. (is_alpha_elf): New macro. Checks a BFD to make sure that is an Alpha ELF bfd. (elf64_alpha_create_got_section): Use is_alpha_elf macro to check the bfd being processed. (elf64_alpha_create_dynamic_section): Likewise. (elf64_alpha_check_relocs): Likewise. (elf64_alpha_size_got_sections): Likewise. (elf64_alpha_relax_section): Likewise. (elf64_alpha_relocate_section): Likewise. (elf64_alpha_final_link): Likewise. (elf64_alpha_check_relocs): Use elf_symtab_hdr. (elf64_alpha_relax_section): Likewise. (elf64_alpha_relocate_section_r): Likewise. (elf64_alpha_relocate_section): Likewise. * elf64-ppc.c (ppc64_elf_mkobject): Call bfd_elf_allocate_object. (ppc64_elf_check_relocs): Use is_ppc64_elf_target to check the bfd being processed. (opd_entry_value): Likewise. (allocate_dynrelocs): Likewise. (ppc64_elf_relocate_section): Likewise. (ppc64_elf_check_relocs): Use elf_symtab_hdr. (opd_entry_value): Likewise. (ppc64_elf_gc_sweep_hook): Likewise. (get_sym_h): Likewise. (ppc64_elf_edit_opd): Likewise. (ppc64_elf_tls_optimize): Likewise. (ppc64_elf_edit_toc): Likewise. (ppc64_elf_size_dynamic_sections): Likewise. (toc_adjusting_stub_needed): Likewise. (ppc64_elf_size_stubs): Likewise. (ppc64_elf_relocate_section): Likewise. * elf64-s390.c (struct elf_s390_obj_tdata): Add a comment reminding programmers to keep this structure in sync with the one defined in elf32-s390.c. (elf_s390_mkobject): Call bfd_elf_allocate_object. (is_s390_elf): New macro. Checks a BFD to make sure that is an s390 ELF bfd. (elf_s390_check_relocs): Use is_s390_elf macro to check the bfd being processed. (elf_s390_size_dynamic_sections): Likewise. (elf_s390_relocate_section): Likewise. (elf_s390_check_relocs): Use elf_symtab_hdr. (elf_s390_gc_sweep_hook): Likewise. (elf_s390_size_dynamic_sections): Likewise. (elf_s390_relocate_section): Likewise. * elf64-x86_64.c (elf64_x86_64_mkobject): Call bfd_elf_allocate_object. (is_x86_64_elf): New macro. Checks a BFD to make sure that is an x86_64 ELF bfd. (elf64_x86_64_check_relocs): Use is_x86_64_elf macro to check the bfd being processed. (elf64_x86_64_size_dynamic_sections): Likewise. (elf64_x86_64_relocate_section): Likewise. (elf64_x86_64_check_relocs): Use elf_symtab_hdr. (elf64_x86_64_gc_sweep_hook): Likewise. (elf64_x86_64_size_dynamic_sections): Likewise. (elf64_x86_64_relocate_section): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_mkobject): Call bfd_elf_allocate_object. (is_sparc_elf): New macro. Checks a BFD to make sure that is a Sparc ELF bfd. (_bfd_sparc_elf_check_relocs): Use is_sparc_elf macro to check the bfd being processed. (_bfd_sparc_elf_gc_sweep_hook): Likewise. (_bfd_sparc_elf_size_dynamic_sections): Likewise. (_bfd_sparc_elf_check_relocs): Use elf_symtab_hdr. (_bfd_sparc_elf_gc_sweep_hook): Likewise. (_bfd_sparc_elf_size_dynamic_sections): Likewise. (_bfd_sparc_elf_relocate_section): Likewise. --- bfd/ChangeLog | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bfd/elf-bfd.h | 30 +++++++++- bfd/elf.c | 32 ++++++++--- bfd/elf32-arm.c | 78 +++++++++++++------------- bfd/elf32-i386.c | 31 ++++++----- bfd/elf32-ppc.c | 31 +++++------ bfd/elf32-s390.c | 35 +++++++----- bfd/elf32-sh.c | 47 ++++++++-------- bfd/elf64-alpha.c | 67 +++++++++++++--------- bfd/elf64-ppc.c | 53 ++++++++++-------- bfd/elf64-s390.c | 35 +++++++----- bfd/elf64-x86-64.c | 41 +++++++------- bfd/elfxx-sparc.c | 32 ++++++----- bfd/elfxx-target.h | 2 +- 14 files changed, 457 insertions(+), 217 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0cd08bd9e..a283f597d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,163 @@ +2008-02-12 Nick Clifton + + PR ld/5692 + * elf-bfd.h (enum elf_object_id): New enum, used to identify + target specific extensions to the elf_obj_tdata structure. + (struct elf_obj_tdata): New field 'object_id'. + (elf_object_id, elf_program_header_size, elf_symtab_hdr): New + macros for accessing fields in the elf_obj_tdata structure. + (bfd_elf_mkobject): Rename to bfd_elf_make_generic_object. + (bfd_elf_allocate_object): New function. + * elf.c (bfd_elf_mkobject): Rename to bfd_elf_make_generic_object + and implement by calling bfd_elf_allocate_object. + (bfd_elf_allocate_object): New function: Allocates an + elf_obj_tdata structure, possibly with a target specific + extension. + * elfxx-target.h (bfd_elfNN_mkobject): Use + bfd_elf_make_generic_object as the default value. + * elf32-arm.c (elf32_arm_obj_tdata): Rename to elf_arm_obj_tdata + for consistency with other, similar structures. + (is_arm_elf): New macro. Checks a BFD to make sure that is an ARM + ELF bfd. + (elf32_arm_mkobject): Call bfd_elf_allocate_object. + (bfd_elf32_arm_vfp11_erratum_scan): Use is_arm_elf macro to check + the bfd being processed. + (bfd_elf32_arm_vfp11_fix_veneer_locations): Likewise. + (bfd_elf32_arm_set_target_relocs): Likewise. + (bfd_elf32_arm_final_link_relocate): Likewise. + (bfd_elf32_arm_copy_private_bfd_data): Likewise. + (bfd_elf32_arm_merge_eabi_attributes): Likewise. + (bfd_elf32_arm_merge_private_bfd_data): Likewise. + (bfd_elf32_arm_check_relocs): Likewise. + (bfd_elf32_arm_gc_mark_extra_sections): Likewise. + (bfd_elf32_arm_size_dynamic_sections): Likewise. + (bfd_elf32_arm_process_before_allocation): Use elf_symtab_hdr. + (bfd_elf32_arm_init_maps): Likewise. + (bfd_elf32_arm_final_link_relocate): Likewise. + (bfd_elf32_arm_relocate_section): Likewise. + (bfd_elf32_arm_gc_sweep_hook): Likewise. + (bfd_elf32_arm_check_relocs): Likewise. + (bfd_elf32_arm_size_dynamic_sections): Likewise. + * elf32-i386.c (elf_i386_mkobject): Call bfd_elf_allocate_object. + (is_i386_elf): New macro. Checks a BFD to make sure that is an x86 + ELF bfd. + (elf_i386_check_relocs): Use is_i386_elf macro to check the bfd + being processed. + (elf_i386_size_dynamic_sections): Likewise. + (elf_i386_relocate_section): Likewise. + (elf_i386_check_relocs): Use elf_symtab_hdr. + (elf_i386_gc_sweep_hook): Likewise. + (elf_i386_size_dynamic_sections): Likewise. + (elf_i386_relocate_section): Likewise. + * elf32-ppc.c (ppc_elf_mkobject): Call bfd_elf_allocate_object. + (elf_create_pointer_linker_section): Use is_ppc_elf_target to + verify that the bfd before accessing target specific fields. + (ppc_elf_check_relocs): Likewise. + (elf_finish_pointer_linker_section): Likewise. + (elf_create_pointer_linker_section): Use elf_symtab_hdr. + (ppc_elf_check_relocs): Likewise. + (ppc_elf_gc_sweep_hook): Likewise. + (ppc_elf_tls_optimize): Likewise. + (ppc_elf_size_dynamic_sections): Likewise. + (ppc_elf_relax_section): Likewise. + (ppc_elf_relocate_section): Likewise. + * elf32-s390.c (struct elf_s390_obj_tdata): Add a comment + reminding programmers to keep this structure in sync with the one + defined in elf64-s390.c. + (elf_s390_mkobject): Call bfd_elf_allocate_object. + (is_s390_elf): New macro. Checks a BFD to make sure that is an s390 + ELF bfd. + (elf_s390_check_relocs): Use is_s390_elf macro to check the bfd + being processed. + (elf_s390_size_dynamic_sections): Likewise. + (elf_s390_relocate_section): Likewise. + (elf_s390_check_relocs): Use elf_symtab_hdr. + (elf_s390_gc_sweep_hook): Likewise. + (elf_s390_size_dynamic_sections): Likewise. + (elf_s390_relocate_section): Likewise. + * elf32-sh.c (sh_elf_mkobject): Call bfd_elf_allocate_object. + (is_sh_elf): New macro. Checks a BFD to make sure that is an SH + ELF bfd. + (sh_elf_size_dynamic_sections): Use is_sh_elf macro to check the + bfd being processed. + (sh_elf_relocate_section): Likewise. + (sh_elf_check_relocs): Likewise. + (sh_elf_copy_private_data): Likewise. + (sh_elf_relax_section): Use elf_symtab_hdr. + (sh_elf_size_dynamic_sections): Likewise. + (sh_elf_relocate_section): Likewise. + (sh_elf_get_relocated_section_contents): Likewise. + (sh_elf_gc_sweep_hook): Likewise. + (sh_elf_check_relocs): Likewise. + * elf64-alpha.c (elf64_alpha_mkobject): Call bfd_elf_allocate_object. + (is_alpha_elf): New macro. Checks a BFD to make sure that is an + Alpha ELF bfd. + (elf64_alpha_create_got_section): Use is_alpha_elf macro to check + the bfd being processed. + (elf64_alpha_create_dynamic_section): Likewise. + (elf64_alpha_check_relocs): Likewise. + (elf64_alpha_size_got_sections): Likewise. + (elf64_alpha_relax_section): Likewise. + (elf64_alpha_relocate_section): Likewise. + (elf64_alpha_final_link): Likewise. + (elf64_alpha_check_relocs): Use elf_symtab_hdr. + (elf64_alpha_relax_section): Likewise. + (elf64_alpha_relocate_section_r): Likewise. + (elf64_alpha_relocate_section): Likewise. + * elf64-ppc.c (ppc64_elf_mkobject): Call bfd_elf_allocate_object. + (ppc64_elf_check_relocs): Use is_ppc64_elf_target to check the bfd + being processed. + (opd_entry_value): Likewise. + (allocate_dynrelocs): Likewise. + (ppc64_elf_relocate_section): Likewise. + (ppc64_elf_check_relocs): Use elf_symtab_hdr. + (opd_entry_value): Likewise. + (ppc64_elf_gc_sweep_hook): Likewise. + (get_sym_h): Likewise. + (ppc64_elf_edit_opd): Likewise. + (ppc64_elf_tls_optimize): Likewise. + (ppc64_elf_edit_toc): Likewise. + (ppc64_elf_size_dynamic_sections): Likewise. + (toc_adjusting_stub_needed): Likewise. + (ppc64_elf_size_stubs): Likewise. + (ppc64_elf_relocate_section): Likewise. + * elf64-s390.c (struct elf_s390_obj_tdata): Add a comment + reminding programmers to keep this structure in sync with the one + defined in elf32-s390.c. + (elf_s390_mkobject): Call bfd_elf_allocate_object. + (is_s390_elf): New macro. Checks a BFD to make sure that is an s390 + ELF bfd. + (elf_s390_check_relocs): Use is_s390_elf macro to check the bfd + being processed. + (elf_s390_size_dynamic_sections): Likewise. + (elf_s390_relocate_section): Likewise. + (elf_s390_check_relocs): Use elf_symtab_hdr. + (elf_s390_gc_sweep_hook): Likewise. + (elf_s390_size_dynamic_sections): Likewise. + (elf_s390_relocate_section): Likewise. + * elf64-x86_64.c (elf64_x86_64_mkobject): Call bfd_elf_allocate_object. + (is_x86_64_elf): New macro. Checks a BFD to make sure that is an + x86_64 ELF bfd. + (elf64_x86_64_check_relocs): Use is_x86_64_elf macro to check the bfd + being processed. + (elf64_x86_64_size_dynamic_sections): Likewise. + (elf64_x86_64_relocate_section): Likewise. + (elf64_x86_64_check_relocs): Use elf_symtab_hdr. + (elf64_x86_64_gc_sweep_hook): Likewise. + (elf64_x86_64_size_dynamic_sections): Likewise. + (elf64_x86_64_relocate_section): Likewise. + * elfxx-sparc.c (_bfd_sparc_elf_mkobject): Call bfd_elf_allocate_object. + (is_sparc_elf): New macro. Checks a BFD to make sure that is a Sparc + ELF bfd. + (_bfd_sparc_elf_check_relocs): Use is_sparc_elf macro to check the + bfd being processed. + (_bfd_sparc_elf_gc_sweep_hook): Likewise. + (_bfd_sparc_elf_size_dynamic_sections): Likewise. + (_bfd_sparc_elf_check_relocs): Use elf_symtab_hdr. + (_bfd_sparc_elf_gc_sweep_hook): Likewise. + (_bfd_sparc_elf_size_dynamic_sections): Likewise. + (_bfd_sparc_elf_relocate_section): Likewise. + 2008-02-12 Alan Modra PR 5303, 5755 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 269b1150f..6dbdac9d3 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1393,6 +1393,24 @@ enum Tag_compatibility = 32 }; +/* Enum used to identify target specific extensions to the elf_obj_tdata + structure. Note the enums deliberately start from 1 so that we can + detect an uninitialized field. The generic value is last so that + additions to this enum do not need to modify more than one line. */ +enum elf_object_id +{ + ALPHA_ELF_TDATA = 1, + ARM_ELF_TDATA, + I386_ELF_TDATA, + PPC32_ELF_TDATA, + PPC64_ELF_TDATA, + S390_ELF_TDATA, + SH_ELF_TDATA, + SPARC_ELF_TDATA, + X86_64_ELF_TDATA, + GENERIC_ELF_TDATA +}; + /* Some private data is stashed away for future use using the tdata pointer in the bfd structure. */ @@ -1545,15 +1563,23 @@ struct elf_obj_tdata /* NT_GNU_BUILD_ID note type. */ bfd_size_type build_id_size; bfd_byte *build_id; + + /* An identifier used to distinguish different target + specific extensions to this structure. */ + enum elf_object_id object_id; }; #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) + +#define elf_object_id(bfd) (elf_tdata(bfd) -> object_id) +#define elf_program_header_size(bfd) (elf_tdata(bfd) -> program_header_size) #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header) #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr) #define elf_numsections(bfd) (elf_tdata(bfd) -> num_elf_sections) #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr) #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) #define elf_symtab_shndx(bfd) (elf_tdata(bfd) -> symtab_shndx_section) +#define elf_symtab_hdr(bfd) (elf_tdata(bfd) -> symtab_hdr) #define elf_dynsymtab(bfd) (elf_tdata(bfd) -> dynsymtab_section) #define elf_dynversym(bfd) (elf_tdata(bfd) -> dynversym_section) #define elf_dynverdef(bfd) (elf_tdata(bfd) -> dynverdef_section) @@ -1647,7 +1673,9 @@ extern unsigned long bfd_elf_gnu_hash extern bfd_reloc_status_type bfd_elf_generic_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); -extern bfd_boolean bfd_elf_mkobject +extern bfd_boolean bfd_elf_allocate_object + (bfd *, size_t, enum elf_object_id); +extern bfd_boolean bfd_elf_make_generic_object (bfd *); extern bfd_boolean bfd_elf_mkcorefile (bfd *); diff --git a/bfd/elf.c b/bfd/elf.c index b5dd63686..ad8e92109 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -226,26 +226,40 @@ bfd_elf_gnu_hash (const char *namearg) return h & 0xffffffff; } +/* If ABFD does not already have an allocated tdata field then create + one, OBJECT_SIZE bytes is length, zeroed out and with the object_id + field of an elf_obj_tdata field set to OBJECT_ID. */ bfd_boolean -bfd_elf_mkobject (bfd *abfd) +bfd_elf_allocate_object (bfd * abfd, + size_t object_size, + enum elf_object_id object_id) { - if (abfd->tdata.any == NULL) - { - abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct elf_obj_tdata)); - if (abfd->tdata.any == NULL) - return FALSE; - } + if (abfd->tdata.any != NULL) + return TRUE; - elf_tdata (abfd)->program_header_size = (bfd_size_type) -1; + BFD_ASSERT (object_size >= sizeof (struct elf_obj_tdata)); + abfd->tdata.any = bfd_zalloc (abfd, object_size); + if (abfd->tdata.any == NULL) + return FALSE; + elf_object_id (abfd) = object_id; + elf_program_header_size (abfd) = (bfd_size_type) -1; return TRUE; } + +bfd_boolean +bfd_elf_make_generic_object (bfd *abfd) +{ + return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata), + GENERIC_ELF_TDATA); +} + bfd_boolean bfd_elf_mkcorefile (bfd *abfd) { /* I think this can be done just like an object file. */ - return bfd_elf_mkobject (abfd); + return bfd_elf_make_generic_object (abfd); } char * diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index b9bc50296..ec887038a 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -2065,7 +2065,7 @@ _arm_elf_section_data; /* The size of the thread control block. */ #define TCB_SIZE 8 -struct elf32_arm_obj_tdata +struct elf_arm_obj_tdata { struct elf_obj_tdata root; @@ -2076,23 +2076,22 @@ struct elf32_arm_obj_tdata int no_enum_size_warning; }; -#define elf32_arm_tdata(abfd) \ - ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) +#define elf_arm_tdata(bfd) \ + ((struct elf_arm_obj_tdata *) (bfd)->tdata.any) -#define elf32_arm_local_got_tls_type(abfd) \ - (elf32_arm_tdata (abfd)->local_got_tls_type) +#define elf32_arm_local_got_tls_type(bfd) \ + (elf_arm_tdata (bfd)->local_got_tls_type) + +#define is_arm_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == ARM_ELF_TDATA) static bfd_boolean elf32_arm_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata), + ARM_ELF_TDATA); } /* The ARM linker needs to keep track of the number of relocs that it @@ -3151,7 +3150,7 @@ bfd_elf32_arm_process_before_allocation (bfd *abfd, if ((sec->flags & SEC_EXCLUDE) != 0) continue; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (abfd); /* Load the relocs. */ internal_relocs @@ -3285,7 +3284,7 @@ bfd_elf32_arm_init_maps (bfd *abfd) if ((abfd->flags & DYNAMIC) != 0) return; - hdr = &elf_tdata (abfd)->symtab_hdr; + hdr = & elf_symtab_hdr (abfd); localsyms = hdr->sh_info; /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field @@ -3658,16 +3657,16 @@ bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info) if (link_info->relocatable) return TRUE; + /* Skip if this bfd does not correspond to an ELF image. */ + if (! is_arm_elf (abfd)) + return TRUE; + /* We should have chosen a fix type by the time we get here. */ BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT); if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE) return TRUE; - /* Skip if this bfd does not correspond to an ELF image. */ - if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) - return TRUE; - for (sec = abfd->sections; sec != NULL; sec = sec->next) { unsigned int i, span, first_fmac = 0, veneer_of_insn = 0; @@ -3840,7 +3839,7 @@ bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd, return; /* Skip if this bfd does not correspond to an ELF image. */ - if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) + if (! is_arm_elf (abfd)) return; globals = elf32_arm_hash_table (link_info); @@ -3943,7 +3942,8 @@ bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd, globals->vfp11_fix = vfp11_fix; globals->pic_veneer = pic_veneer; - elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; + BFD_ASSERT (is_arm_elf (output_bfd)); + elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; } /* The thumb form of a long branch is a bit finicky, because the offset @@ -4528,7 +4528,9 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto, globals = elf32_arm_hash_table (info); - /* Some relocation type map to different relocations depending on the + BFD_ASSERT (is_arm_elf (input_bfd)); + + /* Some relocation types map to different relocations depending on the target. We pick the right one here. */ r_type = arm_real_reloc_type (globals, r_type); if (r_type != howto->type) @@ -4552,7 +4554,7 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto, sgot = bfd_get_section_by_name (dynobj, ".got"); splt = bfd_get_section_by_name (dynobj, ".plt"); } - symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); r_symndx = ELF32_R_SYM (rel->r_info); @@ -6319,7 +6321,7 @@ elf32_arm_relocate_section (bfd * output_bfd, globals = elf32_arm_hash_table (info); - symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); rel = relocs; @@ -6608,8 +6610,7 @@ elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) flagword in_flags; flagword out_flags; - if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour - || bfd_get_flavour (obfd) != bfd_target_elf_flavour) + if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd)) return TRUE; in_flags = elf_elfheader (ibfd)->e_flags; @@ -6867,7 +6868,7 @@ elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) } else if (in_attr[i].i != AEABI_enum_forced_wide && out_attr[i].i != in_attr[i].i - && !elf32_arm_tdata (obfd)->no_enum_size_warning) + && !elf_arm_tdata (obfd)->no_enum_size_warning) { const char *aeabi_enum_names[] = { "", "variable-size", "32-bit", "" }; @@ -6963,8 +6964,7 @@ elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) if (! _bfd_generic_verify_endian_match (ibfd, obfd)) return FALSE; - if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour - || bfd_get_flavour (obfd) != bfd_target_elf_flavour) + if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd)) return TRUE; if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) @@ -7358,7 +7358,7 @@ elf32_arm_gc_sweep_hook (bfd * abfd, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -7492,6 +7492,8 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, if (info->relocatable) return TRUE; + BFD_ASSERT (is_arm_elf (abfd)); + htab = elf32_arm_hash_table (info); sreloc = NULL; @@ -7507,7 +7509,7 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, dynobj = elf_hash_table (info)->dynobj; local_got_offsets = elf_local_got_offsets (abfd); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); rel_end = relocs + sec->reloc_count; @@ -7832,13 +7834,14 @@ elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info, { asection *o; - if (bfd_get_flavour (sub) != bfd_target_elf_flavour) + if (! is_arm_elf (sub)) continue; elf_shdrp = elf_elfsections (sub); for (o = sub->sections; o != NULL; o = o->next) { Elf_Internal_Shdr *hdr; + hdr = &elf_section_data (o)->this_hdr; if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link && !o->gc_mark @@ -8524,12 +8527,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *symtab_hdr; asection *srel; - /* FIXME: Here and elsewhere the test for an ELF input BFD is - not sufficiently strict. Since we use elf32_arm_tdata and - elf32_arm_section_data, we should only allow those targets - that in fact have such data. This of course is the set of - targets defined in this file. */ - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_arm_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -8560,7 +8558,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = & elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = elf32_arm_local_got_tls_type (ibfd); @@ -8606,7 +8604,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, /* Here we rummage through the found bfds to collect glue information. */ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) { - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_arm_elf (ibfd)) continue; /* Initialise mapping tables for code/data. */ diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 3d67693f1..432e7d3c4 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1,6 +1,6 @@ /* Intel 80386/80486-specific support for 32-bit ELF Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -642,17 +642,16 @@ struct elf_i386_obj_tdata #define elf_i386_local_tlsdesc_gotent(abfd) \ (elf_i386_tdata (abfd)->local_tlsdesc_gotent) +#define is_i386_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == I386_ELF_TDATA) + static bfd_boolean elf_i386_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct elf_i386_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct elf_i386_obj_tdata), + I386_ELF_TDATA); } /* i386 ELF linker hash table. */ @@ -1210,8 +1209,10 @@ elf_i386_check_relocs (bfd *abfd, if (info->relocatable) return TRUE; + BFD_ASSERT (is_i386_elf (abfd)); + htab = elf_i386_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); sreloc = NULL; @@ -1604,7 +1605,7 @@ elf_i386_gc_sweep_hook (bfd *abfd, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -2161,7 +2162,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *symtab_hdr; asection *srel; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_i386_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2195,7 +2196,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = elf_i386_local_got_tls_type (ibfd); @@ -2502,8 +2503,10 @@ elf_i386_relocate_section (bfd *output_bfd, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; + BFD_ASSERT (is_i386_elf (input_bfd)); + htab = elf_i386_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd); diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 0c15f3b36..520f99116 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -1,6 +1,6 @@ /* PowerPC-specific support for 32-bit ELF Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -1741,14 +1741,8 @@ struct ppc_elf_obj_tdata static bfd_boolean ppc_elf_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), + PPC32_ELF_TDATA); } /* Fix bad default arch selected for a 32 bit input bfd when the @@ -2895,13 +2889,15 @@ elf_create_pointer_linker_section (bfd *abfd, } else { + BFD_ASSERT (is_ppc_elf_target (abfd->xvec)); + /* Allocation of a pointer to a local symbol. */ elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); /* Allocate a table to hold the local symbols if first time. */ if (!ptr) { - unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info; + unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info; amt = num_symbols; amt *= sizeof (elf_linker_section_pointers_t *); @@ -3059,12 +3055,14 @@ ppc_elf_check_relocs (bfd *abfd, sec, abfd); #endif + BFD_ASSERT (is_ppc_elf_target (abfd->xvec)); + /* Initialize howto table if not already done. */ if (!ppc_elf_howto_table[R_PPC_ADDR32]) ppc_elf_howto_init (); htab = ppc_elf_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); got2 = bfd_get_section_by_name (abfd, ".got2"); sreloc = NULL; @@ -3919,7 +3917,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd, elf_section_data (sec)->local_dynrel = NULL; htab = ppc_elf_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); got2 = bfd_get_section_by_name (abfd, ".got2"); @@ -4077,7 +4075,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) { Elf_Internal_Sym *locsyms = NULL; - Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); for (sec = ibfd->sections; sec != NULL; sec = sec->next) if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) @@ -4954,7 +4952,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; lgot_masks = (char *) end_local_got; @@ -5260,7 +5258,7 @@ ppc_elf_relax_section (bfd *abfd, /* Space for a branch around any trampolines. */ trampoff += 4; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); /* Get a copy of the native relocations. */ internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, @@ -5677,6 +5675,7 @@ elf_finish_pointer_linker_section (bfd *input_bfd, /* Handle local symbol. */ unsigned long r_symndx = ELF32_R_SYM (rel->r_info); + BFD_ASSERT (is_ppc_elf_target (input_bfd->xvec)); BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx]; } @@ -5778,7 +5777,7 @@ ppc_elf_relocate_section (bfd *output_bfd, htab = ppc_elf_hash_table (info); local_got_offsets = elf_local_got_offsets (input_bfd); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); rel = relocs; relend = relocs + input_section->reloc_count; diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index 92bf8eed7..7d6337289 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -1,5 +1,5 @@ /* IBM S/390-specific support for 32-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Carl B. Pedersen and Martin Schwidefsky. @@ -674,11 +674,13 @@ struct elf_s390_link_hash_entry #define elf_s390_hash_entry(ent) \ ((struct elf_s390_link_hash_entry *)(ent)) +/* NOTE: Keep this structure in sync with + the one declared in elf64-s390.c. */ struct elf_s390_obj_tdata { struct elf_obj_tdata root; - /* tls_type for each local got entry. */ + /* TLS type for each local got entry. */ char *local_got_tls_type; }; @@ -688,17 +690,16 @@ struct elf_s390_obj_tdata #define elf_s390_local_got_tls_type(abfd) \ (elf_s390_tdata (abfd)->local_got_tls_type) +#define is_s390_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == S390_ELF_TDATA) + static bfd_boolean elf_s390_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct elf_s390_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), + S390_ELF_TDATA); } static bfd_boolean @@ -982,8 +983,10 @@ elf_s390_check_relocs (abfd, info, sec, relocs) if (info->relocatable) return TRUE; + BFD_ASSERT (is_s390_elf (abfd)); + htab = elf_s390_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1429,7 +1432,7 @@ elf_s390_gc_sweep_hook (bfd *abfd, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -2019,7 +2022,7 @@ elf_s390_size_dynamic_sections (output_bfd, info) Elf_Internal_Shdr *symtab_hdr; asection *srela; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_s390_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2050,7 +2053,7 @@ elf_s390_size_dynamic_sections (output_bfd, info) if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = elf_s390_local_got_tls_type (ibfd); @@ -2269,8 +2272,10 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; + BFD_ASSERT (is_s390_elf (input_bfd)); + htab = elf_s390_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index 827ba6480..1c7b2905e 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -1,6 +1,6 @@ /* Renesas / SuperH SH specific support for 32-bit ELF Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007 Free Software Foundation, Inc. + 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Ian Lance Taylor, Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -487,7 +487,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec, } #endif - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); internal_relocs = (_bfd_elf_link_read_relocs (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, @@ -852,7 +852,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, unsigned int symcount; asection *o; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); @@ -2154,20 +2154,19 @@ struct sh_elf_obj_tdata #define sh_elf_local_got_tls_type(abfd) \ (sh_elf_tdata (abfd)->local_got_tls_type) +#define is_sh_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == SH_ELF_TDATA) + /* Override the generic function because we need to store sh_elf_obj_tdata as the specific tdata. */ static bfd_boolean sh_elf_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct sh_elf_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct sh_elf_obj_tdata), + SH_ELF_TDATA); } /* sh ELF linker hash table. */ @@ -2958,7 +2957,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *symtab_hdr; asection *srel; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_sh_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2992,7 +2991,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; #ifdef INCLUDE_SHMEDIA /* Count datalabel local GOT. */ @@ -3168,8 +3167,10 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, asection *sreloc; asection *srelgot; + BFD_ASSERT (is_sh_elf (input_bfd)); + htab = sh_elf_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (input_bfd); @@ -4427,7 +4428,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd, relocatable, symbols); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); memcpy (data, elf_section_data (input_section)->this_hdr.contents, (size_t) input_section->size); @@ -4569,7 +4570,7 @@ sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -4859,7 +4860,9 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, if (info->relocatable) return TRUE; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + BFD_ASSERT (is_sh_elf (abfd)); + + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); htab = sh_elf_hash_table (info); @@ -5358,13 +5361,12 @@ sh_elf_set_private_flags (bfd *abfd, flagword flags) static bfd_boolean sh_elf_copy_private_data (bfd * ibfd, bfd * obfd) { - if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour - || bfd_get_flavour (obfd) != bfd_target_elf_flavour) - return TRUE; - /* Copy object attributes. */ _bfd_elf_copy_obj_attributes (ibfd, obfd); + if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd)) + return TRUE; + return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags); } #endif /* not sh_elf_copy_private_data */ @@ -5391,8 +5393,7 @@ sh_elf_merge_private_data (bfd *ibfd, bfd *obfd) { extern bfd_boolean sh_merge_bfd_arch (bfd *, bfd *); - if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour - || bfd_get_flavour (obfd) != bfd_target_elf_flavour) + if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd)) return TRUE; if (! elf_flags_init (obfd)) diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 15a417e34..94a7ed010 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -1,6 +1,6 @@ /* Alpha specific support for 64-bit ELF Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007 Free Software Foundation, Inc. + 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Richard Henderson . This file is part of BFD, the Binary File Descriptor library. @@ -324,17 +324,16 @@ struct alpha_elf_obj_tdata #define alpha_elf_tdata(abfd) \ ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any) +#define is_alpha_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == ALPHA_ELF_TDATA) + static bfd_boolean elf64_alpha_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct alpha_elf_obj_tdata), + ALPHA_ELF_TDATA); } static bfd_boolean @@ -1234,6 +1233,9 @@ elf64_alpha_create_got_section (bfd *abfd, flagword flags; asection *s; + if (! is_alpha_elf (abfd)) + return FALSE; + flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); @@ -1260,6 +1262,9 @@ elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) flagword flags; struct elf_link_hash_entry *h; + if (! is_alpha_elf (abfd)) + return FALSE; + /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */ flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY @@ -1761,14 +1766,16 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info, if ((sec->flags & SEC_ALLOC) == 0) return TRUE; - dynobj = elf_hash_table(info)->dynobj; + BFD_ASSERT (is_alpha_elf (abfd)); + + dynobj = elf_hash_table (info)->dynobj; if (dynobj == NULL) - elf_hash_table(info)->dynobj = dynobj = abfd; + elf_hash_table (info)->dynobj = dynobj = abfd; sreloc = NULL; rel_sec_name = NULL; - symtab_hdr = &elf_tdata(abfd)->symtab_hdr; - sym_hashes = alpha_elf_sym_hashes(abfd); + symtab_hdr = &elf_symtab_hdr (abfd); + sym_hashes = alpha_elf_sym_hashes (abfd); relend = relocs + sec->reloc_count; for (rel = relocs; rel < relend; ++rel) @@ -2390,7 +2397,12 @@ elf64_alpha_size_got_sections (struct bfd_link_info *info) { for (i = info->input_bfds; i ; i = i->link_next) { - bfd *this_got = alpha_elf_tdata (i)->gotobj; + bfd *this_got; + + if (! is_alpha_elf (i)) + continue; + + this_got = alpha_elf_tdata (i)->gotobj; if (this_got == NULL) continue; @@ -2421,6 +2433,9 @@ elf64_alpha_size_got_sections (struct bfd_link_info *info) } cur_got_obj = got_list; + if (cur_got_obj == NULL) + return FALSE; + i = alpha_elf_tdata(cur_got_obj)->got_link_next; while (i != NULL) { @@ -3612,6 +3627,8 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec, || sec->reloc_count == 0) return TRUE; + BFD_ASSERT (is_alpha_elf (abfd)); + /* Make sure our GOT and PLT tables are up-to-date. */ if (alpha_elf_hash_table(link_info)->relax_trip != link_info->relax_trip) { @@ -3628,7 +3645,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec, } } - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); local_got_entries = alpha_elf_tdata(abfd)->local_got_entries; /* Load the relocations for this section. */ @@ -3935,7 +3952,7 @@ elf64_alpha_relocate_section_r (bfd *output_bfd ATTRIBUTE_UNUSED, struct elf_link_hash_entry **sym_hashes; bfd_boolean ret_val = TRUE; - symtab_hdr_sh_info = elf_tdata (input_bfd)->symtab_hdr.sh_info; + symtab_hdr_sh_info = elf_symtab_hdr (input_bfd).sh_info; sym_hashes = elf_sym_hashes (input_bfd); relend = relocs + input_section->reloc_count; @@ -4023,6 +4040,8 @@ elf64_alpha_relocate_section (bfd *output_bfd, struct bfd_link_info *info, struct alpha_elf_got_entry **local_got_entries; bfd_boolean ret_val; + BFD_ASSERT (is_alpha_elf (input_bfd)); + /* Handle relocatable links with a smaller loop. */ if (info->relocatable) return elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, @@ -4033,7 +4052,7 @@ elf64_alpha_relocate_section (bfd *output_bfd, struct bfd_link_info *info, ret_val = TRUE; - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); dynobj = elf_hash_table (info)->dynobj; if (dynobj) @@ -5043,15 +5062,11 @@ elf64_alpha_final_link (bfd *abfd, struct bfd_link_info *info) input_section = p->u.indirect.section; input_bfd = input_section->owner; - if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour - || (get_elf_backend_data (input_bfd) - ->elf_backend_ecoff_debug_swap) == NULL) - { - /* I don't know what a non ALPHA ELF bfd would be - doing with a .mdebug section, but I don't really - want to deal with it. */ - continue; - } + if (! is_alpha_elf (input_bfd)) + /* I don't know what a non ALPHA ELF bfd would be + doing with a .mdebug section, but I don't really + want to deal with it. */ + continue; input_swap = (get_elf_backend_data (input_bfd) ->elf_backend_ecoff_debug_swap); diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 026c52e42..0dae3d75e 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -2430,14 +2430,8 @@ struct ppc64_elf_obj_tdata static bfd_boolean ppc64_elf_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata), + PPC64_ELF_TDATA); } /* Return 1 if target is one of ours. */ @@ -3888,6 +3882,9 @@ create_got_section (bfd *abfd, struct bfd_link_info *info) flagword flags; struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (! is_ppc64_elf_target (abfd->xvec)) + return FALSE; + if (!htab->got) { if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) @@ -4425,8 +4422,10 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, if ((sec->flags & SEC_ALLOC) == 0) return TRUE; + BFD_ASSERT (is_ppc64_elf_target (abfd->xvec)); + htab = ppc_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); sym_hashes_end = (sym_hashes @@ -4989,6 +4988,8 @@ opd_entry_value (asection *opd_sec, return val; } + BFD_ASSERT (is_ppc64_elf_target (opd_bfd->xvec)); + relocs = ppc64_elf_tdata (opd_bfd)->opd_relocs; if (relocs == NULL) relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE); @@ -5007,7 +5008,8 @@ opd_entry_value (asection *opd_sec, hi = look; else { - Elf_Internal_Shdr *symtab_hdr = &elf_tdata (opd_bfd)->symtab_hdr; + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd); + if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC) { @@ -5265,7 +5267,7 @@ ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, elf_section_data (sec)->local_dynrel = NULL; htab = ppc_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_ents = elf_local_got_ents (abfd); @@ -6005,7 +6007,7 @@ get_sym_h (struct elf_link_hash_entry **hp, unsigned long r_symndx, bfd *ibfd) { - Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd); if (r_symndx >= symtab_hdr->sh_info) { @@ -6369,7 +6371,7 @@ ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info, continue; local_syms = NULL; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); sym_hashes = elf_sym_hashes (ibfd); /* Read the relocations. */ @@ -6837,7 +6839,7 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) if (toc_ref != NULL) free (toc_ref); if (locsyms != NULL - && (elf_tdata (ibfd)->symtab_hdr.contents + && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms)) free (locsyms); return FALSE; @@ -7019,7 +7021,7 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) unsigned long r_symndx2; struct elf_link_hash_entry *h2; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); /* The next instruction should be a call to __tls_get_addr. Peek at the reloc to be sure. */ @@ -7161,13 +7163,12 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) free (toc_ref); if (locsyms != NULL - && (elf_tdata (ibfd)->symtab_hdr.contents - != (unsigned char *) locsyms)) + && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms)) { if (!info->keep_memory) free (locsyms); else - elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; + elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms; } } return TRUE; @@ -7255,7 +7256,7 @@ ppc64_elf_edit_toc (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) continue; local_syms = NULL; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); sym_hashes = elf_sym_hashes (ibfd); /* Look at sections dropped from the final link. */ @@ -7748,6 +7749,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) continue; } + if (! is_ppc64_elf_target (gent->owner->xvec)) + continue; + s = ppc64_elf_tdata (gent->owner)->got; gent->got.offset = s->size; s->size @@ -7956,7 +7960,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (!lgot_ents) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_lgot_ents = lgot_ents + locsymcount; lgot_masks = (char *) end_lgot_ents; @@ -9092,8 +9096,7 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) } if (local_syms != NULL - && (elf_tdata (isec->owner)->symtab_hdr.contents - != (unsigned char *) local_syms)) + && (elf_symtab_hdr (isec->owner).contents != (unsigned char *) local_syms)) free (local_syms); if (elf_section_data (isec)->relocs != relstart) free (relstart); @@ -9311,7 +9314,7 @@ ppc64_elf_size_stubs (bfd *output_bfd, continue; /* We'll need the symbol table in a second. */ - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); if (symtab_hdr->sh_info == 0) continue; @@ -9958,9 +9961,11 @@ ppc64_elf_relocate_section (bfd *output_bfd, if (input_section->owner == htab->stub_bfd) return TRUE; + BFD_ASSERT (is_ppc64_elf_target (input_bfd->xvec)); + local_got_ents = elf_local_got_ents (input_bfd); TOCstart = elf_gp (output_bfd); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd; diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index cfbc13516..820e4632e 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -1,5 +1,5 @@ /* IBM S/390-specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Contributed Martin Schwidefsky (schwidefsky@de.ibm.com). @@ -629,11 +629,13 @@ struct elf_s390_link_hash_entry #define elf_s390_hash_entry(ent) \ ((struct elf_s390_link_hash_entry *)(ent)) +/* NOTE: Keep this structure in sync with + the one declared in elf32-s390.c. */ struct elf_s390_obj_tdata { struct elf_obj_tdata root; - /* tls_type for each local got entry. */ + /* TLS type for each local got entry. */ char *local_got_tls_type; }; @@ -643,17 +645,16 @@ struct elf_s390_obj_tdata #define elf_s390_local_got_tls_type(abfd) \ (elf_s390_tdata (abfd)->local_got_tls_type) +#define is_s390_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == S390_ELF_TDATA) + static bfd_boolean elf_s390_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct elf_s390_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), + S390_ELF_TDATA); } static bfd_boolean @@ -937,8 +938,10 @@ elf_s390_check_relocs (abfd, info, sec, relocs) if (info->relocatable) return TRUE; + BFD_ASSERT (is_s390_elf (abfd)); + htab = elf_s390_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1397,7 +1400,7 @@ elf_s390_gc_sweep_hook (bfd *abfd, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1993,7 +1996,7 @@ elf_s390_size_dynamic_sections (output_bfd, info) Elf_Internal_Shdr *symtab_hdr; asection *srela; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_s390_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2024,7 +2027,7 @@ elf_s390_size_dynamic_sections (output_bfd, info) if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = elf_s390_local_got_tls_type (ibfd); @@ -2243,8 +2246,10 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; + BFD_ASSERT (is_s390_elf (input_bfd)); + htab = elf_s390_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 84d5ee58b..3e508e00a 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1,5 +1,5 @@ /* X86-64 specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Jan Hubicka . @@ -457,6 +457,18 @@ struct elf64_x86_64_obj_tdata #define elf64_x86_64_local_tlsdesc_gotent(abfd) \ (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent) +#define is_x86_64_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == X86_64_ELF_TDATA) + +static bfd_boolean +elf64_x86_64_mkobject (bfd *abfd) +{ + return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata), + X86_64_ELF_TDATA); +} + /* x86-64 ELF linker hash table. */ struct elf64_x86_64_link_hash_table @@ -693,19 +705,6 @@ elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info, } static bfd_boolean -elf64_x86_64_mkobject (bfd *abfd) -{ - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); -} - -static bfd_boolean elf64_x86_64_elf_object_p (bfd *abfd) { /* Set the right machine number for an x86-64 elf64 file. */ @@ -990,8 +989,10 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, if (info->relocatable) return TRUE; + BFD_ASSERT (is_x86_64_elf (abfd)); + htab = elf64_x86_64_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); sreloc = NULL; @@ -1430,7 +1431,7 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, elf_section_data (sec)->local_dynrel = NULL; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1972,7 +1973,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *symtab_hdr; asection *srel; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_x86_64_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2007,7 +2008,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = elf64_x86_64_local_got_tls_type (ibfd); @@ -2310,8 +2311,10 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; + BFD_ASSERT (is_x86_64_elf (input_bfd)); + htab = elf64_x86_64_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd); diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index 9796849b1..cb22eaf10 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -1,5 +1,5 @@ /* SPARC-specific support for ELF - Copyright 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -510,17 +510,16 @@ struct _bfd_sparc_elf_obj_tdata #define _bfd_sparc_elf_local_got_tls_type(abfd) \ (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type) +#define is_sparc_elf(bfd) \ + (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ + && elf_tdata (bfd) != NULL \ + && elf_object_id (bfd) == SPARC_ELF_TDATA) + bfd_boolean _bfd_sparc_elf_mkobject (bfd *abfd) { - if (abfd->tdata.any == NULL) - { - bfd_size_type amt = sizeof (struct _bfd_sparc_elf_obj_tdata); - abfd->tdata.any = bfd_zalloc (abfd, amt); - if (abfd->tdata.any == NULL) - return FALSE; - } - return bfd_elf_mkobject (abfd); + return bfd_elf_allocate_object (abfd, sizeof (struct _bfd_sparc_elf_obj_tdata), + SPARC_ELF_TDATA); } static void @@ -1090,7 +1089,7 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return TRUE; htab = _bfd_sparc_elf_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_offsets = elf_local_got_offsets (abfd); @@ -1100,6 +1099,9 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, num_relocs = NUM_SHDR_ENTRIES (& elf_section_data (sec)->rel_hdr); else num_relocs = sec->reloc_count; + + BFD_ASSERT (is_sparc_elf (abfd) || num_relocs == 0); + rel_end = relocs + num_relocs; for (rel = relocs; rel < rel_end; rel++) { @@ -1566,10 +1568,12 @@ _bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, if (info->relocatable) return TRUE; + BFD_ASSERT (is_sparc_elf (abfd) || sec->reloc_count == 0); + elf_section_data (sec)->local_dynrel = NULL; htab = _bfd_sparc_elf_hash_table (info); - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -2157,7 +2161,7 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd, Elf_Internal_Shdr *symtab_hdr; asection *srel; - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + if (! is_sparc_elf (ibfd)) continue; for (s = ibfd->sections; s != NULL; s = s->next) @@ -2188,7 +2192,7 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd, if (!local_got) continue; - symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (ibfd); locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; local_tls_type = _bfd_sparc_elf_local_got_tls_type (ibfd); @@ -2486,7 +2490,7 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, int num_relocs; htab = _bfd_sparc_elf_hash_table (info); - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 53d3c34dd..2e6be6d84 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -269,7 +269,7 @@ #endif #ifndef bfd_elfNN_mkobject -#define bfd_elfNN_mkobject bfd_elf_mkobject +#define bfd_elfNN_mkobject bfd_elf_make_generic_object #endif #ifndef bfd_elfNN_mkcorefile -- 2.11.4.GIT