From: "Thiébaud Weksteen" <tweek@google.com>
To: "Quentin Monnet" <qmo@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>,
"Shuah Khan" <shuah@kernel.org>,
"Thiébaud Weksteen" <tweek@google.com>,
"KP Singh" <kpsingh@kernel.org>,
"Leon Hwang" <leon.hwang@linux.dev>,
"Emil Tsalapatis" <emil@etsalapatis.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next v3 2/3] bpftool: Compute light skeleton ctx.sz without relying on links
Date: Fri, 18 Sep 2026 14:09:18 +1000 [thread overview]
Message-ID: <20260918040919.3402577-2-tweek@google.com> (raw)
In-Reply-To: <20260918040919.3402577-1-tweek@google.com>
When generating a light skeleton, gen_trace() unconditionally sets
skel->ctx.sz using (char *)&skel->links - (char *)skel. However, if a
BPF object has no programs and no struct_ops maps (prog_cnt +
attach_map_cnt == 0), do_skeleton() omits the links struct, causing the
generated skeleton header to fail compilation.
Compute skel->ctx.sz from the end of progs (if prog_cnt > 0), maps (if
map_cnt > 0), or ctx instead of relying on skel->links. Also remove the
unused opts.data_sz argument passed to codegen().
Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
Signed-off-by: Thiébaud Weksteen <tweek@google.com>
---
No changes since v2
tools/bpf/bpftool/gen.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 1e55f0e67d91..b275373b3781 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -711,7 +711,7 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)
}
static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard,
- const struct gen_loader_opts *opts)
+ const struct gen_loader_opts *opts, size_t prog_cnt, size_t map_cnt)
{
struct bpf_load_and_run_opts sopts = {};
char sig_buf[MAX_SIG_SIZE];
@@ -742,9 +742,16 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
skel = (struct %1$s *)skel_alloc(sizeof(*skel)); \n\
if (!skel) \n\
goto cleanup; \n\
- skel->ctx.sz = (char *)&skel->links - (char *)skel; \n\
",
- obj_name, opts->data_sz);
+ obj_name);
+ if (prog_cnt)
+ printf("\tskel->ctx.sz = (char *)&skel->progs - (char *)skel\n"
+ "\t\t + sizeof(skel->progs);\n");
+ else if (map_cnt)
+ printf("\tskel->ctx.sz = (char *)&skel->maps - (char *)skel\n"
+ "\t\t + sizeof(skel->maps);\n");
+ else
+ printf("\tskel->ctx.sz = sizeof(skel->ctx);\n");
bpf_object__for_each_map(map, obj) {
const void *mmap_data = NULL;
size_t mmap_size = 0;
@@ -1473,7 +1480,7 @@ static int do_skeleton(int argc, char **argv)
goto out;
}
if (use_loader) {
- err = gen_trace(obj, obj_name, header_guard, &gen_opts);
+ err = gen_trace(obj, obj_name, header_guard, &gen_opts, prog_cnt, map_cnt);
goto out;
}
--
2.55.0.1082.g2b9226bbc0-goog
next prev parent reply other threads:[~2026-09-18 4:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 4:09 [PATCH bpf-next v3 1/3] bpftool: Skip non-autoload programs when generating light skeletons Thiébaud Weksteen
2026-09-18 4:09 ` Thiébaud Weksteen [this message]
2026-09-18 8:42 ` [PATCH bpf-next v3 2/3] bpftool: Compute light skeleton ctx.sz without relying on links Quentin Monnet
2026-09-18 4:09 ` [PATCH bpf-next v3 3/3] selftests/bpf: Add iter subtest using lskel in global_data_init Thiébaud Weksteen
2026-09-18 5:05 ` bot+bpf-ci
2026-09-18 8:43 ` [PATCH bpf-next v3 1/3] bpftool: Skip non-autoload programs when generating light skeletons Quentin Monnet
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=20260918040919.3402577-2-tweek@google.com \
--to=tweek@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
--cc=shuah@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
all inboxes | Powered by JetHome®