summaryrefslogtreecommitdiff
path: root/libctf/ctf-serialize.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2021-03-18 12:37:52 +0000
committerNick Alcock <nick.alcock@oracle.com>2021-03-18 12:40:36 +0000
commit7879dd88efdabc5a2e93b71f488f09303117a0a9 (patch)
treea120f390349fe8cd5e8cdbe74e3f54fc625b737b /libctf/ctf-serialize.c
parenteefe721eadf78a5f68c38ea9ca0272c7be06e0c0 (diff)
downloadbinutils-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-serialize.c')
-rw-r--r--libctf/ctf-serialize.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 1e2c98b473a..f07cb61c42a 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -858,7 +858,6 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr)
uint32_t vlen = LCTF_INFO_VLEN (fp, dtd->dtd_data.ctt_info);
ctf_array_t cta;
- uint32_t encoding;
size_t len;
ctf_stype_t *copied;
const char *name;
@@ -879,24 +878,12 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr)
{
case CTF_K_INTEGER:
case CTF_K_FLOAT:
- if (kind == CTF_K_INTEGER)
- {
- encoding = CTF_INT_DATA (dtd->dtd_u.dtu_enc.cte_format,
- dtd->dtd_u.dtu_enc.cte_offset,
- dtd->dtd_u.dtu_enc.cte_bits);
- }
- else
- {
- encoding = CTF_FP_DATA (dtd->dtd_u.dtu_enc.cte_format,
- dtd->dtd_u.dtu_enc.cte_offset,
- dtd->dtd_u.dtu_enc.cte_bits);
- }
- memcpy (t, &encoding, sizeof (encoding));
- t += sizeof (encoding);
+ memcpy (t, dtd->dtd_vlen, sizeof (uint32_t));
+ t += sizeof (uint32_t);
break;
case CTF_K_SLICE:
- memcpy (t, &dtd->dtd_u.dtu_slice, sizeof (struct ctf_slice));
+ memcpy (t, dtd->dtd_vlen, sizeof (struct ctf_slice));
t += sizeof (struct ctf_slice);
break;