Selaa lähdekoodia

[efi] Fix the 32-bit version of elf2efi64

Currently, if elf2efi.c is compiled using a 32-bit HOST_CC, then the
resulting elf2efi64 binary will generate 32-bit EFI binaries instead
of 64-bit EFI binaries.

The problem is that elf2efi.c uses the MDE_CPU_* definitions to decide
whether to output a 32-bit or 64-bit PE binary.  However, MDE_CPU_*
gets defined in ProcessorBind.h, depending on the compiler's target
architecture.  Overriding them on the command line doesn't work in the
expected way, and you can end up in cases where both MDE_CPU_IA32 and
MDE_CPU_X64 are defined.

Fix by using a separate definition, EFI_TARGET_IA32/EFI_TARGET_X64,
which is specified only on the command line.

Signed-off-by: Geoff Lywood <glywood@vmware.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Geoff Lywood 14 vuotta sitten
vanhempi
commit
b8dd94686b
2 muutettua tiedostoa jossa 12 lisäystä ja 12 poistoa
  1. 2
    2
      src/Makefile.housekeeping
  2. 10
    10
      src/util/elf2efi.c

+ 2
- 2
src/Makefile.housekeeping Näytä tiedosto

@@ -907,12 +907,12 @@ ELF2EFI_CFLAGS	:= -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
907 907
 
908 908
 $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
909 909
 	$(QM)$(ECHO) "  [HOSTCC] $@"
910
-	$(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DMDE_CPU_IA32 -O2 -o $@
910
+	$(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 -O2 -o $@
911 911
 CLEANUP += $(ELF2EFI32)
912 912
 
913 913
 $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
914 914
 	$(QM)$(ECHO) "  [HOSTCC] $@"
915
-	$(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DMDE_CPU_X64 -O2 -o $@
915
+	$(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 -O2 -o $@
916 916
 CLEANUP += $(ELF2EFI64)
917 917
 
918 918
 $(EFIROM) : util/efirom.c $(MAKEDEPS)

+ 10
- 10
src/util/elf2efi.c Näytä tiedosto

@@ -52,9 +52,9 @@ struct pe_relocs {
52 52
 struct pe_header {
53 53
 	EFI_IMAGE_DOS_HEADER dos;
54 54
 	uint8_t padding[128];
55
-#if defined(MDE_CPU_IA32)
55
+#if defined(EFI_TARGET_IA32)
56 56
 	EFI_IMAGE_NT_HEADERS32 nt;
57
-#elif defined(MDE_CPU_X64)
57
+#elif defined(EFI_TARGET_X64)
58 58
 	EFI_IMAGE_NT_HEADERS64 nt;
59 59
 #endif
60 60
 };
@@ -67,24 +67,24 @@ static struct pe_header efi_pe_header = {
67 67
 	.nt = {
68 68
 		.Signature = EFI_IMAGE_NT_SIGNATURE,
69 69
 		.FileHeader = {
70
-#if defined(MDE_CPU_IA32)
70
+#if defined(EFI_TARGET_IA32)
71 71
 			.Machine = EFI_IMAGE_MACHINE_IA32,
72
-#elif defined(MDE_CPU_X64)
72
+#elif defined(EFI_TARGET_X64)
73 73
 			.Machine = EFI_IMAGE_MACHINE_X64,
74 74
 #endif
75 75
 			.TimeDateStamp = 0x10d1a884,
76 76
 			.SizeOfOptionalHeader =
77 77
 				sizeof ( efi_pe_header.nt.OptionalHeader ),
78 78
 			.Characteristics = ( EFI_IMAGE_FILE_DLL |
79
-#if defined(MDE_CPU_IA32)
79
+#if defined(EFI_TARGET_IA32)
80 80
 					     EFI_IMAGE_FILE_32BIT_MACHINE |
81 81
 #endif
82 82
 					     EFI_IMAGE_FILE_EXECUTABLE_IMAGE ),
83 83
 		},
84 84
 		.OptionalHeader = {
85
-#if defined(MDE_CPU_IA32)
85
+#if defined(EFI_TARGET_IA32)
86 86
 			.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC,
87
-#elif defined(MDE_CPU_X64)
87
+#elif defined(EFI_TARGET_X64)
88 88
 			.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC,
89 89
 #endif
90 90
 			.SectionAlignment = EFI_FILE_ALIGN,
@@ -345,9 +345,9 @@ static struct pe_section * process_section ( bfd *bfd,
345 345
 	/* Extract current RVA limits from file header */
346 346
 	code_start = pe_header->nt.OptionalHeader.BaseOfCode;
347 347
 	code_end = ( code_start + pe_header->nt.OptionalHeader.SizeOfCode );
348
-#if defined(MDE_CPU_IA32)
348
+#if defined(EFI_TARGET_IA32)
349 349
 	data_start = pe_header->nt.OptionalHeader.BaseOfData;
350
-#elif defined(MDE_CPU_X64)
350
+#elif defined(EFI_TARGET_X64)
351 351
 	data_start = code_end;
352 352
 #endif
353 353
 	data_mid = ( data_start +
@@ -434,7 +434,7 @@ static struct pe_section * process_section ( bfd *bfd,
434 434
 	/* Write RVA limits back to file header */
435 435
 	pe_header->nt.OptionalHeader.BaseOfCode = code_start;
436 436
 	pe_header->nt.OptionalHeader.SizeOfCode = ( code_end - code_start );
437
-#if defined(MDE_CPU_IA32)
437
+#if defined(EFI_TARGET_IA32)
438 438
 	pe_header->nt.OptionalHeader.BaseOfData = data_start;
439 439
 #endif
440 440
 	pe_header->nt.OptionalHeader.SizeOfInitializedData =

Loading…
Peruuta
Tallenna