btf_encoder: Adopt btf__encode_ref_type() as btf_encoder__add_ref_type()

As it is just prep work to call the various libbpf's btf__add*() for
types that reference other types (volatile, const, pointers, etc) using
pahole's data structures populated from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-06-09 09:31:26 -03:00
parent 07d4ec9cef
commit 2c7a2f270e
3 changed files with 11 additions and 10 deletions

View File

@ -236,22 +236,22 @@ static int btf_encoder__encode_tag(struct btf_encoder *encoder, struct cu *cu, s
name = dwarves__active_loader->strings__ptr(cu, tag__base_type(tag)->name);
return btf_encoder__add_base_type(encoder, tag__base_type(tag), name);
case DW_TAG_const_type:
return btf__encode_ref_type(btf, BTF_KIND_CONST, ref_type_id, NULL, false);
return btf_encoder__add_ref_type(encoder, BTF_KIND_CONST, ref_type_id, NULL, false);
case DW_TAG_pointer_type:
return btf__encode_ref_type(btf, BTF_KIND_PTR, ref_type_id, NULL, false);
return btf_encoder__add_ref_type(encoder, BTF_KIND_PTR, ref_type_id, NULL, false);
case DW_TAG_restrict_type:
return btf__encode_ref_type(btf, BTF_KIND_RESTRICT, ref_type_id, NULL, false);
return btf_encoder__add_ref_type(encoder, BTF_KIND_RESTRICT, ref_type_id, NULL, false);
case DW_TAG_volatile_type:
return btf__encode_ref_type(btf, BTF_KIND_VOLATILE, ref_type_id, NULL, false);
return btf_encoder__add_ref_type(encoder, BTF_KIND_VOLATILE, ref_type_id, NULL, false);
case DW_TAG_typedef:
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
return btf__encode_ref_type(btf, BTF_KIND_TYPEDEF, ref_type_id, name, false);
return btf_encoder__add_ref_type(encoder, BTF_KIND_TYPEDEF, ref_type_id, name, false);
case DW_TAG_structure_type:
case DW_TAG_union_type:
case DW_TAG_class_type:
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
if (tag__type(tag)->declaration)
return btf__encode_ref_type(btf, BTF_KIND_FWD, 0, name, tag->tag == DW_TAG_union_type);
return btf_encoder__add_ref_type(encoder, BTF_KIND_FWD, 0, name, tag->tag == DW_TAG_union_type);
else
return btf__encode_struct_type(btf, cu, tag, type_id_off);
case DW_TAG_array_type:
@ -745,7 +745,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, bool skip
btf_fnproto_id = btf__encode_func_proto(encoder->btf, cu, &fn->proto, type_id_off);
name = dwarves__active_loader->strings__ptr(cu, fn->name);
btf_fn_id = btf__encode_ref_type(encoder->btf, BTF_KIND_FUNC, btf_fnproto_id, name, false);
btf_fn_id = btf_encoder__add_ref_type(encoder, BTF_KIND_FUNC, btf_fnproto_id, name, false);
if (btf_fnproto_id < 0 || btf_fn_id < 0) {
err = -1;
printf("error: failed to encode function '%s'\n", function__name(fn, cu));

View File

@ -302,9 +302,10 @@ int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const struct bas
return id;
}
int32_t btf__encode_ref_type(struct btf *btf, uint16_t kind, uint32_t type,
const char *name, bool kind_flag)
int32_t btf_encoder__add_ref_type(struct btf_encoder *encoder, uint16_t kind, uint32_t type,
const char *name, bool kind_flag)
{
struct btf *btf = encoder->btf;
const struct btf_type *t;
int32_t id;

View File

@ -23,7 +23,7 @@ struct base_type;
struct ftype;
int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const struct base_type *bt, const char *name);
int32_t btf__encode_ref_type(struct btf *btf, uint16_t kind, uint32_t type, const char *name, bool kind_flag);
int32_t btf_encoder__add_ref_type(struct btf_encoder *encoder, uint16_t kind, uint32_t type, const char *name, bool kind_flag);
int btf__encode_member(struct btf *btf, const char *name, uint32_t type, uint32_t bitfield_size, uint32_t bit_offset);
int32_t btf__encode_struct(struct btf *btf, uint8_t kind, const char *name, uint32_t size);
int32_t btf__encode_array(struct btf *btf, uint32_t type, uint32_t index_type, uint32_t nelems);