[syslinux] [PATCH 2/4] efi: Location, size and alignment of .text section
Matt Fleming
matt at console-pimps.org
Fri Nov 29 04:24:02 PST 2013
On Wed, 27 Nov, at 02:38:29PM, Celelibi wrote:
> In the generated PE file, the section header for the .text section used
> to address more than the whole file. Starting at offset 0 (before the
> end of the headers) is illegal and is rejected by OVMF. Giving a size
> greater than the actual file size is also illegal and rejected.
>
> Moreover, the actual data inside the PE file have to be aligned to at
> least 512 bytes. Hence, .text need to be aligned as well.
>
> Signed-off-by: Celelibi <celelibi at gmail.com>
> ---
> efi/wrapper.c | 44 +++++++++++++++++++++++++-------------------
> 1 file changed, 25 insertions(+), 19 deletions(-)
>
> diff --git a/efi/wrapper.c b/efi/wrapper.c
> index ec77271..bd2c175 100644
> --- a/efi/wrapper.c
> +++ b/efi/wrapper.c
> @@ -54,11 +54,15 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
> struct coff_hdr c_hdr;
> struct header hdr;
> struct coff_reloc c_rel;
> - __uint32_t total_sz = so_size;
> + __uint32_t total_sz = data_size;
> __uint32_t dummy = 0;
> __uint32_t hdr_sz;
> __uint32_t reloc_start, reloc_end;
>
> + hdr_sz = 512;
Please include a comment to explain the magic 512.
> @@ -163,6 +159,16 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size,
> fwrite(&c_rel, sizeof(c_rel), 1, f);
> fwrite(&dummy, sizeof(dummy), 1, f);
>
> + /*
> + * Add some padding to align the ELF as needed
> + */
> + if (ftell(f) > t_sec.virtual_address) {
> + // A fseek that rewind would be a bug hard to track
Use C-style comments please.
Other than that, the patch looks good. Thanks!
--
Matt Fleming, Intel Open Source Technology Center
More information about the Syslinux
mailing list