From d1036acbe72ee838ccf0c876be94884246589641 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 14 Mar 2007 02:56:45 +0000 Subject: 2007-03-13 H.J. Lu PR binutils/3826 * elf-bfd.h (elf_backend_data): Add elf_osabi. (_bfd_elf_set_osabi): New. * elf.c (_bfd_elf_set_osabi): New. * elf32-hppa.c (elf32_hppa_post_process_headers): Removed. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi. (ELF_OSABI): Properly defined for each target. * elf32-i370.c (i370_elf_post_process_headers): Removed. (ELF_OSABI): Defined. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi. * elf32-i386.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. (elf_i386_post_process_headers): Set EI_OSABI with elf_osabi. * elf32-msp430.c (elf32_msp430_post_process_headers): Removed. (ELF_OSABI): Defined. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi. * elf64-alpha.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. (elf64_alpha_fbsd_post_process_headers): Set EI_OSABI with elf_osabi. * elf64-hppa.c (elf64_hppa_post_process_headers): Set EI_OSABI with elf_osabi. (ELF_OSABI): Properly defined for each target. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi for Linux. * elf64-sparc.c (elf64_sparc_fbsd_post_process_headers): Removed. (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi. * elf64-x86-64.c (elf64_x86_64_fbsd_post_process_headers): Removed. (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. (elf_backend_post_process_headers): Defined with _bfd_elf_set_osabi. * elfcode.h (elf_object_p): Match the ELFOSABI_NONE ELF target with any ELF target of the compatible machine for which we do not have a specific backend. * elfxx-ia64.c (elfNN_hpux_post_process_headers): Set EI_OSABI with elf_osabi. * elfxx-target.h (ELF_OSABI): Default to ELFOSABI_NONE. (elfNN_bed): Initialize elf_osabi with ELF_OSABI. --- bfd/ChangeLog | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bfd/elf-bfd.h | 5 +++++ bfd/elf.c | 11 +++++++++++ bfd/elf32-hppa.c | 31 ++++++----------------------- bfd/elf32-i370.c | 14 +++---------- bfd/elf32-i386.c | 6 ++++-- bfd/elf32-msp430.c | 18 ++--------------- bfd/elf64-alpha.c | 4 +++- bfd/elf64-hppa.c | 19 +++++++++--------- bfd/elf64-sparc.c | 20 +++---------------- bfd/elf64-x86-64.c | 19 +++--------------- bfd/elfcode.h | 49 +++++++++++++++++++++++++++++++++++++++++---- bfd/elfxx-ia64.c | 4 +++- bfd/elfxx-target.h | 5 +++++ 14 files changed, 160 insertions(+), 103 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2dd58ed..6813f17 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,61 @@ +2007-03-13 H.J. Lu + + PR binutils/3826 + * elf-bfd.h (elf_backend_data): Add elf_osabi. + (_bfd_elf_set_osabi): New. + + * elf.c (_bfd_elf_set_osabi): New. + + * elf32-hppa.c (elf32_hppa_post_process_headers): Removed. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi. + (ELF_OSABI): Properly defined for each target. + + * elf32-i370.c (i370_elf_post_process_headers): Removed. + (ELF_OSABI): Defined. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi. + + * elf32-i386.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for + freebsd. + (elf_i386_post_process_headers): Set EI_OSABI with elf_osabi. + + * elf32-msp430.c (elf32_msp430_post_process_headers): Removed. + (ELF_OSABI): Defined. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi. + + * elf64-alpha.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for + freebsd. + (elf64_alpha_fbsd_post_process_headers): Set EI_OSABI with + elf_osabi. + + * elf64-hppa.c (elf64_hppa_post_process_headers): Set EI_OSABI + with elf_osabi. + (ELF_OSABI): Properly defined for each target. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi for Linux. + + * elf64-sparc.c (elf64_sparc_fbsd_post_process_headers): Removed. + (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi. + + * elf64-x86-64.c (elf64_x86_64_fbsd_post_process_headers): Removed. + (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebsd. + (elf_backend_post_process_headers): Defined with + _bfd_elf_set_osabi. + + * elfcode.h (elf_object_p): Match the ELFOSABI_NONE ELF target + with any ELF target of the compatible machine for which we do not + have a specific backend. + + * elfxx-ia64.c (elfNN_hpux_post_process_headers): Set EI_OSABI + with elf_osabi. + + * elfxx-target.h (ELF_OSABI): Default to ELFOSABI_NONE. + (elfNN_bed): Initialize elf_osabi with ELF_OSABI. + 2007-03-08 Alan Modra * elf32-v850.c (v850_elf_link_output_symbol_hook): Clean out diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index dd7d51d..4a01fe6 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -550,6 +550,9 @@ struct elf_backend_data /* The ELF machine code (EM_xxxx) for this backend. */ int elf_machine_code; + /* EI_OSABI. */ + int elf_osabi; + /* The maximum page size for this backend. */ bfd_vma maxpagesize; @@ -1755,6 +1758,8 @@ extern void bfd_elf_perform_complex_relocation extern bfd_boolean _bfd_elf_setup_sections (bfd *); +extern void _bfd_elf_set_osabi (bfd * , struct bfd_link_info *); + extern const bfd_target *bfd_elf32_object_p (bfd *); extern const bfd_target *bfd_elf32_core_file_p diff --git a/bfd/elf.c b/bfd/elf.c index d882882..05d45e1 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9115,3 +9115,14 @@ _bfd_elf_match_sections_by_type (bfd *abfd, const asection *asec, return elf_section_type (asec) == elf_section_type (bsec); } + +void +_bfd_elf_set_osabi (bfd * abfd, + struct bfd_link_info * link_info ATTRIBUTE_UNUSED) +{ + Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ + + i_ehdrp = elf_elfheader (abfd); + + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; +} diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 117300e..13c2696 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -4601,30 +4601,6 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd, return TRUE; } -/* Tweak the OSABI field of the elf header. */ - -static void -elf32_hppa_post_process_headers (bfd *abfd, - struct bfd_link_info *info ATTRIBUTE_UNUSED) -{ - Elf_Internal_Ehdr * i_ehdrp; - - i_ehdrp = elf_elfheader (abfd); - - if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0) - { - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX; - } - else if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0) - { - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_NETBSD; - } - else - { - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX; - } -} - /* Called when writing out an object file to decide the type of a symbol. */ static int @@ -4663,7 +4639,7 @@ elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) #define elf_backend_grok_psinfo elf32_hppa_grok_psinfo #define elf_backend_object_p elf32_hppa_object_p #define elf_backend_final_write_processing elf_hppa_final_write_processing -#define elf_backend_post_process_headers elf32_hppa_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class #define elf_backend_action_discarded elf_hppa_action_discarded @@ -4682,6 +4658,7 @@ elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) #define ELF_ARCH bfd_arch_hppa #define ELF_MACHINE_CODE EM_PARISC #define ELF_MAXPAGESIZE 0x1000 +#define ELF_OSABI ELFOSABI_HPUX #define elf32_bed elf32_hppa_hpux_bed #include "elf32-target.h" @@ -4690,6 +4667,8 @@ elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec #undef TARGET_BIG_NAME #define TARGET_BIG_NAME "elf32-hppa-linux" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_LINUX #undef elf32_bed #define elf32_bed elf32_hppa_linux_bed @@ -4699,6 +4678,8 @@ elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) #define TARGET_BIG_SYM bfd_elf32_hppa_nbsd_vec #undef TARGET_BIG_NAME #define TARGET_BIG_NAME "elf32-hppa-netbsd" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_NETBSD #undef elf32_bed #define elf32_bed elf32_hppa_netbsd_bed diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c index 87e2189..69393d9 100644 --- a/bfd/elf32-i370.c +++ b/bfd/elf32-i370.c @@ -1417,16 +1417,6 @@ i370_elf_relocate_section (bfd *output_bfd, return ret; } - -static void -i370_elf_post_process_headers (bfd * abfd, - struct bfd_link_info * link_info ATTRIBUTE_UNUSED) -{ - Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form. */ - - i_ehdrp = elf_elfheader (abfd); - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX; -} #define TARGET_BIG_SYM bfd_elf32_i370_vec #define TARGET_BIG_NAME "elf32-i370" @@ -1436,6 +1426,8 @@ i370_elf_post_process_headers (bfd * abfd, #define ELF_MACHINE_ALT1 EM_I370_OLD #endif #define ELF_MAXPAGESIZE 0x1000 +#define ELF_OSABI ELFOSABI_LINUX + #define elf_info_to_howto i370_elf_info_to_howto #define elf_backend_plt_not_loaded 1 @@ -1456,7 +1448,7 @@ i370_elf_post_process_headers (bfd * abfd, #define elf_backend_section_from_shdr i370_elf_section_from_shdr #define elf_backend_adjust_dynamic_symbol i370_elf_adjust_dynamic_symbol #define elf_backend_check_relocs i370_elf_check_relocs -#define elf_backend_post_process_headers i370_elf_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi static int i370_noop (void) diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 05fe640..a277f7a 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3847,6 +3847,8 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h) #define TARGET_LITTLE_SYM bfd_elf32_i386_freebsd_vec #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf32-i386-freebsd" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD /* The kernel recognizes executables as valid only if they carry a "FreeBSD" label in the ELF header. So we put this label on all @@ -3861,7 +3863,7 @@ elf_i386_post_process_headers (bfd *abfd, i_ehdrp = elf_elfheader (abfd); /* Put an ABI label supported by FreeBSD >= 4.1. */ - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; #ifdef OLD_FREEBSD_ABI_LABEL /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); @@ -3881,7 +3883,7 @@ elf_i386_post_process_headers (bfd *abfd, #define TARGET_LITTLE_SYM bfd_elf32_i386_vxworks_vec #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf32-i386-vxworks" - +#undef ELF_OSABI /* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */ diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c index 6889d46..c8124e7 100644 --- a/bfd/elf32-msp430.c +++ b/bfd/elf32-msp430.c @@ -656,21 +656,6 @@ elf32_msp430_object_p (bfd * abfd) return bfd_default_set_arch_mach (abfd, bfd_arch_msp430, e_set); } -static void -elf32_msp430_post_process_headers (bfd * abfd, - struct bfd_link_info * link_info ATTRIBUTE_UNUSED) -{ - Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ - - i_ehdrp = elf_elfheader (abfd); - -#ifndef ELFOSABI_STANDALONE -#define ELFOSABI_STANDALONE 255 -#endif - - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_STANDALONE; -} - /* These functions handle relaxing for the msp430. Relaxation required only in two cases: - Bad hand coding like jumps from one section to another or @@ -1174,6 +1159,7 @@ error_return: #define ELF_MACHINE_CODE EM_MSP430 #define ELF_MACHINE_ALT1 EM_MSP430_OLD #define ELF_MAXPAGESIZE 1 +#define ELF_OSABI ELFOSABI_STANDALONE #define TARGET_LITTLE_SYM bfd_elf32_msp430_vec #define TARGET_LITTLE_NAME "elf32-msp430" @@ -1185,7 +1171,7 @@ error_return: #define elf_backend_can_gc_sections 1 #define elf_backend_final_write_processing bfd_elf_msp430_final_write_processing #define elf_backend_object_p elf32_msp430_object_p -#define elf_backend_post_process_headers elf32_msp430_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi #define bfd_elf32_bfd_relax_section msp430_elf_relax_section #include "elf32-target.h" diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 126ac64..efda753 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -5354,6 +5354,8 @@ static const struct elf_size_info alpha_elf_size_info = #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf64-alpha-freebsd" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD /* The kernel recognizes executables as valid only if they carry a "FreeBSD" label in the ELF header. So we put this label on all @@ -5368,7 +5370,7 @@ elf64_alpha_fbsd_post_process_headers (bfd * abfd, i_ehdrp = elf_elfheader (abfd); /* Put an ABI label supported by FreeBSD >= 4.1. */ - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; #ifdef OLD_FREEBSD_ABI_LABEL /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index 675b02b..8e7e9d1 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -1198,16 +1198,9 @@ elf64_hppa_post_process_headers (abfd, link_info) Elf_Internal_Ehdr * i_ehdrp; i_ehdrp = elf_elfheader (abfd); - - if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0) - { - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX; - } - else - { - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX; - i_ehdrp->e_ident[EI_ABIVERSION] = 1; - } + + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; + i_ehdrp->e_ident[EI_ABIVERSION] = 1; } /* Create function descriptor section (.opd). This section is called .opd @@ -2800,6 +2793,8 @@ const struct elf_size_info hppa64_elf_size_info = /* This is not strictly correct. The maximum page size for PA2.0 is 64M. But everything still uses 4k. */ #define ELF_MAXPAGESIZE 0x1000 +#define ELF_OSABI ELFOSABI_HPUX + #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name #define elf_info_to_howto elf_hppa_info_to_howto @@ -2874,6 +2869,10 @@ const struct elf_size_info hppa64_elf_size_info = #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec #undef TARGET_BIG_NAME #define TARGET_BIG_NAME "elf64-hppa-linux" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_LINUX +#undef elf_backend_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi #undef elf64_bed #define elf64_bed elf64_hppa_linux_bed diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c index 0eefc95..f9d4c81 100644 --- a/bfd/elf64-sparc.c +++ b/bfd/elf64-sparc.c @@ -910,25 +910,11 @@ const struct elf_size_info elf64_sparc_size_info = #define TARGET_BIG_SYM bfd_elf64_sparc_freebsd_vec #undef TARGET_BIG_NAME #define TARGET_BIG_NAME "elf64-sparc-freebsd" - -/* The kernel recognizes executables as valid only if they carry a - "FreeBSD" label in the ELF header. So we put this label on all - executables and (for simplicity) also all other object files. */ - -static void -elf64_sparc_fbsd_post_process_headers (bfd *abfd, - struct bfd_link_info *info ATTRIBUTE_UNUSED) -{ - Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */ - - i_ehdrp = elf_elfheader (abfd); - - /* Put an ABI label supported by FreeBSD >= 4.1 */ - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; -} +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD #undef elf_backend_post_process_headers -#define elf_backend_post_process_headers elf64_sparc_fbsd_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi #undef elf64_bed #define elf64_bed elf64_sparc_fbsd_bed diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 7e959b1..eec8441 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3713,24 +3713,11 @@ static const struct bfd_elf_special_section #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd" -/* The kernel recognizes executables as valid only if they carry a - "FreeBSD" label in the ELF header. So we put this label on all - executables and (for simplicity) also all other object files. */ - -static void -elf64_x86_64_fbsd_post_process_headers (bfd * abfd, - struct bfd_link_info * link_info ATTRIBUTE_UNUSED) -{ - Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ - - i_ehdrp = elf_elfheader (abfd); - - /* Put an ABI label supported by FreeBSD >= 4.1. */ - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; -} +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD #undef elf_backend_post_process_headers -#define elf_backend_post_process_headers elf64_x86_64_fbsd_post_process_headers +#define elf_backend_post_process_headers _bfd_elf_set_osabi #undef elf64_bed #define elf64_bed elf64_x86_64_fbsd_bed diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 04c2d91..3c29550 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -500,6 +500,8 @@ elf_object_p (bfd *abfd) struct bfd_preserve preserve; asection *s; bfd_size_type amt; + const bfd_target *target; + const bfd_target * const *target_ptr; preserve.marker = NULL; @@ -543,10 +545,12 @@ elf_object_p (bfd *abfd) if (!bfd_preserve_save (abfd, &preserve)) goto got_no_match; + target = abfd->xvec; + /* Allocate an instance of the elf_obj_tdata structure and hook it up to the tdata pointer in the bfd. */ - if (! (*abfd->xvec->_bfd_set_format[bfd_object]) (abfd)) + if (! (*target->_bfd_set_format[bfd_object]) (abfd)) goto got_no_match; preserve.marker = elf_tdata (abfd); @@ -586,8 +590,6 @@ elf_object_p (bfd *abfd) && (ebd->elf_machine_alt2 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt2)) { - const bfd_target * const *target_ptr; - if (ebd->elf_machine_code != EM_NONE) goto got_wrong_format_error; @@ -628,6 +630,45 @@ elf_object_p (bfd *abfd) goto got_no_match; } + if (ebd->elf_machine_code != EM_NONE + && i_ehdrp->e_ident[EI_OSABI] != ebd->elf_osabi) + { + if (ebd->elf_osabi != ELFOSABI_NONE) + goto got_wrong_format_error; + + /* This is an ELFOSABI_NONE ELF target. Let it match any ELF + target of the compatible machine for which we do not have a + backend with matching ELFOSABI. */ + for (target_ptr = bfd_target_vector; + *target_ptr != NULL; + target_ptr++) + { + const struct elf_backend_data *back; + + /* Skip this target and targets with incompatible byte + order. */ + if (*target_ptr == target + || (*target_ptr)->flavour != bfd_target_elf_flavour + || (*target_ptr)->byteorder != target->byteorder + || ((*target_ptr)->header_byteorder + != target->header_byteorder)) + continue; + + back = (const struct elf_backend_data *) (*target_ptr)->backend_data; + if (back->elf_osabi == i_ehdrp->e_ident[EI_OSABI] + && (back->elf_machine_code == i_ehdrp->e_machine + || (back->elf_machine_alt1 != 0 + && back->elf_machine_alt1 == i_ehdrp->e_machine) + || (back->elf_machine_alt2 != 0 + && back->elf_machine_alt2 == i_ehdrp->e_machine))) + { + /* target_ptr is an ELF backend which matches this + object file, so reject the ELFOSABI_NONE ELF target. */ + goto got_wrong_format_error; + } + } + } + if (i_ehdrp->e_shoff != 0) { bfd_signed_vma where = i_ehdrp->e_shoff; @@ -848,7 +889,7 @@ elf_object_p (bfd *abfd) } bfd_preserve_finish (abfd, &preserve); - return abfd->xvec; + return target; got_wrong_format_error: /* There is way too much undoing of half-known state here. The caller, diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c index 7975401..a0a1b1c 100644 --- a/bfd/elfxx-ia64.c +++ b/bfd/elfxx-ia64.c @@ -5681,7 +5681,7 @@ elfNN_hpux_post_process_headers (abfd, info) { Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); - i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX; + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; i_ehdrp->e_ident[EI_ABIVERSION] = 1; } @@ -5838,6 +5838,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, #undef ELF_MAXPAGESIZE #define ELF_MAXPAGESIZE 0x1000 /* 4K */ #undef ELF_COMMONPAGESIZE +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_HPUX #undef elfNN_bed #define elfNN_bed elfNN_ia64_hpux_bed diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 6615841..ea21b62 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -291,6 +291,10 @@ #define elf_info_to_howto_rel 0 #endif +#ifndef ELF_OSABI +#define ELF_OSABI ELFOSABI_NONE +#endif + #ifndef ELF_MAXPAGESIZE #error ELF_MAXPAGESIZE is not defined #define ELF_MAXPAGESIZE 1 @@ -589,6 +593,7 @@ static struct elf_backend_data elfNN_bed = { ELF_ARCH, /* arch */ ELF_MACHINE_CODE, /* elf_machine_code */ + ELF_OSABI, /* elf_osabi */ ELF_MAXPAGESIZE, /* maxpagesize */ ELF_MINPAGESIZE, /* minpagesize */ ELF_COMMONPAGESIZE, /* commonpagesize */ -- cgit v1.1