libbpf: Assume unsigned values for BTF_KIND_ENUM
authorAndrii Nakryiko <andriin@fb.com>
Tue, 3 Mar 2020 00:32:32 +0000 (16:32 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 4 Mar 2020 16:00:06 +0000 (17:00 +0100)
Currently, BTF_KIND_ENUM type doesn't record whether enum values should be
interpreted as signed or unsigned. In Linux, most enums are unsigned, though,
so interpreting them as unsigned matches real world better.

Change btf_dump test case to test maximum 32-bit value, instead of negative
value.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200303003233.3496043-3-andriin@fb.com
tools/lib/bpf/btf_dump.c
tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c

index dc451e4de5ad45d62cb3701c597cf432bc841f66..0c28ee82834b722c47e8326ccede07202c0cc8e9 100644 (file)
@@ -916,13 +916,13 @@ static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
                        /* enumerators share namespace with typedef idents */
                        dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
                        if (dup_cnt > 1) {
-                               btf_dump_printf(d, "\n%s%s___%zu = %d,",
+                               btf_dump_printf(d, "\n%s%s___%zu = %u,",
                                                pfx(lvl + 1), name, dup_cnt,
-                                               (__s32)v->val);
+                                               (__u32)v->val);
                        } else {
-                               btf_dump_printf(d, "\n%s%s = %d,",
+                               btf_dump_printf(d, "\n%s%s = %u,",
                                                pfx(lvl + 1), name,
-                                               (__s32)v->val);
+                                               (__u32)v->val);
                        }
                }
                btf_dump_printf(d, "\n%s}", pfx(lvl));
index d4a02fe44a1269f34d5677347669f2a08817db1a..31975c96e2c9cfb97dc72bc85c87bde0cfc4d7e6 100644 (file)
@@ -13,7 +13,7 @@ enum e1 {
 
 enum e2 {
        C = 100,
-       D = -100,
+       D = 4294967295,
        E = 0,
 };