libctf: simplify ctf_txlate

Before now, this critical internal structure was an array mapping from a
type ID to the type index of the type with that ID.  This was critical for
the old world in which ctf_update() reserialized the entire dict, so things
moved around in memory all the time: but these days, a ctf_type_t * never
moves after creation, so we can just make ctf_txlate an array of ctf_type_t *
and be done with it.

This lets us point type indexes anywhere in memory, not just to entries
in the ctf_buf, which means we can have synthetic ones for various purposes.
And we will.
This commit is contained in:
Nick Alcock
2025-04-03 15:21:47 +01:00
parent 1d70873382
commit a80b903b45
2 changed files with 5 additions and 6 deletions

View File

@@ -402,7 +402,7 @@ struct ctf_dict
uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab
entries. */ entries. */
unsigned long ctf_nsyms; /* Number of entries in symtab xlate table. */ unsigned long ctf_nsyms; /* Number of entries in symtab xlate table. */
uint32_t *ctf_txlate; /* Translation table for type IDs. */ ctf_type_t **ctf_txlate; /* Translation table for type IDs. */
uint32_t *ctf_ptrtab; /* Translation table for pointer-to lookups. */ uint32_t *ctf_ptrtab; /* Translation table for pointer-to lookups. */
size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */ size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */
uint32_t *ctf_pptrtab; /* Parent types pointed to by child dicts. */ uint32_t *ctf_pptrtab; /* Parent types pointed to by child dicts. */
@@ -592,8 +592,8 @@ extern ctf_id_t ctf_index_to_type (const ctf_dict_t *, uint32_t);
#define LCTF_INDEX_TO_TYPEPTR(fp, i) \ #define LCTF_INDEX_TO_TYPEPTR(fp, i) \
((i > fp->ctf_stypes) ? \ ((i > fp->ctf_stypes) ? \
&(ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data) : \ ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data : \
(ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)])) (fp)->ctf_txlate[(i)])
/* The non *INFO variants of these macros acquire the relevant info from the /* The non *INFO variants of these macros acquire the relevant info from the
suffixed type, if the type is prefixed. (Internally to libctf, all types suffixed type, if the type is prefixed. (Internally to libctf, all types

View File

@@ -696,7 +696,7 @@ init_static_types (ctf_dict_t *fp, ctf_header_t *cth)
because later-added types will call grow_ptrtab() automatically, as because later-added types will call grow_ptrtab() automatically, as
needed. */ needed. */
fp->ctf_txlate = calloc (typemax + 1, sizeof (uint32_t)); fp->ctf_txlate = calloc (typemax + 1, sizeof (ctf_type_t *));
fp->ctf_ptrtab = calloc (typemax + 1, sizeof (uint32_t)); fp->ctf_ptrtab = calloc (typemax + 1, sizeof (uint32_t));
fp->ctf_ptrtab_len = typemax + 1; fp->ctf_ptrtab_len = typemax + 1;
fp->ctf_stypes = typemax; fp->ctf_stypes = typemax;
@@ -773,8 +773,7 @@ init_static_types_names_internal (ctf_dict_t *fp, ctf_header_t *cth,
assert (!(fp->ctf_flags & LCTF_NO_STR)); assert (!(fp->ctf_flags & LCTF_NO_STR));
xp = fp->ctf_txlate; xp = &fp->ctf_txlate[1];
*xp++ = 0; /* Type id 0 is used as a sentinel value. */
/* In this second pass through the types, we fill in each entry of the type /* In this second pass through the types, we fill in each entry of the type
and pointer tables and add names to the appropriate hashes. and pointer tables and add names to the appropriate hashes.