Re: [PATCH] KVM: arm64: Don't use cbz/adr with external symbols
From: Kees Cook
Date: Fri Mar 05 2021 - 15:23:40 EST
On Fri, Mar 05, 2021 at 12:21:24PM -0800, Sami Tolvanen wrote:
> allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following
> linker errors:
>
> ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
> relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in
> [-1048576, 1048575]; references hyp_panic
> >>> defined in vmlinux.o
>
> ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21E0):
> relocation R_AARCH64_ADR_PREL_LO21 out of range: 2031200 is not in
> [-1048576, 1048575]; references hyp_panic
> >>> defined in vmlinux.o
>
> This is because with LTO, the compiler ends up placing hyp_panic()
> more than 1MB away from __guest_enter(). Use an unconditional branch
> and adr_l instead to fix the issue.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1317
> Reported-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> Suggested-by: Marc Zyngier <maz@xxxxxxxxxx>
> Suggested-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
> Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
--
Kees Cook