diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2021-03-18 12:37:52 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2021-03-18 12:40:36 +0000 |
commit | 7879dd88efdabc5a2e93b71f488f09303117a0a9 (patch) | |
tree | a120f390349fe8cd5e8cdbe74e3f54fc625b737b /libctf/ctf-types.c | |
parent | eefe721eadf78a5f68c38ea9ca0272c7be06e0c0 (diff) | |
download | binutils-gdb-7879dd88efdabc5a2e93b71f488f09303117a0a9.tar.gz |
libctf: eliminate dtd_u, part 1: int/float/slice
This series eliminates a lot of special-case code to handle dynamic
types (types added to writable dicts and not yet serialized).
Historically, when such types have variable-length data in their final
CTF representations, libctf has always worked by adding such types to a
special union (ctf_dtdef_t.dtd_u) in the dynamic type definition
structure, then picking the members out of this structure at
serialization time and packing them into their final form.
This has the advantage that the ctf_add_* code doesn't need to know
anything about the final CTF representation, but the significant
disadvantage that all code that looks up types in any way needs two code
paths, one for dynamic types, one for all others. Historically libctf
"handled" this by not supporting most type lookups on dynamic types at
all until ctf_update was called to do a complete reserialization of the
entire dict (it didn't emit an error, it just emitted wrong results).
Since commit 676c3ecbad6e9c4, which eliminated ctf_update in favour of
the internal-only ctf_serialize function, all the type-lookup paths
grew an extra branch to handle dynamic types.
We can eliminate this branch again by dropping the dtd_u stuff and
simply writing out the vlen in (close to) its final form at ctf_add_*
time: type lookup for types using this approach is then identical for
types in writable dicts and types that are in read-only ones, and
serialization is also simplified (we just need to write out the vlen
we already created).
The only complexity lies in type kinds for which multiple
vlen representations are valid depending on properties of the type,
e.g. structures. But we can start simple, adjusting ints, floats,
and slices to work this way, and leaving everything else as is.
libctf/ChangeLog
2021-03-18 Nick Alcock <nick.alcock@oracle.com>
* ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_enc>: Remove.
<dtd_u.dtu_slice>: Likewise.
<dtd_vlen>: New.
* ctf-create.c (ctf_add_generic): Perhaps allocate it. All
callers adjusted.
(ctf_dtd_delete): Free it.
(ctf_add_slice): Use the dtd_vlen, not dtu_enc.
(ctf_add_encoded): Likewise. Assert that this must be an int or
float.
* ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen.
* ctf-dedup.c (ctf_dedup_rhash_type): Use the dtd_vlen, not
dtu_slice.
* ctf-types.c (ctf_type_reference): Likewise.
(ctf_type_encoding): Remove most dynamic-type-specific code: just
get the vlen from the right place. Report failure to look up the
underlying type's encoding.
Diffstat (limited to 'libctf/ctf-types.c')
-rw-r--r-- | libctf/ctf-types.c | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index 28c5c7aa1e1..ae243817713 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -1168,7 +1168,7 @@ ctf_type_reference (ctf_dict_t *fp, ctf_id_t type) sp = (const ctf_slice_t *) ((uintptr_t) tp + increment); } else - sp = &dtd->dtd_u.dtu_slice; + sp = (const ctf_slice_t *) dtd->dtd_vlen; return sp->cts_type; } @@ -1218,52 +1218,30 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) ctf_dtdef_t *dtd; const ctf_type_t *tp; ssize_t increment; + const unsigned char *vlen; uint32_t data; if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) return -1; /* errno is set for us. */ if ((dtd = ctf_dynamic_type (ofp, type)) != NULL) + vlen = dtd->dtd_vlen; + else { - switch (LCTF_INFO_KIND (fp, tp->ctt_info)) - { - case CTF_K_INTEGER: - case CTF_K_FLOAT: - *ep = dtd->dtd_u.dtu_enc; - break; - case CTF_K_SLICE: - { - const ctf_slice_t *slice; - ctf_encoding_t underlying_en; - ctf_id_t underlying; - - slice = &dtd->dtd_u.dtu_slice; - underlying = ctf_type_resolve (fp, slice->cts_type); - data = ctf_type_encoding (fp, underlying, &underlying_en); - - ep->cte_format = underlying_en.cte_format; - ep->cte_offset = slice->cts_offset; - ep->cte_bits = slice->cts_bits; - break; - } - default: - return (ctf_set_errno (ofp, ECTF_NOTINTFP)); - } - return 0; + ctf_get_ctt_size (fp, tp, NULL, &increment); + vlen = (const unsigned char *) ((uintptr_t) tp + increment); } - (void) ctf_get_ctt_size (fp, tp, NULL, &increment); - switch (LCTF_INFO_KIND (fp, tp->ctt_info)) { case CTF_K_INTEGER: - data = *(const uint32_t *) ((uintptr_t) tp + increment); + data = *(const uint32_t *) vlen; ep->cte_format = CTF_INT_ENCODING (data); ep->cte_offset = CTF_INT_OFFSET (data); ep->cte_bits = CTF_INT_BITS (data); break; case CTF_K_FLOAT: - data = *(const uint32_t *) ((uintptr_t) tp + increment); + data = *(const uint32_t *) vlen; ep->cte_format = CTF_FP_ENCODING (data); ep->cte_offset = CTF_FP_OFFSET (data); ep->cte_bits = CTF_FP_BITS (data); @@ -1274,9 +1252,10 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) ctf_encoding_t underlying_en; ctf_id_t underlying; - slice = (ctf_slice_t *) ((uintptr_t) tp + increment); + slice = (ctf_slice_t *) vlen; underlying = ctf_type_resolve (fp, slice->cts_type); - data = ctf_type_encoding (fp, underlying, &underlying_en); + if (ctf_type_encoding (fp, underlying, &underlying_en) < 0) + return -1; /* errno is set for us. */ ep->cte_format = underlying_en.cte_format; ep->cte_offset = slice->cts_offset; |