[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOd=8trq9qndYvf8KD4_3XVfaT_BXcNZhrKP67-YH9WQL0g@mail.gmail.com>
Date: Thu, 3 Dec 2020 11:04:39 -0800
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: Fangrui Song <maskray@...gle.com>
Cc: Arnd Bergmann <arnd@...db.de>,
linux-arch <linux-arch@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>,
Nathan Chancellor <natechancellor@...il.com>,
kernel test robot <lkp@...el.com>, dwmw@...zon.co.uk,
Peter Zijlstra <peterz@...radead.org>,
Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH] firmware_loader: Align .builtin_fw to 8
On Thu, Dec 3, 2020 at 9:05 AM Fangrui Song <maskray@...gle.com> wrote:
>
> arm64 references the start address of .builtin_fw (__start_builtin_fw)
> with a pair of R_AARCH64_ADR_PREL_PG_HI21/R_AARCH64_LDST64_ABS_LO12_NC
> relocations. The compiler is allowed to emit the
> R_AARCH64_LDST64_ABS_LO12_NC relocation because struct builtin_fw in
> include/linux/firmware.h is 8-byte aligned.
>
> The R_AARCH64_LDST64_ABS_LO12_NC relocation requires the address to be a
> multiple of 8, which may not be the case if .builtin_fw is empty.
> Unconditionally align .builtin_fw to fix the linker error.
>
> Fixes: 5658c76 ("firmware: allow firmware files to be built into kernel image")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1204
> Reported-by: kernel test robot <lkp@...el.com>
> Signed-off-by: Fangrui Song <maskray@...gle.com>
> ---
> include/asm-generic/vmlinux.lds.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index b2b3d81b1535..3cd4bd1193ab 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -459,6 +459,7 @@
> } \
> \
> /* Built-in firmware blobs */ \
> + ALIGN_FUNCTION(); \
Thanks for the patch!
I'm going to repeat my question from the above link
(https://github.com/ClangBuiltLinux/linux/issues/1204#issuecomment-737610582)
just in case it's not naive:
ALIGN_FUNCTION() C preprocessor macro seems to be used to realign
code, while STRUCT_ALIGN() seems to be used to realign data. It looks
to me like only data is put into .builtin_fw. If these relocations
require an alignment of 8, than multiples of 8 should also be fine
(STRUCT_ALIGN in 32 for all toolchain version, except gcc 4.9 which is
64; both are multiples of 8 though). It looks like only structs are
placed in .builtin_fw; ie. data. In that case, I worry that using
ALIGN_FUNCTION/8 might actually be under-aligning data in this
section.
Though, in https://github.com/ClangBuiltLinux/linux/issues/1204#issuecomment-737625134
you're comment:
>> In GNU ld, the empty .builtin_fw is removed
So that's a difference in behavior between ld.bfd and ld.lld, which is
fine, but it makes me wonder whether we should instead or additionally
be discarding this section explicitly via linker script when
CONFIG_FW_LOADER is not set?
> .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \
> __start_builtin_fw = .; \
> KEEP(*(.builtin_fw)) \
> --
> 2.29.2.576.ga3fc446d84-goog
>
--
Thanks,
~Nick Desaulniers
Powered by blists - more mailing lists