Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: Nick Alcock <nix@esperi.org.uk>
To: "Jose E. Marchesi" <jemarch@gnu.org>
Cc: "Can" <can@tartanoglu.com>, <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Alan Maguire" <alan.maguire@oracle.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"David Faust" <david.faust@oss.qualcomm.com>,
	"Bruce McCulloch" <bruce.mcculloch64@gmail.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>, <linux-kbuild@vger.kernel.org>,
	<dwarves@vger.kernel.org>, <llvm@lists.linux.dev>
Subject: Re: RFC: vmlinux BTF from clang -gbtf, stock lld and a libbpf tool
Date: Fri, 27 Nov 2026 14:07:13 +0000	[thread overview]
Message-ID: <87ecc6fjvy.fsf@esperi.org.uk> (raw)
In-Reply-To: <87fqwmspyg.fsf@gnu.org>

On 27 Nov 2026, Jose E. Marchesi uttered the following:

> [Fixing email adresses of David Faust and Bruce McCullough and Nick
>  Alcock]

Thanks!

>> Alexei asked in llvm/llvm-project#183915 [1][2] for native-vs-pahole
>> results to come here, and suggested dropping BTF dedup from lld in
>> favour of a stock link plus a libbpf-based kernel tool. I closed
>> #183915 and tested that route on saved x86-64 kernel objects.
>>
>> Two headline findings up front:
>>
>> 1. On those saved objects, unmodified ld.lld plus a libbpf prototype
>> reproduced the patched linker's decoded vmlinux BTF (bpftool raw
>> dumps match) and byte-identical .BTF_ids, though not byte-identical
>> .BTF and without booting a host-tool image.
>> 2. On the booted native kernel from the earlier patched-lld run, a
>> verifier negative test (flex_array_unaligned_step in
>> verifier_btf_array_access) unexpectedly loads across all three
>> test_progs flavours because struct vring_used is only a FWD in
>> native BTF. Static checks also show shifted-register FUNC
>> prototypes (e.g. __add_to_kill) and two duplicate-ID warnings in
>> resolve_btfids that fail CONFIG_WERROR=y.
>>
>> The compiler side is LLVM #183929 (-gbtf for non-BPF ELF targets);
>> its

Ooh! I thought I was going to have to implement this. :)

>> Discourse RFC [3] drew a key question from LLVM DebugInfo
>> maintainers:
>> LLVM debug info is best-effort, whereas the verifier and trampolines
>> treat vmlinux BTF as trusted safety and ABI metadata. Before
>> reshaping #183929 or proposing kbuild patches, I'd like feedback on where that
>> trust boundary sits, how functions and DATASECs should be handled,
>> and what GCC/Clang/linker contract makes sense.

I'm quite interested in this too, given my past, ah, arguments over the
possibility of structs with conflicting definitions in different TUs,
the mess pahole makes of them (because it assumes they don't exist, and
accepts the first available struct with a given name it sees), and their
occasional appearance in the kernel. We've even had cases where setting
the wrong kconfig options can cause wildly different duplicate
definitions of things like task_struct, though having structs this
important with the wrong definitions causes the BTF self-tests to fail
disastrously so hopefully nobody would actually ship a kernel that
turned those on.

(I am willing to believe that there is an intent that no such structures
exist in the kernel and thus the file format need not accommodate them,
though CTF, being meant for userspace, has to be more flexible. I stil
don't believe that they don't *appear*, because I've seen them, and
there is no obvious means to keep them from reappearing accidentally.
A deduplicator is of course the perfect place to implement guards
against such things appearing in built kernels, but it has to be able to
spot them first...)

>> true_signature [7]. Whatever comes out of this should work for GCC
>> objects too.

I intend to build CTFv4 support for LLVM on top of it, too, following
which BTF-compatible (CTFv4) support in LLVM-compiled userspace should
be practical, modulo bugs.

>> Saved-object replay (experimental instrument, not a kbuild API)

This is really neat :)

>> Types. In raw BTF, 132 STRUCT/UNION definitions present in pahole are
>> FWD-only in native. In the normalized C-dump comparison (23,109 exact
>> of 23,216 native and 23,490 pahole declaration rows), only 39 show up
>> in fwd_vs_definition.txt; the other 93 (including vring_used) were
>> paired as "exact" against bpftool's synthetic forward declarations
>> and
>> filed under extras.txt (111 pahole rows = 93 missing definitions + 18
>> extra FWDs; 2 native FWDs). Walking pahole's BTF from those 132 roots
>> reaches 149 of 178 pahole-only rows (e.g. acpi_gpio_params via
>> acpi_gpio_mapping).
>>
>> The cause confirmed per-object in libahci.o (ahci_cmd_hdr) and
>> e1000_hw.o (e1000_shadow_ram) is clang's deferred pointee traversal,
>> which emits a FWD even when the CU's DWARF has the full definition.

libctf fuses such things together when it sees them (addition of
structs/unions to a dict when a forward already exists mutates the
forward into a struct/union; addition of a forward when a struct/union
already exists just returns the struct/union; the deduplicator also
avoids emitting forwards unless no concrate definition is visible, and
by the time it emits anything it's already seen everything there is to
see.)

This sort of thing may not be practical in your model though.

      reply	other threads:[~2026-11-27 14:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261121205803.b46d9bd1a88c@tartanoglu.com>
2026-11-27  7:17 ` RFC: vmlinux BTF from clang -gbtf, stock lld and a libbpf tool Jose E. Marchesi
2026-11-27 14:07   ` Nick Alcock [this message]

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=87ecc6fjvy.fsf@esperi.org.uk \
    --to=nix@esperi.org.uk \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=bruce.mcculloch64@gmail.com \
    --cc=can@tartanoglu.com \
    --cc=daniel@iogearbox.net \
    --cc=david.faust@oss.qualcomm.com \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jemarch@gnu.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --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