[syslinux:firmware] efi: Fill out MS-DOS header relocs field

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon May 13 06:54:10 PDT 2013


Commit-ID:  5de984d3f42258fb49cfb713002a2e2aae4b16a4
Gitweb:     http://www.syslinux.org/commit/5de984d3f42258fb49cfb713002a2e2aae4b16a4
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 9 May 2013 14:24:21 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Mon, 13 May 2013 12:08:07 +0100

efi: Fill out MS-DOS header relocs field

The relocs field in the MS-DOS header actually indicates the size of the
MS-DOS header and needs filling out with a value >= 0x40. See,

  http://www.ctyme.com/intr/rb-2939.htm#table1594 -

  "18h    WORD    offset within header of relocation table
                  40h or greater for new-format (NE,LE,LX,W3,PE,etc.)
                  executable"

Incidentally, file(1) checks the value of that field to differentiate
MS-DOS executables from PE-COFF files, e.g.

file(1) output before:

  MS-DOS executable

file(1) output after:

  PE32+ executable (EFI application) x86-64 (stripped to external PDB), for MS Windows

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 efi/wrapper.c | 8 ++++++++
 efi/wrapper.h | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/efi/wrapper.c b/efi/wrapper.c
index 0943534..1b1d5d3 100644
--- a/efi/wrapper.c
+++ b/efi/wrapper.c
@@ -60,6 +60,14 @@ static void write_header(FILE *f, __uint32_t entry, __uint32_t so_size, __uint8_
 
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.msdos_signature = MSDOS_SIGNATURE;
+
+	/*
+	 * The relocs table pointer needs to be >= 0x40 for PE files. It
+	 * informs things like file(1) that we are not an MS-DOS
+	 * executable.
+	 */
+	hdr.relocs_ptr = 0x40;
+
 	hdr.pe_hdr = OFFSETOF(struct header, pe_signature);
 	hdr.pe_signature = PE_SIGNATURE;
 	fwrite(&hdr, sizeof(hdr), 1, f);
diff --git a/efi/wrapper.h b/efi/wrapper.h
index 492c262..4f76991 100644
--- a/efi/wrapper.h
+++ b/efi/wrapper.h
@@ -28,7 +28,9 @@
 
 struct header {
 	__uint16_t msdos_signature;
-	__uint8_t _pad1[0x3c - 2];
+	__uint8_t _pad1[0x16];
+	__uint16_t relocs_ptr;
+	__uint8_t __pad2[0x3c - 0x1a];
 	__uint32_t pe_hdr;
 	__uint16_t pe_signature;
 	__uint16_t _pad2;


More information about the Syslinux-commits mailing list