btf_encoder: Move add_ref_type() from btf_elf to btf encode_ref_type()
As it is all that it needs. Rename from __add to __encode prefix for consistency, as we have btf__add_array() and thus need to use a different name for arrays, so do it here as well. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
a97ed8080a
commit
a96c91261e
|
@ -238,22 +238,22 @@ static int tag__encode_btf(struct cu *cu, struct tag *tag, uint32_t core_id, str
|
||||||
name = dwarves__active_loader->strings__ptr(cu, tag__base_type(tag)->name);
|
name = dwarves__active_loader->strings__ptr(cu, tag__base_type(tag)->name);
|
||||||
return btf__encode_base_type(btfe->btf, tag__base_type(tag), name);
|
return btf__encode_base_type(btfe->btf, tag__base_type(tag), name);
|
||||||
case DW_TAG_const_type:
|
case DW_TAG_const_type:
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_CONST, ref_type_id, NULL, false);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_CONST, ref_type_id, NULL, false);
|
||||||
case DW_TAG_pointer_type:
|
case DW_TAG_pointer_type:
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_PTR, ref_type_id, NULL, false);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_PTR, ref_type_id, NULL, false);
|
||||||
case DW_TAG_restrict_type:
|
case DW_TAG_restrict_type:
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_RESTRICT, ref_type_id, NULL, false);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_RESTRICT, ref_type_id, NULL, false);
|
||||||
case DW_TAG_volatile_type:
|
case DW_TAG_volatile_type:
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_VOLATILE, ref_type_id, NULL, false);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_VOLATILE, ref_type_id, NULL, false);
|
||||||
case DW_TAG_typedef:
|
case DW_TAG_typedef:
|
||||||
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
|
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_TYPEDEF, ref_type_id, name, false);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_TYPEDEF, ref_type_id, name, false);
|
||||||
case DW_TAG_structure_type:
|
case DW_TAG_structure_type:
|
||||||
case DW_TAG_union_type:
|
case DW_TAG_union_type:
|
||||||
case DW_TAG_class_type:
|
case DW_TAG_class_type:
|
||||||
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
|
name = dwarves__active_loader->strings__ptr(cu, tag__namespace(tag)->name);
|
||||||
if (tag__type(tag)->declaration)
|
if (tag__type(tag)->declaration)
|
||||||
return btf_elf__add_ref_type(btfe, BTF_KIND_FWD, 0, name, tag->tag == DW_TAG_union_type);
|
return btf__encode_ref_type(btfe->btf, BTF_KIND_FWD, 0, name, tag->tag == DW_TAG_union_type);
|
||||||
else
|
else
|
||||||
return structure_type__encode(btfe, cu, tag, type_id_off);
|
return structure_type__encode(btfe, cu, tag, type_id_off);
|
||||||
case DW_TAG_array_type:
|
case DW_TAG_array_type:
|
||||||
|
@ -574,7 +574,7 @@ int cu__encode_btf(struct cu *cu, struct btf *base_btf, int verbose, bool force,
|
||||||
|
|
||||||
btf_fnproto_id = btf_elf__add_func_proto(btfe, cu, &fn->proto, type_id_off);
|
btf_fnproto_id = btf_elf__add_func_proto(btfe, cu, &fn->proto, type_id_off);
|
||||||
name = dwarves__active_loader->strings__ptr(cu, fn->name);
|
name = dwarves__active_loader->strings__ptr(cu, fn->name);
|
||||||
btf_fn_id = btf_elf__add_ref_type(btfe, BTF_KIND_FUNC, btf_fnproto_id, name, false);
|
btf_fn_id = btf__encode_ref_type(btfe->btf, BTF_KIND_FUNC, btf_fnproto_id, name, false);
|
||||||
if (btf_fnproto_id < 0 || btf_fn_id < 0) {
|
if (btf_fnproto_id < 0 || btf_fn_id < 0) {
|
||||||
err = -1;
|
err = -1;
|
||||||
printf("error: failed to encode function '%s'\n", function__name(fn, cu));
|
printf("error: failed to encode function '%s'\n", function__name(fn, cu));
|
||||||
|
|
3
libbtf.c
3
libbtf.c
|
@ -408,10 +408,9 @@ int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t btf_elf__add_ref_type(struct btf_elf *btfe, uint16_t kind, uint32_t type,
|
int32_t btf__encode_ref_type(struct btf *btf, uint16_t kind, uint32_t type,
|
||||||
const char *name, bool kind_flag)
|
const char *name, bool kind_flag)
|
||||||
{
|
{
|
||||||
struct btf *btf = btfe->btf;
|
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
int32_t id;
|
int32_t id;
|
||||||
|
|
||||||
|
|
3
libbtf.h
3
libbtf.h
|
@ -41,8 +41,7 @@ struct btf_elf *btf_elf__new(const char *filename, Elf *elf, struct btf *base_bt
|
||||||
void btf_elf__delete(struct btf_elf *btf);
|
void btf_elf__delete(struct btf_elf *btf);
|
||||||
|
|
||||||
int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const char *name);
|
int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const char *name);
|
||||||
int32_t btf_elf__add_ref_type(struct btf_elf *btf, uint16_t kind, uint32_t type,
|
int32_t btf__encode_ref_type(struct btf *btf, uint16_t kind, uint32_t type, const char *name, bool kind_flag);
|
||||||
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);
|
int btf__encode_member(struct btf *btf, const char *name, uint32_t type, uint32_t bitfield_size, uint32_t bit_offset);
|
||||||
int32_t btf_elf__add_struct(struct btf_elf *btf, uint8_t kind, const char *name, uint32_t size);
|
int32_t btf_elf__add_struct(struct btf_elf *btf, uint8_t kind, const char *name, uint32_t size);
|
||||||
int32_t btf_elf__add_array(struct btf_elf *btf, uint32_t type, uint32_t index_type,
|
int32_t btf_elf__add_array(struct btf_elf *btf, uint32_t type, uint32_t index_type,
|
||||||
|
|
Loading…
Reference in New Issue