This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Don't match PE/EFI target with EFI/PE file
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Wed, 6 Jun 2007 16:34:12 -0700
- Subject: PATCH: Don't match PE/EFI target with EFI/PE file
When both PE and EFI are enabled for i386/x86-64, objdump will
match both PE and EFI targets with PE/EFI input files. This
patch checks IMAGE_SUBSYSTEM_EFI_APPLICATION to avoid matching
PE/EFI target with EFI/PE file.
H.J.
----
2007-06-06 H.J. Lu <hongjiu.lu@intel.com>
* efi-app-ia32.c (TARGET_NAME): Redefined as "efi-app-i386".
* libpei.h (_bfd_XXi_final_link_postscript): Remove
duplication.
(bfd_target_pei_p): New.
(bfd_target_efi_p): Likewise.
(bfd_pe_executable_p): Use bfd_target_pei_p and
bfd_target_efi_p.
* peicode.h (pe_bfd_object_p): Don't match PE/EFI target with
EFI/PE file if there is an EFI/PE target.
--- bfd/efi-app-ia32.c.efi 2007-04-26 08:57:29.000000000 -0700
+++ bfd/efi-app-ia32.c 2007-06-06 16:12:14.000000000 -0700
@@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street - F
#include "bfd.h"
#define TARGET_SYM bfd_efi_app_ia32_vec
-#define TARGET_NAME "efi-app-ia32"
+#define TARGET_NAME "efi-app-i386"
#define COFF_IMAGE_WITH_PE
#define COFF_WITH_PE
#define PCRELOFFSET TRUE
--- bfd/libpei.h.efi 2006-09-20 04:35:07.000000000 -0700
+++ bfd/libpei.h 2007-06-06 15:50:51.000000000 -0700
@@ -224,7 +224,6 @@
#define _bfd_XX_only_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
#define _bfd_XX_print_private_bfd_data_common _bfd_pex64_print_private_bfd_data_common
#define _bfd_XXi_final_link_postscript _bfd_pex64i_final_link_postscript
-#define _bfd_XXi_final_link_postscript _bfd_pex64i_final_link_postscript
#define _bfd_XXi_only_swap_filehdr_out _bfd_pex64i_only_swap_filehdr_out
#define _bfd_XXi_swap_aouthdr_in _bfd_pex64i_swap_aouthdr_in
#define _bfd_XXi_swap_aouthdr_out _bfd_pex64i_swap_aouthdr_out
@@ -256,7 +255,6 @@
#define _bfd_XX_only_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
#define _bfd_XX_print_private_bfd_data_common _bfd_pep_print_private_bfd_data_common
#define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
-#define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
#define _bfd_XXi_only_swap_filehdr_out _bfd_pepi_only_swap_filehdr_out
#define _bfd_XXi_swap_aouthdr_in _bfd_pepi_swap_aouthdr_in
#define _bfd_XXi_swap_aouthdr_out _bfd_pepi_swap_aouthdr_out
@@ -288,7 +286,6 @@
#define _bfd_XX_only_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
#define _bfd_XX_print_private_bfd_data_common _bfd_pe_print_private_bfd_data_common
#define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
-#define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
#define _bfd_XXi_only_swap_filehdr_out _bfd_pei_only_swap_filehdr_out
#define _bfd_XXi_swap_aouthdr_in _bfd_pei_swap_aouthdr_in
#define _bfd_XXi_swap_aouthdr_out _bfd_pei_swap_aouthdr_out
@@ -302,10 +299,19 @@
#endif /* !COFF_WITH_pep */
-/* Macro: Returns true if the bfd is a PE executable as opposed to a PE object file. */
+/* Returns true if the target is a PE executable target. */
+#define bfd_target_pei_p(xvec) \
+ (CONST_STRNEQ ((xvec)->name, "pei-"))
+
+/* Returns true if the target is an EFI target. */
+#define bfd_target_efi_p(xvec) \
+ (CONST_STRNEQ ((xvec)->name, "efi-app-"))
+
+/* Macro: Returns true if the bfd is a PE executable as opposed to a
+ PE object file. */
#define bfd_pe_executable_p(abfd) \
- (CONST_STRNEQ ((abfd)->xvec->name, "pei-") \
- || CONST_STRNEQ ((abfd)->xvec->name, "efi-app-"))
+ (bfd_target_pei_p ((abfd)->xvec) \
+ || bfd_target_efi_p ((abfd)->xvec))
/* These functions are architecture dependent, and are in peicode.h:
coff_swap_reloc_in
--- bfd/peicode.h.efi 2006-09-20 04:35:07.000000000 -0700
+++ bfd/peicode.h 2007-06-06 16:26:24.000000000 -0700
@@ -1241,6 +1241,7 @@ pe_bfd_object_p (bfd * abfd)
struct external_PEI_DOS_hdr dos_hdr;
struct external_PEI_IMAGE_hdr image_hdr;
file_ptr offset;
+ const bfd_target *target;
/* Detect if this a Microsoft Import Library Format element. */
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
@@ -1305,7 +1306,61 @@ pe_bfd_object_p (bfd * abfd)
return NULL;
}
- return coff_object_p (abfd);
+ target = coff_object_p (abfd);
+ if (target)
+ {
+ pe_data_type *pe = pe_data (abfd);
+ struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
+ bfd_boolean efi = i->Subsystem == IMAGE_SUBSYSTEM_EFI_APPLICATION;
+ const char *machine;
+ const bfd_target * const *target_ptr;
+
+ /* Get the machine. */
+ if (bfd_target_efi_p (abfd->xvec))
+ machine = abfd->xvec->name + sizeof ("efi-app-") - 1;
+ else
+ machine = abfd->xvec->name + sizeof ("pei-") - 1;
+
+ for (target_ptr = bfd_target_vector; *target_ptr != NULL;
+ target_ptr++)
+ {
+ if (*target_ptr == target
+ || (*target_ptr)->flavour != bfd_target_coff_flavour)
+ continue;
+
+ if (bfd_target_efi_p (*target_ptr))
+ {
+ /* Skip incompatible machine. */
+ if (strcmp ((*target_ptr)->name + sizeof ("efi-app-") - 1,
+ machine))
+ continue;
+
+ if (!efi)
+ {
+ /* target_ptr is an EFI backend. Don't match it
+ with a PE file if there is a PE target. */
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+ }
+ else if (bfd_target_pei_p (*target_ptr))
+ {
+ if (strcmp ((*target_ptr)->name + sizeof ("pei-") - 1,
+ machine))
+ continue;
+
+ if (efi)
+ {
+ /* target_ptr is a PE backend. Don't match it
+ with an EFI file if there is a EFI target. */
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
+ }
+ }
+ }
+
+ return target;
}
#define coff_object_p pe_bfd_object_p