diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2022-06-29 15:41:32 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2022-07-12 09:01:11 -0300 |
commit | 9712d9ec929fb6b3595d2970bbbac8b0b1c10ead (patch) | |
tree | e213ab92fdadb989abfdcf6650cee0d2d3feaf66 | |
parent | 35a11221b305a5204402ce7467adfdbac8971f77 (diff) | |
download | pahole-9712d9ec929fb6b3595d2970bbbac8b0b1c10ead.tar.gz |
btf_loader: Add support to BTF_KIND_ENUM64
It'll just reuse 'struct enumerator' and 'struct enumeration', as
'enumerator' already suppored 64-bit due to DWARF.
$ pdwtags -F btf vmlinux-v5.18-rc7+ | grep -B5 -A5 BPF_F_CTXLEN_MASK
/* 27413 */
enum {
BPF_F_INDEX_MASK = 4294967295,
BPF_F_CURRENT_CPU = 4294967295,
BPF_F_CTXLEN_MASK = 4503595332403200,
} __attribute__((__packed__)); /* size: 8 */
/* 27414 */
enum {
BPF_F_GET_BRANCH_RECORDS_SIZE = 1,
$
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jiri Olsa <olsajiri@gmail.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: kernel-team@fb.com
Link: https://lore.kernel.org/dwarves/YryELT6OadpiJki%2F@kernel.org/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | btf_loader.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/btf_loader.c b/btf_loader.c index b5d44464..406a007b 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -312,6 +312,49 @@ out_free: return -ENOMEM; } +static struct enumerator *enumerator__new64(const char *name, uint64_t value) +{ + struct enumerator *en = tag__alloc(sizeof(*en)); + + if (en != NULL) { + en->name = name; + en->value = value; // Value is already 64-bit, as this is used with DWARF as well + en->tag.tag = DW_TAG_enumerator; + } + + return en; +} + +static int create_new_enumeration64(struct cu *cu, const struct btf_type *tp, uint32_t id) +{ + struct btf_enum64 *ep = btf_enum64(tp); + uint16_t i, vlen = btf_vlen(tp); + struct type *enumeration = type__new(DW_TAG_enumeration_type, + cu__btf_str(cu, tp->name_off), + tp->size ? tp->size * 8 : (sizeof(int) * 8)); + + if (enumeration == NULL) + return -ENOMEM; + + for (i = 0; i < vlen; i++) { + const char *name = cu__btf_str(cu, ep[i].name_off); + uint64_t value = btf_enum64_value(&ep[i]); + struct enumerator *enumerator = enumerator__new64(name, value); + + if (enumerator == NULL) + goto out_free; + + enumeration__add(enumeration, enumerator); + } + + cu__add_tag_with_id(cu, &enumeration->namespace.tag, id); + + return 0; +out_free: + enumeration__delete(enumeration); + return -ENOMEM; +} + static int create_new_subroutine_type(struct cu *cu, const struct btf_type *tp, uint32_t id) { struct ftype *proto = tag__alloc(sizeof(*proto)); @@ -419,6 +462,9 @@ static int btf__load_types(struct btf *btf, struct cu *cu) case BTF_KIND_ENUM: err = create_new_enumeration(cu, type_ptr, type_index); break; + case BTF_KIND_ENUM64: + err = create_new_enumeration64(cu, type_ptr, type_index); + break; case BTF_KIND_FWD: err = create_new_forward_decl(cu, type_ptr, type_index); break; |