Re: [PATCH 1/2] kallsyms: output rodata to ".kallsyms_rodata"
Andrii Nakryiko <[email protected]> Mon, 24 Feb 2025 10:51:38 -0800
| Newsgroups | org.kernel.vger.linux-debuggers,org.kernel.vger.bpf,org.kernel.vger.linux-arch,org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAEf4Bzb9rYHTVkuxxSuoW=0P84M7UPkBr-4991KiMnFsv10hjA@mail.gmail.com> |
On Sat, Feb 15, 2025 at 6:21 AM Masahiro Yamada <[email protected]> wrote: > > On Fri, Feb 7, 2025 at 10:21 AM Stephen Brennan > <[email protected]> wrote: > > > > When vmlinux is linked, the rodata from kallsyms is placed arbitrarily > > within the .rodata section. The linking process is repeated several > > times, since the kallsyms data size changes, which shifts symbols, > > requiring re-generating the data and re-linking. > > > > BTF is generated during the first link only. For variables, BTF includes > > a BTF_K_DATASEC for each data section that may contain a variable, which > > includes the variable's name, type, and offset within the data section. > > Because the size of kallsyms data changes during later links, the > > offsets of variables placed after it in .rodata will change. This means > > that BTF_K_DATASEC information for those variables becomes inaccurate. > > > > This is not currently a problem, because BTF currently only generates > > variable data for percpu variables. However, the next commit will add > > support for generating BTF for all global variables, including for the > > .rodata section. > > > > We could re-generate BTF each time vmlinux is linked, but this is quite > > expensive, and should be avoided at all costs. Further as each chunk of > > data (BTF and kallsyms) are re-generated, there's no guarantee that > > their sizes will converge anyway. > > > > Instead, we can take advantage of the fact that BTF only cares to store > > the offset of variables from the start of their section. Therefore, so > > long as the kallsyms data is stored last in the .rodata section, no > > offsets will be affected. Adjust kallsyms to output to .rodata.kallsyms, > > and update the linker script to include this at the end of .rodata. > > > > Signed-off-by: Stephen Brennan <[email protected]> > > --- > > I am fine if this is helpful for BTF. This seems like a useful change all by itself even while the main feature of this patch set is still being developed and reviewed. Should we land just this .kallsyms_rodata change? > > > > -- > Best Regards > Masahiro Yamada