Re: git: 7eb26be9c808 - main - arm64: Use adrp + :lo12: to load globals from asm

From: Jessica Clarke <jrtc27_at_freebsd.org>
Date: Wed, 15 Nov 2023 18:23:27 UTC
On 15 Nov 2023, at 18:12, Andrew Turner <andrew@FreeBSD.org> wrote:
> 
> The branch main has been updated by andrew:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=7eb26be9c8080686f64fdc0a28e5ae7839bbc82d
> 
> commit 7eb26be9c8080686f64fdc0a28e5ae7839bbc82d
> Author:     Andrew Turner <andrew@FreeBSD.org>
> AuthorDate: 2023-11-11 09:27:30 +0000
> Commit:     Andrew Turner <andrew@FreeBSD.org>
> CommitDate: 2023-11-15 18:05:08 +0000
> 
>    arm64: Use adrp + :lo12: to load globals from asm
> 
>    When loading a global variable we can use a pseudo-instruction similar
>    to "ldr, xn, =global" to load the address of the symbol. As this is
>    unlikely to be supported by a mov instruction a pc-relative load is
>    used, with the absolute address written at the end of the function so
>    it will be loaded.
> 
>    This load can be partially replaced with an adrp instruction. This
>    generates the address, aligned to a 4k boundary, using a pc-relative
>    addition. Because the address is 4k-aligned we then update reading the
>    global variable using a load with the offset of the load the low
>    12-bits of the global. Arm64 assemblers have :lo12: to support this,
>    e.g. "ldr xn, [xn, :lo12:global]".
> 
>    The only remaining users of "ldr, xn, =global" that I can find are
>    executed from the physical address space the kernel was loaded in and
>    need an address in the kernels virtual address space. Because of this
>    they can't use adrp.
> 
>    Sponsored by:   Arm Ltd
>    Differential Revision:  https://reviews.freebsd.org/D42565

I assume the motivation for this, which seems to be missing from the
description, is that it removes an unnecessary level of indirection,
rather than that there are issues with the PC-relative load literal
instruction not working, given that I doubt we’re hitting the 1 MiB
literal pool offset range limit in hand-written assembly?

Jess