PATCH: PR binutils/3826: elf_object_p can't tell freebsd object file from standard ELF object file
H. J. Lu
hjl@lucon.org
Thu Jan 4 15:31:00 GMT 2007
More information about the Binutils mailing list
Thu Jan 4 15:31:00 GMT 2007
- Previous message (by thread): PATCH: Remember the symbol size if it isn't undefined
- Next message (by thread): PATCH: PR binutils/3826: elf_object_p can't tell freebsd object file from standard ELF object file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The problem is elf_object_p doesn't check EI_OSABI. This patch implements EI_OSABI checking for i386, x86-64 and ia64. I can add it to other arches. H.J. ---- 2076-01-04 H.J. Lu <hongjiu.lu@intel.com> PR binutils/3826 * elf-bfd.h (elf_backend_data): Add elf_osabi. (_bfd_elf_post_process_headers): New. * elf.c (_bfd_elf_post_process_headers): New. * elf32-i386.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebfd. (elf_i386_post_process_headers): Set EI_OSABI with elf_osabi. Defined only if OLD_FREEBSD_ABI_LABEL is defined. * elf64-x86-64.c (ELF_OSABI): Defined to ELFOSABI_FREEBSD for freebfd. (elf64_x86_64_fbsd_post_process_headers): Removed. * elfcode.h (elf_object_p): Also check EI_OSABI. * elfxx-target.h (ELF_OSABI): Default to ELFOSABI_NONE. (elf_backend_post_process_headers): Default to _bfd_elf_post_process_headers. (elfNN_bed): Initialize elf_osabi with ELF_OSABI. --- bfd/elf-bfd.h.fbsd 2007-01-04 06:27:49.000000000 -0800 +++ bfd/elf-bfd.h 2007-01-04 07:22:34.000000000 -0800 @@ -546,6 +546,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; @@ -1731,6 +1734,9 @@ extern bfd_boolean bfd_elf_match_symbols extern bfd_boolean _bfd_elf_setup_sections (bfd *); +extern void _bfd_elf_post_process_headers + (bfd * , struct bfd_link_info *); + extern const bfd_target *bfd_elf32_object_p (bfd *); extern const bfd_target *bfd_elf32_core_file_p --- bfd/elf.c.fbsd 2007-01-04 06:27:49.000000000 -0800 +++ bfd/elf.c 2007-01-04 07:22:07.000000000 -0800 @@ -9008,3 +9008,14 @@ _bfd_elf_match_sections_by_type (bfd *ab return elf_section_type (asec) == elf_section_type (bsec); } + +void +_bfd_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] = get_elf_backend_data (abfd)->elf_osabi; +} --- bfd/elf32-i386.c.fbsd 2007-01-04 07:06:44.000000000 -0800 +++ bfd/elf32-i386.c 2007-01-04 07:24:25.000000000 -0800 @@ -3881,6 +3881,10 @@ elf_i386_hash_symbol (struct elf_link_ha #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf32-i386-freebsd" +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD + +#ifdef OLD_FREEBSD_ABI_LABEL /* 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. */ @@ -3894,15 +3898,15 @@ 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; -#ifdef OLD_FREEBSD_ABI_LABEL + i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); -#endif } #undef elf_backend_post_process_headers #define elf_backend_post_process_headers elf_i386_post_process_headers +#endif + #undef elf32_bed #define elf32_bed elf32_i386_fbsd_bed @@ -3915,6 +3919,7 @@ elf_i386_post_process_headers (bfd *abfd #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. */ --- bfd/elf64-x86-64.c.fbsd 2006-11-02 19:36:09.000000000 -0800 +++ bfd/elf64-x86-64.c 2007-01-04 07:19:52.000000000 -0800 @@ -3710,24 +3710,8 @@ static const struct bfd_elf_special_sect #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_backend_post_process_headers -#define elf_backend_post_process_headers elf64_x86_64_fbsd_post_process_headers +#undef ELF_OSABI +#define ELF_OSABI ELFOSABI_FREEBSD #undef elf64_bed #define elf64_bed elf64_x86_64_fbsd_bed --- bfd/elfcode.h.fbsd 2006-09-22 06:26:29.000000000 -0700 +++ bfd/elfcode.h 2007-01-04 07:08:00.000000000 -0800 @@ -613,6 +613,11 @@ elf_object_p (bfd *abfd) } } + /* Check EI_OSABI. */ + if (i_ehdrp->e_ident[EI_OSABI] + != get_elf_backend_data (abfd)->elf_osabi) + goto got_wrong_format_error; + if (i_ehdrp->e_type == ET_EXEC) abfd->flags |= EXEC_P; else if (i_ehdrp->e_type == ET_DYN) --- bfd/elfxx-ia64.c.fbsd 2006-11-02 19:36:09.000000000 -0800 +++ bfd/elfxx-ia64.c 2007-01-04 07:11:32.000000000 -0800 @@ -5680,7 +5680,7 @@ elfNN_hpux_post_process_headers (abfd, i { 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,9 @@ elfNN_hpux_backend_symbol_processing (bf #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 --- bfd/elfxx-target.h.fbsd 2006-12-25 07:17:10.000000000 -0800 +++ bfd/elfxx-target.h 2007-01-04 07:19:07.000000000 -0800 @@ -285,6 +285,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 @@ -422,7 +426,7 @@ #define elf_backend_got_header_size 0 #endif #ifndef elf_backend_post_process_headers -#define elf_backend_post_process_headers NULL +#define elf_backend_post_process_headers _bfd_elf_post_process_headers #endif #ifndef elf_backend_print_symbol_all #define elf_backend_print_symbol_all NULL @@ -581,6 +585,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 */
- Previous message (by thread): PATCH: Remember the symbol size if it isn't undefined
- Next message (by thread): PATCH: PR binutils/3826: elf_object_p can't tell freebsd object file from standard ELF object file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list