• Yonghong Song's avatar
    bpftool: Add btf enum64 support · 58a53978
    Yonghong Song authored
    Add BTF_KIND_ENUM64 support.
    For example, the following enum is defined in uapi bpf.h.
      $ cat core.c
      enum A {
            BPF_F_INDEX_MASK                = 0xffffffffULL,
            BPF_F_CURRENT_CPU               = BPF_F_INDEX_MASK,
            BPF_F_CTXLEN_MASK               = (0xfffffULL << 32),
      } g;
    Compiled with
      clang -target bpf -O2 -g -c core.c
    Using bpftool to dump types and generate format C file:
      $ bpftool btf dump file core.o
      ...
      [1] ENUM64 'A' encoding=UNSIGNED size=8 vlen=3
            'BPF_F_INDEX_MASK' val=4294967295ULL
            'BPF_F_CURRENT_CPU' val=4294967295ULL
            'BPF_F_CTXLEN_MASK' val=4503595332403200ULL
      $ bpftool btf dump file core.o format c
      ...
      enum A {
            BPF_F_INDEX_MASK = 4294967295ULL,
            BPF_F_CURRENT_CPU = 4294967295ULL,
            BPF_F_CTXLEN_MASK = 4503595332403200ULL,
      };
      ...
    
    Note that for raw btf output, the encoding (UNSIGNED or SIGNED)
    is printed out as well. The 64bit value is also represented properly
    in BTF and C dump.
    Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/r/20220607062652.3722649-1-yhs@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    58a53978
gen.c 53.5 KB