Re: [PATCH 2/5] efi/x86: Decompress at start of PE image load address

From: Arvind Sankar
Date: Tue Mar 03 2020 - 08:45:27 EST


On Tue, Mar 03, 2020 at 06:28:20AM +0000, Mika Penttilà wrote:
>
>
> On 2.3.2020 1.05, Arvind Sankar wrote:
> > When booted via PE loader, define image_offset to hold the offset of
> > startup_32 from the start of the PE image, and use it as the start of
> > the decompression buffer.
> >
> > Signed-off-by: Arvind Sankar <nivedita@xxxxxxxxxxxx>
> > ---
> > arch/x86/boot/compressed/head_32.S | 17 +++++++++++
> > arch/x86/boot/compressed/head_64.S | 38 +++++++++++++++++++++++--
> > drivers/firmware/efi/libstub/x86-stub.c | 12 ++++++--
> > 3 files changed, 61 insertions(+), 6 deletions(-)
>
> ...
> > --- a/drivers/firmware/efi/libstub/x86-stub.c
> > +++ b/drivers/firmware/efi/libstub/x86-stub.c
> > @@ -19,6 +19,7 @@
> >
> > static efi_system_table_t *sys_table;
> > extern const bool efi_is64;
> > +extern u32 image_offset;
> >
> > __pure efi_system_table_t *efi_system_table(void)
> > {
> > @@ -364,6 +365,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
> > struct boot_params *boot_params;
> > struct setup_header *hdr;
> > efi_loaded_image_t *image;
> > + void *image_base;
> > efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
> > int options_size = 0;
> > efi_status_t status;
> > @@ -384,7 +386,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
> > efi_exit(handle, status);
> > }
> >
> > - hdr = &((struct boot_params *)efi_table_attr(image, image_base))->hdr;
> > + image_base = efi_table_attr(image, image_base);
> > + image_offset = (void *)startup_32 - image_base;
>
> startup_32 == 0, so maybe something like
>
> leaq startup_32(%rip) - image_base
>
> should be used ?
>

That's what it already uses. All the files in this directory are
compiled to be position-independent, so it uses rip-relative addressing
on 64-bit and GOT-relative addressing on 32-bit.