From: Yonghong Song <yonghong.song@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
kernel-team@fb.com
Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Take unsigned enum values as unsigned int for GCC
Date: Wed, 18 Nov 2026 21:15:04 -0800 [thread overview]
Message-ID: <20261119051504.1904004-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20261119051443.1902163-1-yonghong.song@linux.dev>
GCC's __builtin_preserve_enum_value() returns int, so storing the
value of enum named_uint_enum into a long field sign-extends it. With
the previous patch, the program built by GCC loads, but uint_val1 reads
back as 0xffffffff80000001 while the test expects 0x80000001. Convert
the result to unsigned int for GCC to get the enumerator value. Clang
still stores the 64-bit relocated value, so its upper 32 bits keep
being checked.
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
.../selftests/bpf/progs/test_core_reloc_enumval.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
index 964297b9bab5..dc15caf8c151 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c
@@ -49,6 +49,13 @@ struct core_reloc_enumval_output {
long uint_val2;
};
+#ifdef __clang__
+#define UINT_ENUM_VALUE(v) bpf_core_enum_value(enum named_uint_enum, v)
+#else
+/* GCC's __builtin_preserve_enum_value() returns int */
+#define UINT_ENUM_VALUE(v) (unsigned int)bpf_core_enum_value(enum named_uint_enum, v)
+#endif
+
SEC("raw_tracepoint/sys_enter")
int test_core_enumval(void *ctx)
{
@@ -75,9 +82,9 @@ int test_core_enumval(void *ctx)
/* enum named_uint_enum is optional */
if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL1))
- out->uint_val1 = bpf_core_enum_value(enum named_uint_enum, UINT_ENUM_VAL1);
+ out->uint_val1 = UINT_ENUM_VALUE(UINT_ENUM_VAL1);
if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL2))
- out->uint_val2 = bpf_core_enum_value(enum named_uint_enum, UINT_ENUM_VAL2);
+ out->uint_val2 = UINT_ENUM_VALUE(UINT_ENUM_VAL2);
#else
data.skip = true;
#endif
--
2.53.1-Meta
prev parent reply other threads:[~2026-11-19 5:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 5:14 [PATCH bpf-next v2 0/4] libbpf: Fix CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19 5:14 ` [PATCH bpf-next v2 1/4] libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19 5:54 ` bot+bpf-ci
2026-11-19 5:14 ` [PATCH bpf-next v2 2/4] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19 5:54 ` bot+bpf-ci
2026-11-19 5:14 ` [PATCH bpf-next v2 3/4] libbpf: Accept sign-extended 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19 5:21 ` sashiko-bot
2026-11-19 5:15 ` Yonghong Song [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=20261119051504.1904004-1-yonghong.song@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
/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