+2007-03-13 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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 <amodra@bigpond.net.au>
* elf32-v850.c (v850_elf_link_output_symbol_hook): Clean out
/* 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;
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
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;
+}
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
#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
#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"
#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
#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
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;
-}
\f
#define TARGET_BIG_SYM bfd_elf32_i370_vec
#define TARGET_BIG_NAME "elf32-i370"
#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
#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)
#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
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);
#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. */
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
#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"
#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"
#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
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);
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
/* 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
#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
#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
#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
struct bfd_preserve preserve;
asection *s;
bfd_size_type amt;
+ const bfd_target *target;
+ const bfd_target * const *target_ptr;
preserve.marker = NULL;
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);
&& (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;
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;
}
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,
{
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;
}
#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
#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
{
ELF_ARCH, /* arch */
ELF_MACHINE_CODE, /* elf_machine_code */
+ ELF_OSABI, /* elf_osabi */
ELF_MAXPAGESIZE, /* maxpagesize */
ELF_MINPAGESIZE, /* minpagesize */
ELF_COMMONPAGESIZE, /* commonpagesize */