]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: simplify ctf_txlate
authorNick Alcock <nick.alcock@oracle.com>
Thu, 3 Apr 2025 14:21:47 +0000 (15:21 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:41 +0000 (18:07 +0100)
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.

libctf/ctf-impl.h
libctf/ctf-open.c

index db2ad1d8e5367657fcd790fe43419824ff0308cd..9833f6c3377d0f0a3cdd7f51a79b50e4066f9ed4 100644 (file)
@@ -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
index b17dae6bdbdc07af2a7bb06e12d5038fc479fd8f..61dbdd55d03b6095bfe75d8d480175aac883a5fc 100644 (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
      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.