From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
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>,
Shuah Khan <shuah@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Michal Luczaj <mhal@rbox.co>, Sechang Lim <rhkrqnwk98@gmail.com>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH bpf v1] selftests/bpf: Fix CO-RE relocation of anonymous unions for bpf-gcc
Date: Tue, 17 Nov 2026 17:45:38 +0800 [thread overview]
Message-ID: <20261117094544.148437-1-jiayuan.chen@linux.dev> (raw)
bpf-gcc fails to load test_trace_iter_unix:
Error: #766/6 verifier_sockmap_mutate/test_trace_iter_unix
libbpf: elf: skipping section(3) .data (size 0)
libbpf: elf: skipping unrecognized data section(18) .comment
run_subtest:PASS:obj_open_mem 0 nsec
libbpf: prog 'test_trace_iter_unix': relo #0: insn #0 (LDX/ST/STX) accesses field incorrectly. ...
libbpf: prog 'test_trace_iter_unix': BPF program load failed: -EINVAL
libbpf: prog 'test_trace_iter_unix': failed to load: -EINVAL
libbpf: failed to load object 'verifier_sockmap_mutate'
run_subtest:PASS:unexpected_load_success 0 nsec
validate_msgs:FAIL:1014 expect_msg
VERIFIER LOG:
=============
0: R1=ctx() R10=fp0
; @ verifier_sockmap_mutate.c:124
0: <invalid CO-RE relocation>
failed to resolve CO-RE relocation <byte_off> [4] struct bpf_iter__unix (0:0 @ offset 0)
processed 1 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
=============
EXPECTED SUBSTR: 'cannot update sockmap in this context'
GCC only applies preserve_access_index to types that carry the attribute
themselves. The anonymous union holding the sock pointer doesn't, so the
CO-RE access stops at the union ("0:0") instead of reaching the pointer
("0:0:0"), and libbpf rejects the relocation. Mark the unions too.
Fixes: e16c83fa764f ("selftests/bpf: Add negative test for sockmap update from non-sockmap iter")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c b/tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c
index 1516fe1524bb..68b1a5323470 100644
--- a/tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c
+++ b/tools/testing/selftests/bpf/progs/verifier_sockmap_mutate.c
@@ -16,13 +16,13 @@ struct sock {
struct bpf_iter__sockmap {
union {
struct sock *sk;
- };
+ } __attribute__((preserve_access_index));
} __attribute__((preserve_access_index));
struct bpf_iter__unix {
union {
struct sock *unix_sk;
- };
+ } __attribute__((preserve_access_index));
} __attribute__((preserve_access_index));
struct {
--
2.43.0
next reply other threads:[~2026-11-17 9:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:45 Jiayuan Chen [this message]
2026-11-17 11:19 ` [PATCH bpf v1] selftests/bpf: Fix CO-RE relocation of anonymous unions for bpf-gcc Michal Luczaj
2026-11-17 11:49 ` Jiayuan Chen
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=20261117094544.148437-1-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--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=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mhal@rbox.co \
--cc=rhkrqnwk98@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.