From: Nick Alcock Date: Thu, 3 Apr 2025 14:21:47 +0000 (+0100) Subject: libctf: simplify ctf_txlate X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a80b903b45313cb6b17b79395d6bdb5bf016bc02;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index db2ad1d8e53..9833f6c3377 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -402,7 +402,7 @@ struct ctf_dict uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab entries. */ 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. */ size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */ 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) \ ((i > fp->ctf_stypes) ? \ - &(ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data) : \ - (ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)])) + ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data : \ + (fp)->ctf_txlate[(i)]) /* 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 diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index b17dae6bdbd..61dbdd55d03 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -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 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_len = typemax + 1; 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)); - xp = fp->ctf_txlate; - *xp++ = 0; /* Type id 0 is used as a sentinel value. */ + xp = &fp->ctf_txlate[1]; /* 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.