From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Masahiro Yamada <masahiroy@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Andrii Nakryiko <andrii@kernel.org>,
Nicolas Schier <nicolas@fjasle.eu>, Kees Cook <kees@kernel.org>,
KP Singh <kpsingh@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Sami Tolvanen <samitolvanen@google.com>,
Eduard Zingerman <eddyz87@gmail.com>,
linux-arch@vger.kernel.org, Stanislav Fomichev <sdf@fomichev.me>,
Kent Overstreet <kent.overstreet@linux.dev>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Jann Horn <jannh@google.com>, Ard Biesheuvel <ardb@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Hao Luo <haoluo@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kbuild@vger.kernel.org,
Daniel Borkmann <daniel@iogearbox.net>,
Nathan Chancellor <nathan@kernel.org>,
linux-debuggers@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>, Song Liu <song@kernel.org>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH 1/2] kallsyms: output rodata to ".kallsyms_rodata"
Date: Mon, 24 Feb 2025 17:24:40 -0800 [thread overview]
Message-ID: <87eczm6ckn.fsf@oracle.com> (raw)
In-Reply-To: <CAEf4Bzb9rYHTVkuxxSuoW=0P84M7UPkBr-4991KiMnFsv10hjA@mail.gmail.com>
Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:
> On Sat, Feb 15, 2025 at 6:21 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>>
>> On Fri, Feb 7, 2025 at 10:21 AM Stephen Brennan
>> <stephen.s.brennan@oracle.com> 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 <stephen.s.brennan@oracle.com>
>> > ---
>>
>> 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?
I would be happy to see it merged now.
I don't think it would help anything other than BTF, because most other
things (e.g. kallsyms) refer to symbols via an absolute address. Using
the section offset seems pretty uncommon.
But it still is a nice cleanup anyway.
Thanks,
Stephen
next prev parent reply other threads:[~2025-02-25 1:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 1:20 [PATCH 0/2] Add option for generating BTF types of global variables Stephen Brennan
2025-02-07 1:20 ` [PATCH 1/2] kallsyms: output rodata to ".kallsyms_rodata" Stephen Brennan
2025-02-15 14:21 ` Masahiro Yamada
2025-02-24 18:51 ` Andrii Nakryiko
2025-02-25 1:24 ` Stephen Brennan [this message]
2025-02-25 16:59 ` Andrii Nakryiko
2025-02-07 1:20 ` [PATCH 2/2] btf: Add the option to include global variable types Stephen Brennan
2025-02-07 23:50 ` Alexei Starovoitov
2025-02-11 23:58 ` Stephen Brennan
2025-02-14 1:18 ` Alexei Starovoitov
2025-02-18 23:09 ` Stephen Brennan
2025-02-25 21:47 ` Andrii Nakryiko
2025-02-25 10:01 ` Alan Maguire
2025-02-25 21:52 ` Andrii Nakryiko
2025-02-26 14:20 ` Alan Maguire
2025-02-26 16:57 ` Andrii Nakryiko
2025-05-12 11:15 ` Tony Ambardar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eczm6ckn.fsf@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jannh@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=kent.overstreet@linux.dev \
--cc=kpsingh@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-debuggers@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=masahiroy@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=pasha.tatashin@soleen.com \
--cc=samitolvanen@google.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox