[gPXE git] mainline commit to master: [efi] Fix the 32-bit version of elf2efi64
git at etherboot.org
git at etherboot.org
Sun Aug 1 07:48:00 EDT 2010
In the Main gPXE repository, branch master has been updated.
adds c542da3 [efi] Fix the 32-bit version of elf2efi64
from b8d214c [forcedeth] Replace driver with native gPXE driver
Summary of changes:
src/Makefile.housekeeping | 4 ++--
src/util/elf2efi.c | 20 ++++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)
- Log -----------------------------------------------------------------
------
commit c542da3f3d167a79903c6d4cfdbd97891513b954
Author: Geoff Lywood <glywood at vmware.com>
Date: Tue Jul 20 19:23:02 2010 -0700
Committer: Stefan Hajnoczi <stefanha at gmail.com>
[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, 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.
The patch below should fix the problem. I tested this patch by building
with all 4 combinations of 32- and 64-bit toolchains, targeting both 32-
and 64-bit EFI. In each case, I used objdump to verify that the file
format of bin-*-efi/snponly.efi matched what was expected. I also booted
the 64-bit executable that was generated using the 32-bit toolchain.
Signed-off-by: Geoff Lywood <glywood at vmware.com>
Signed-off-by: Stefan Hajnoczi <stefanha at gmail.com>
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index 79a3332..1ddabb1 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -893,12 +893,12 @@ ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
- $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DMDE_CPU_IA32 -O2 -o $@
+ $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 -O2 -o $@
CLEANUP += $(ELF2EFI32)
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
- $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DMDE_CPU_X64 -O2 -o $@
+ $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 -O2 -o $@
CLEANUP += $(ELF2EFI64)
$(EFIROM) : util/efirom.c $(MAKEDEPS)
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index d93391a..7462993 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -52,9 +52,9 @@ struct pe_relocs {
struct pe_header {
EFI_IMAGE_DOS_HEADER dos;
uint8_t padding[128];
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
EFI_IMAGE_NT_HEADERS32 nt;
-#elif defined(MDE_CPU_X64)
+#elif defined(EFI_TARGET_X64)
EFI_IMAGE_NT_HEADERS64 nt;
#endif
};
@@ -67,24 +67,24 @@ static struct pe_header efi_pe_header = {
.nt = {
.Signature = EFI_IMAGE_NT_SIGNATURE,
.FileHeader = {
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
.Machine = EFI_IMAGE_MACHINE_IA32,
-#elif defined(MDE_CPU_X64)
+#elif defined(EFI_TARGET_X64)
.Machine = EFI_IMAGE_MACHINE_X64,
#endif
.TimeDateStamp = 0x10d1a884,
.SizeOfOptionalHeader =
sizeof ( efi_pe_header.nt.OptionalHeader ),
.Characteristics = ( EFI_IMAGE_FILE_DLL |
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
EFI_IMAGE_FILE_32BIT_MACHINE |
#endif
EFI_IMAGE_FILE_EXECUTABLE_IMAGE ),
},
.OptionalHeader = {
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC,
-#elif defined(MDE_CPU_X64)
+#elif defined(EFI_TARGET_X64)
.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC,
#endif
.SectionAlignment = EFI_FILE_ALIGN,
@@ -345,9 +345,9 @@ static struct pe_section * process_section ( bfd *bfd,
/* Extract current RVA limits from file header */
code_start = pe_header->nt.OptionalHeader.BaseOfCode;
code_end = ( code_start + pe_header->nt.OptionalHeader.SizeOfCode );
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
data_start = pe_header->nt.OptionalHeader.BaseOfData;
-#elif defined(MDE_CPU_X64)
+#elif defined(EFI_TARGET_X64)
data_start = code_end;
#endif
data_mid = ( data_start +
@@ -434,7 +434,7 @@ static struct pe_section * process_section ( bfd *bfd,
/* Write RVA limits back to file header */
pe_header->nt.OptionalHeader.BaseOfCode = code_start;
pe_header->nt.OptionalHeader.SizeOfCode = ( code_end - code_start );
-#if defined(MDE_CPU_IA32)
+#if defined(EFI_TARGET_IA32)
pe_header->nt.OptionalHeader.BaseOfData = data_start;
#endif
pe_header->nt.OptionalHeader.SizeOfInitializedData =
-----------------------------------------------------------------------
--
Main gPXE repository
More information about the gPXE-commits
mailing list