aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Gault <sylvain.gault@gmail.com>2014-02-03 05:43:04 +0100
committerH. Peter Anvin <hpa@linux.intel.com>2014-02-14 16:31:43 -0800
commit0468e14525caea143b4cad8082f2b91876a457ea (patch)
treecd9c95a36c144296816de07eed7ee43c530c2692
parent76ef6aab4a157bba1c53a5da19cecbbee4172a19 (diff)
downloadsyslinux-0468e14525caea143b4cad8082f2b91876a457ea.tar.gz
syslinux-0468e14525caea143b4cad8082f2b91876a457ea.tar.xz
syslinux-0468e14525caea143b4cad8082f2b91876a457ea.zip
efi: Remove buggy relocation in PE file
OVMF and probably other UEFI implementation refuse a file with a relocation entry inside the headers. And since the dummy relocation wasn't used at all, better remove it. Moreover, the field base_relocation_table wasn't initialized properly, leading to unpredictable bugs. Signed-off-by: Sylvain Gault <sylvain.gault@gmail.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--efi/wrapper.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/efi/wrapper.c b/efi/wrapper.c
index 8b553f85..1630bbb7 100644
--- a/efi/wrapper.c
+++ b/efi/wrapper.c
@@ -53,9 +53,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
struct extra_hdr_pe32p e_hdr_pe32p;
struct coff_hdr c_hdr;
struct header hdr;
- struct coff_reloc c_rel;
__uint32_t total_sz = data_size;
- __uint32_t dummy = 0;
__uint32_t hdr_sz;
__uint32_t reloc_start, reloc_end;
@@ -122,7 +120,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
o_hdr_pe32p.entry_point = entry;
o_hdr.initialized_data_sz = data_size;
fwrite(&o_hdr_pe32p, sizeof(o_hdr_pe32p), 1, f);
- memset(&e_hdr_pe32p, 0, sizeof(e_hdr));
+ memset(&e_hdr_pe32p, 0, sizeof(e_hdr_pe32p));
e_hdr_pe32p.section_align = 4096;
e_hdr_pe32p.file_align = 512;
e_hdr_pe32p.image_sz = hdr_sz + so_size;
@@ -144,12 +142,14 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
fwrite(&t_sec, sizeof(t_sec), 1, f);
/*
- * Write our dummy relocation and reloc section.
+ * Write our empty reloc section.
*/
memset(&r_sec, 0, sizeof(r_sec));
strcpy((char *)r_sec.name, ".reloc");
- r_sec.virtual_sz = sizeof(c_rel);
- r_sec.virtual_address = ftell(f) + sizeof(r_sec);
+ r_sec.virtual_sz = 0;
+ /* /!\ Attention! Some UEFI implementations require a valid virtual
+ * address despite the virtual_sz = 0. */
+ r_sec.virtual_address = t_sec.virtual_address;
r_sec.raw_data_sz = r_sec.virtual_sz;
r_sec.raw_data = r_sec.virtual_address;
r_sec.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA |
@@ -157,12 +157,6 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
IMAGE_SCN_MEM_READ;
fwrite(&r_sec, sizeof(r_sec), 1, f);
- memset(&c_rel, 0, sizeof(c_rel));
- c_rel.virtual_address = ftell(f) + sizeof(c_rel);
- c_rel.symtab_index = 10;
- fwrite(&c_rel, sizeof(c_rel), 1, f);
- fwrite(&dummy, sizeof(dummy), 1, f);
-
/*
* Add some padding to align the ELF as needed
*/