[PATCH bpf-next] bpftool: Preserve unsigned enum64 values in data dumps

From: Hungyu Lin

Date: Sat Oct 31 2026 - 18:36:47 EST


When an enum64 data value does not match a named enumerator,
btf_dumper_enum64() always prints it as signed. Unsigned values with
bit 63 set therefore appear negative in BTF-formatted map dump and
lookup output, in both plain and JSON modes. For example,
0x8000000000000001 is printed as -9223372036854775807 instead of
9223372036854775809.

Choose the numeric writer according to the enum's signedness. Keep
signed values and named enumerators unchanged.

Fixes: 58a53978fdf6 ("bpftool: Add btf enum64 support")
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
tools/bpf/bpftool/btf_dumper.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 3267163119dc..88c0da29f246 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -204,7 +204,10 @@ static int btf_dumper_enum64(const struct btf_dumper *d,
}
}

- jsonw_int(d->jw, value);
+ if (btf_kflag(t))
+ jsonw_int(d->jw, value);
+ else
+ jsonw_uint(d->jw, value);
return 0;
}


base-commit: eaae576c34d7e001767b6845a5950b0b8db3e68a
--
2.43.0