diff options
author | David Faust <david.faust@oracle.com> | 2024-05-30 14:06:27 -0700 |
---|---|---|
committer | David Faust <david.faust@oracle.com> | 2024-07-02 10:16:12 -0700 |
commit | 36774cec1f8d224e202dd3ca2012dae79d4e8ba9 (patch) | |
tree | ded96e169ede7f88cddb5de71cf4328bbc65dcb1 /gcc/btfout.cc | |
parent | d3f586ec50d3d502e0727e8307ae76770fdaee79 (diff) | |
download | gcc-36774cec1f8d224e202dd3ca2012dae79d4e8ba9.zip gcc-36774cec1f8d224e202dd3ca2012dae79d4e8ba9.tar.gz gcc-36774cec1f8d224e202dd3ca2012dae79d4e8ba9.tar.bz2 |
ctf: use pointers instead of IDs internally
This patch replaces all inter-type references in the ctfc internal data
structures with pointers, rather than the references-by-ID which were
used previously.
A couple of small updates in the BPF backend are included to make it
compatible with the change.
This change is only to the in-memory representation of various CTF
structures to make them easier to work with in various cases. It is
outwardly transparent; there is no change in emitted CTF.
gcc/
* btfout.cc (BTF_VOID_TYPEID, BTF_INIT_TYPEID): Move defines to
include/btf.h.
(btf_dvd_emit_preprocess_cb, btf_emit_preprocess)
(btf_dmd_representable_bitfield_p, btf_asm_array, btf_asm_varent)
(btf_asm_sou_member, btf_asm_func_arg, btf_init_postprocess):
Adapt to structural changes in ctf_* structs.
* ctfc.h (struct ctf_dtdef): Add forward declaration.
(ctf_dtdef_t, ctf_dtdef_ref): Move typedefs earlier.
(struct ctf_arinfo, struct ctf_funcinfo, struct ctf_sliceinfo)
(struct ctf_itype, struct ctf_dmdef, struct ctf_func_arg)
(struct ctf_dvdef): Use pointers instead of type IDs for
references to other types and use typedefs where appropriate.
(struct ctf_dtdef): Add ref_type member.
(ctf_type_exists): Use pointer instead of type ID.
(ctf_add_reftype, ctf_add_enum, ctf_add_slice, ctf_add_float)
(ctf_add_integer, ctf_add_unknown, ctf_add_pointer)
(ctf_add_array, ctf_add_forward, ctf_add_typedef)
(ctf_add_function, ctf_add_sou, ctf_add_enumerator)
(ctf_add_variable): Likewise. Return pointer instead of ID.
(ctf_lookup_tree_type): Return pointer to type instead of ID.
* ctfc.cc: Analogous changes.
* ctfout.cc (ctf_asm_type, ctf_asm_slice, ctf_asm_varent)
(ctf_asm_sou_lmember, ctf_asm_sou_member, ctf_asm_func_arg)
(output_ctf_objt_info): Adapt to changes.
* dwarf2ctf.cc (gen_ctf_type, gen_ctf_void_type)
(gen_ctf_unknown_type, gen_ctf_base_type, gen_ctf_pointer_type)
(gen_ctf_subrange_type, gen_ctf_array_type, gen_ctf_typedef)
(gen_ctf_modifier_type, gen_ctf_sou_type, gen_ctf_function_type)
(gen_ctf_enumeration_type, gen_ctf_variable, gen_ctf_function)
(gen_ctf_type, ctf_do_die): Likewise.
* config/bpf/btfext-out.cc (struct btf_ext_core_reloc): Use
pointer instead of type ID.
(bpf_core_reloc_add, bpf_core_get_sou_member_index)
(output_btfext_core_sections): Adapt to above changes.
* config/bpf/core-builtins.cc (process_type): Likewise.
include/
* btf.h (BTF_VOID_TYPEID, BTF_INIT_TYPEID): Move defines here,
from gcc/btfout.cc.
Diffstat (limited to 'gcc/btfout.cc')
-rw-r--r-- | gcc/btfout.cc | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/gcc/btfout.cc b/gcc/btfout.cc index d5e9f3b..9d73478 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -61,11 +61,6 @@ static char btf_info_section_label[MAX_BTF_LABEL_BYTES]; #define BTF_INFO_SECTION_LABEL "Lbtf" #endif -/* BTF encodes void as type id 0. */ - -#define BTF_VOID_TYPEID 0 -#define BTF_INIT_TYPEID 1 - #define BTF_INVALID_TYPEID 0xFFFFFFFF /* Mapping of CTF variables to the IDs they will be assigned when they are @@ -626,7 +621,8 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc) return 1; /* Do not add variables which refer to unsupported types. */ - if (!voids.contains (var->dvd_type) && btf_removed_type_p (var->dvd_type)) + if (!voids.contains (var->dvd_type->dtd_type) + && btf_removed_type_p (var->dvd_type->dtd_type)) return 1; arg_ctfc->ctfc_vars_list[num_vars_added] = var; @@ -716,7 +712,7 @@ btf_emit_preprocess (ctf_container_ref ctfc) static bool btf_dmd_representable_bitfield_p (ctf_container_ref ctfc, ctf_dmdef_t *dmd) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type]; + ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; if (CTF_V2_INFO_KIND (ref_type->dtd_data.ctti_info) == CTF_K_SLICE) { @@ -913,8 +909,8 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd) static void btf_asm_array (ctf_container_ref ctfc, ctf_arinfo_t arr) { - btf_asm_type_ref ("bta_elem_type", ctfc, arr.ctr_contents); - btf_asm_type_ref ("bta_index_type", ctfc, arr.ctr_index); + btf_asm_type_ref ("bta_elem_type", ctfc, arr.ctr_contents->dtd_type); + btf_asm_type_ref ("bta_index_type", ctfc, arr.ctr_index->dtd_type); dw2_asm_output_data (4, arr.ctr_nelems, "bta_nelems"); } @@ -927,7 +923,7 @@ btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) (*(btf_var_ids->get (var)) + num_types_added + 1), var->dvd_name); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_VAR, 0, 0), "btv_info"); - btf_asm_type_ref ("btv_type", ctfc, var->dvd_type); + btf_asm_type_ref ("btv_type", ctfc, var->dvd_type->dtd_type); dw2_asm_output_data (4, var->dvd_visibility, "btv_linkage"); } @@ -937,8 +933,8 @@ btf_asm_varent (ctf_container_ref ctfc, ctf_dvdef_ref var) static void btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) { - ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type]; - ctf_id_t base_type = dmd->dmd_type; + ctf_dtdef_ref ref_type = ctfc->ctfc_types_list[dmd->dmd_type->dtd_type]; + ctf_id_t base_type = dmd->dmd_type->dtd_type; uint64_t sou_offset = dmd->dmd_offset; dw2_asm_output_data (4, dmd->dmd_name_offset, @@ -959,7 +955,7 @@ btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd, unsigned int idx) sou_offset |= ((bits & 0xff) << 24); /* Refer to the base type of the slice. */ - base_type = ref_type->dtd_u.dtu_slice.cts_type; + base_type = ref_type->dtd_u.dtu_slice.cts_type->dtd_type; } else { @@ -1003,9 +999,11 @@ btf_asm_func_arg (ctf_container_ref ctfc, ctf_func_arg_t * farg, else dw2_asm_output_data (4, 0, "farg_name"); - btf_asm_type_ref ("farg_type", ctfc, (btf_removed_type_p (farg->farg_type) - ? BTF_VOID_TYPEID - : farg->farg_type)); + ctf_id_t ref_id = BTF_VOID_TYPEID; + if (farg->farg_type && !btf_removed_type_p (farg->farg_type->dtd_type)) + ref_id = farg->farg_type->dtd_type; + + btf_asm_type_ref ("farg_type", ctfc, ref_id); } /* Asm'out a BTF_KIND_FUNC type. */ @@ -1381,7 +1379,7 @@ btf_init_postprocess (void) to create the const modifier type (if needed) now, before making the types list. So we can't avoid iterating with FOR_EACH_VARIABLE here, and then again when creating the DATASEC entries. */ - ctf_id_t constvoid_id = CTF_NULL_TYPEID; + ctf_dtdef_ref constvoid_dtd = NULL; varpool_node *var; FOR_EACH_VARIABLE (var) { @@ -1400,10 +1398,10 @@ btf_init_postprocess (void) continue; /* Create the 'const' modifier type for void. */ - if (constvoid_id == CTF_NULL_TYPEID) - constvoid_id = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, - dvd->dvd_type, CTF_K_CONST, NULL); - dvd->dvd_type = constvoid_id; + if (constvoid_dtd == NULL) + constvoid_dtd = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, + dvd->dvd_type, CTF_K_CONST, NULL); + dvd->dvd_type = constvoid_dtd; } } |