You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EFI stub booting fails with ld.lld: __efistub__end miscalculated #634
ld.lld: error: /home/kees/src/linux/drivers/firmware/efi/libstub/arm64-stub.c:134:(.init.text+0x70): relocation R_AARCH64_ADR_PREL_PG_HI21 out of range: -70505092558848 is not in [-4294967296, 4294967295]
line 134 is:
*reserve_size = round_up(kernel_memsize, EFI_ALLOC_ALIGN);
This is only visible if I disable CONFIG_ARM64_ERRATUM_843419. If I leave this enabled, the EFI stub fails to boot the kernel, with handle_kernel_image() failing...
changed the title [-]relocation R_AARCH64_ADR_PREL_PG_HI21 out of range[/-][+]EFI stub booting fails with ld.lld: __efistub__end miscalculated[/+]on Aug 9, 2019
This math works out to 0x5000 in both bfd and lld (measured by adding __init_pg_size = ABSOLUTE(. - init_pg_dir);) However, lld for some reason breaks __efistub__end afterwards:
When I revert the kernel work-around for #561 but move all the variables assignments to after the SECTIONS, I appear to get the correct value for __efistub_stext_offset! I thought I tested this when checking for bug dups, but I guess I did it wrong initially. :)
@kees Do you mind patching in that change and check if that fixes the linking problem? cd path/to/lld; curl -L 'https://reviews.llvm.org/D66279?download=true' | patch -p0
Activity
kees commentedon Aug 9, 2019
Just for fun, if I try to remove references to _text, _edata, and _end:
I get a different error:
kallsyms failure: relative symbol value 0xffff000001c36000 out of range in relative mode
kees commentedon Aug 9, 2019
I think this is all due to a negative calculation about kernel_memsize (and likely the real bug). With ld.bfd:
ffff0000110f91e4: f0ff7c39 adrp x25, ffff000010080000 <__efistub__text>
ffff0000110f91e8: f90002f8 str x24, [x23]
ffff0000110f91ec: f90002b8 str x24, [x21]
ffff0000110f91f0: 91000339 add x25, x25, #0x0
ffff0000110f91f4: 90007138 adrp x24, ffff000011f1d000 <__efistub__end>
with ld.lld __efistub__end is very wrong (off by 0x10000000):
ffff0000111191f4: b0f86878 adrp x24, ffff000001e26000 <__efistub__end>
Literally adding 0x10000000 to kernel_memsize appears to fix it (?!)
[-]relocation R_AARCH64_ADR_PREL_PG_HI21 out of range[/-][+]EFI stub booting fails with ld.lld: __efistub__end miscalculated[/+]nickdesaulniers commentedon Aug 9, 2019
cc @smithp35
kees commentedon Aug 12, 2019
FYI, to reproduce this under qemu, just add the following drive arguments, after copying
AAVMF_VARS.fdto the local directory from/usr/share/AAVMF/:If I leave these off, the kernels boot fine, so something with the EFI stub's symbol aliases and objcopy pass break the
_endlocation.kees commentedon Aug 13, 2019
Trouble appears to be with processing the linker script, perhaps due to _end being present in math leading up to its definition:
This math works out to 0x5000 in both bfd and lld (measured by adding
__init_pg_size = ABSOLUTE(. - init_pg_dir);) However, lld for some reason breaks __efistub__end afterwards:bfd doesn't:
kees commentedon Aug 13, 2019
Ugh. It's evaluation ordering. ld.lld treats an assignment as an immediate assignment instead of as an alias:
poc.lds:
but if
__efistub__end = _end;is moved afterSECTIONS:nathanchance commentedon Aug 13, 2019
Is this potentially related to #561?
nickdesaulniers commentedon Aug 13, 2019
cc @MaskRay @ardbiesheuvel @georgiir @rui314 @smithp35
Thanks for the reproducer, @kees !
kees commentedon Aug 13, 2019
https://llvm.org/pr42990
kees commentedon Aug 13, 2019
When I revert the kernel work-around for #561 but move all the variables assignments to after the SECTIONS, I appear to get the correct value for __efistub_stext_offset! I thought I tested this when checking for bug dups, but I guess I did it wrong initially. :)
5 remaining items
MaskRay commentedon Aug 15, 2019
Proposed lld patch: https://reviews.llvm.org/D66279 . Peter said it should be close.
@kees Do you mind patching in that change and check if that fixes the linking problem?
cd path/to/lld; curl -L 'https://reviews.llvm.org/D66279?download=true' | patch -p0The convergence problem may be a bit more tractable than #561 (https://llvm.org/pr42506).
driver: Support booting via EFI on arm64 and x86_64
nathanchance commentedon Aug 16, 2019
That patch works fine here.
MaskRay commentedon Aug 26, 2019
https://reviews.llvm.org/D66279 was committed as r369889. It will be included in lld 10.
I left some notes at https://reviews.llvm.org/D66279#1632518 about how ld.bfd evaluates expressions.
powerpc/powernv/ioda2: Allocate TCE table levels on demand for defaul…
arm64/efi: Move variable assignments after SECTIONS
arm64/efi: Move variable assignments after SECTIONS
arm64/efi: Move variable assignments after SECTIONS
arm64/efi: Move variable assignments after SECTIONS
arm64/efi: Move variable assignments after SECTIONS
arm64/efi: Move variable assignments after SECTIONS