diff mbox series

[v2,01/20] x86: decompressor: Use proper sequence to take the address of the GOT

Message ID 20230508070330.582131-2-ardb@kernel.org
State Superseded
Headers show
Series efi/x86: Avoid bare metal decompressor during EFI boot | expand

Commit Message

Ard Biesheuvel May 8, 2023, 7:03 a.m. UTC
We don't actually use a global offset table (GOT) in the 32-bit
decompressor, but as is common for 32-bit position independent code, we
use the magic symbol _GLOBAL_OFFSET_TABLE_ as an anchor from which to
derive the actual runtime addresses of other symbols, using special
@GOTOFF symbol references that are resolved at link time, and populated
with the distance between the address of the magic _GLOBAL_OFFSET_TABLE_
anchor and the address of the symbol in question.

This means _GLOBAL_OFFSET_TABLE_ is the only symbol whose actual runtime
address we have to determine explicitly, which is one of the first
things we do in startup_32. However, we do so by taking the absolute
address via the immediate field of an ADD instruction (plus a small
offset), and taking absolute addresses that need to be resolved at link
time is what we are trying to avoid.

Fortunately, the assembler knows that _GLOBAL_OFFSET_TABLE_ is magic,
and emits a special relative relocation instead, and so the resulting
code works as expected. However, this is not obvious for someone reading
the code, and the use of LEA with an explicit relative addend is more
idiomatic so use that instead.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/boot/compressed/head_32.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Borislav Petkov May 17, 2023, 5:31 p.m. UTC | #1
Please fix all your subjects as explained here:

https://kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject

On Mon, May 08, 2023 at 09:03:11AM +0200, Ard Biesheuvel wrote:
> We don't actually use a global offset table (GOT) in the 32-bit

Please use passive voice in your commit message: no "we" or "I", etc,
and describe your changes in imperative mood.

Personal pronouns are ambiguous in text, especially with
so many parties/companies/etc developing the kernel so let's avoid them
please.

> diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
> index 987ae727cf9f0d04..53cbee1e2a93efce 100644
> --- a/arch/x86/boot/compressed/head_32.S
> +++ b/arch/x86/boot/compressed/head_32.S
> @@ -58,7 +58,7 @@ SYM_FUNC_START(startup_32)
>  	leal	(BP_scratch+4)(%esi), %esp
>  	call	1f
>  1:	popl	%edx
> -	addl	$_GLOBAL_OFFSET_TABLE_+(.-1b), %edx
> +	leal	(_GLOBAL_OFFSET_TABLE_ - 1b)(%edx), %edx

Yeah, that's a bit better.

Thx.
Ard Biesheuvel May 17, 2023, 5:39 p.m. UTC | #2
On Wed, 17 May 2023 at 19:31, Borislav Petkov <bp@alien8.de> wrote:
>
> Please fix all your subjects as explained here:
>
> https://kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject
>
> On Mon, May 08, 2023 at 09:03:11AM +0200, Ard Biesheuvel wrote:
> > We don't actually use a global offset table (GOT) in the 32-bit
>
> Please use passive voice in your commit message: no "we" or "I", etc,
> and describe your changes in imperative mood.
>
> Personal pronouns are ambiguous in text, especially with
> so many parties/companies/etc developing the kernel so let's avoid them
> please.
>

Ack.

> > diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
> > index 987ae727cf9f0d04..53cbee1e2a93efce 100644
> > --- a/arch/x86/boot/compressed/head_32.S
> > +++ b/arch/x86/boot/compressed/head_32.S
> > @@ -58,7 +58,7 @@ SYM_FUNC_START(startup_32)
> >       leal    (BP_scratch+4)(%esi), %esp
> >       call    1f
> >  1:   popl    %edx
> > -     addl    $_GLOBAL_OFFSET_TABLE_+(.-1b), %edx
> > +     leal    (_GLOBAL_OFFSET_TABLE_ - 1b)(%edx), %edx
>
> Yeah, that's a bit better.
>
> Thx.
>
> --
> Regards/Gruss,
>     Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
diff mbox series

Patch

diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 987ae727cf9f0d04..53cbee1e2a93efce 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -58,7 +58,7 @@  SYM_FUNC_START(startup_32)
 	leal	(BP_scratch+4)(%esi), %esp
 	call	1f
 1:	popl	%edx
-	addl	$_GLOBAL_OFFSET_TABLE_+(.-1b), %edx
+	leal	(_GLOBAL_OFFSET_TABLE_ - 1b)(%edx), %edx
 
 	/* Load new GDT */
 	leal	gdt@GOTOFF(%edx), %eax