Re: [PATCH 2/3] kbuild: remove PROVIDE() for kallsyms symbols

From: Masahiro Yamada
Date: Sat May 25 2024 - 12:43:53 EST


On Thu, May 23, 2024 at 6:32 PM Ard Biesheuvel <ardb@xxxxxxxxxx> wrote:
>
> On Wed, 22 May 2024 at 13:48, Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> >
> > This reimplements commit 951bcae6c5a0 ("kallsyms: Avoid weak references
> > for kallsyms symbols").
> >
> > I am not a big fan of PROVIDE() because it always satisfies the linker
> > even in situations that should result in a link error. In other words,
> > it can potentially shift a compile-time error into a run-time error.
> >
>
> I don't disagree. However, I did realize that, in this particular
> case, we could at least make the preliminary symbol definitions
> conditional on CONFIG_KALLSYMS rather than always providing them.


Fair enough. I am fine with dropping this statement.




>
> This approach is also fine with me, though.
>
>
> > Duplicating kallsyms_* in vmlinux.lds.h also reduces maintainability.
> >
> > As an alternative solution, this commit prepends one more kallsyms step.
> >
> > KSYMS .tmp_vmlinux.kallsyms0.S # added
> > AS .tmp_vmlinux.kallsyms0.o # added
> > LD .tmp_vmlinux.btf
> > BTF .btf.vmlinux.bin.o
> > LD .tmp_vmlinux.kallsyms1
> > NM .tmp_vmlinux.kallsyms1.syms
> > KSYMS .tmp_vmlinux.kallsyms1.S
> > AS .tmp_vmlinux.kallsyms1.o
> > LD .tmp_vmlinux.kallsyms2
> > NM .tmp_vmlinux.kallsyms2.syms
> > KSYMS .tmp_vmlinux.kallsyms2.S
> > AS .tmp_vmlinux.kallsyms2.o
> > LD vmlinux
> >
> > Step 0 takes /dev/null as input, and generates .tmp_vmlinux.kallsyms0.o,
> > which has a valid kallsyms format with the empty symbol list, and can be
> > linked to vmlinux. Since it is really small, the added compile-time cost
> > is negligible.
> >
>
> OK, so the number of linker invocations is the same, right? The
> difference is that the kallsyms symbol references are satisfied by a
> dummy object?


Correct.

In 3/3, I even reduce the number of link steps
when both CONFIG_DEBUG_INFO_BTF and CONFIG_KALLSYMS are enabled.





>
> That seems reasonable to me.
>
> For the series,
>
> Acked-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
>


--
Best Regards
Masahiro Yamada