[syslinux] [PATCH v2 1/4] efi: Fix PE header field rva_and_sizes_nr

Celelibi celelibi at gmail.com
Sun Dec 1 14:14:02 PST 2013


The value of the field rva_and_sizes_nr is used by OVMF to check the
consistency of the PE file with respect to the field optional_hdr_sz. It
now have the right value.

Signed-off-by: Celelibi <celelibi at gmail.com>
---
 efi/wrapper.c |  6 +++---
 efi/wrapper.h | 28 ++++++++++++++++------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/efi/wrapper.c b/efi/wrapper.c
index 04c895f..ec77271 100644
--- a/efi/wrapper.c
+++ b/efi/wrapper.c
@@ -102,7 +102,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
 		e_hdr.image_sz = total_sz;
 		e_hdr.headers_sz = 512;
 		e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
-		e_hdr.rva_and_sizes_nr = 1;
+		e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t);
 		fwrite(&e_hdr, sizeof(e_hdr), 1, f);
 	}
 	else if (class == ELFCLASS64) {
@@ -130,7 +130,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
 		e_hdr_pe32p.image_sz = total_sz;
 		e_hdr_pe32p.headers_sz = 512;
 		e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
-		e_hdr_pe32p.rva_and_sizes_nr = 1;
+		e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t);
 		fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f);
 	}
 
@@ -237,7 +237,7 @@ int main(int argc, char **argv)
 		fprintf(stderr, "Unsupported architecture\n");
 		exit(EXIT_FAILURE);
 	}
-		
+
 	if (id[EI_MAG0] != ELFMAG0 ||
 	    id[EI_MAG1] != ELFMAG1 ||
 	    id[EI_MAG2] != ELFMAG2 ||
diff --git a/efi/wrapper.h b/efi/wrapper.h
index 4f76991..0e6b38e 100644
--- a/efi/wrapper.h
+++ b/efi/wrapper.h
@@ -102,12 +102,14 @@ struct extra_hdr {
 	__uint32_t heap_commit_sz;
 	__uint32_t loader_flags;
 	__uint32_t rva_and_sizes_nr;
-	__uint64_t export_table;
-	__uint64_t import_table;
-	__uint64_t resource_table;
-	__uint64_t exception_table;
-	__uint64_t certification_table;
-	__uint64_t base_relocation_table;
+	struct {
+		__uint64_t export_table;
+		__uint64_t import_table;
+		__uint64_t resource_table;
+		__uint64_t exception_table;
+		__uint64_t certification_table;
+		__uint64_t base_relocation_table;
+	} data_directory;
 } __packed;
 
 /* Extra header for PE32+ format 
@@ -136,12 +138,14 @@ struct extra_hdr_pe32p {
 	__uint64_t heap_commit_sz;
 	__uint32_t loader_flags;
 	__uint32_t rva_and_sizes_nr;
-	__uint64_t export_table;
-	__uint64_t import_table;
-	__uint64_t resource_table;
-	__uint64_t exception_table;
-	__uint64_t certification_table;
-	__uint64_t base_relocation_table;
+	struct {
+		__uint64_t export_table;
+		__uint64_t import_table;
+		__uint64_t resource_table;
+		__uint64_t exception_table;
+		__uint64_t certification_table;
+		__uint64_t base_relocation_table;
+	} data_directory;
 } __packed;
 
 struct section {
-- 
1.8.4.3



More information about the Syslinux mailing list