diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2023-12-18 17:47:48 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2024-04-19 16:14:46 +0100 |
commit | 54a0219150d9dd2b0034e9682072900d4ec403b3 (patch) | |
tree | e27705e3a8e7045f642e26330bacb5020b415d79 /libctf/ctf-impl.h | |
parent | ca019227843f62f5ac0a1c432680e3ca05c4377b (diff) | |
download | binutils-54a0219150d9dd2b0034e9682072900d4ec403b3.zip binutils-54a0219150d9dd2b0034e9682072900d4ec403b3.tar.gz binutils-54a0219150d9dd2b0034e9682072900d4ec403b3.tar.bz2 |
libctf: remove static/dynamic name lookup distinction
libctf internally maintains a set of hash tables for type name lookups,
one for each valid C type namespace (struct, union, enum, and everything
else).
Or, rather, it maintains *two* sets of hash tables: one, a ctf_hash *,
is meant for lookups in ctf_(buf)open()ed dicts with fixed content; the
other, a ctf_dynhash *, is meant for lookups in ctf_create()d dicts.
This distinction was somewhat valuable in the far pre-binutils past when
two different hashtable implementations were used (one expanding, the
other fixed-size), but those days are long gone: the hash table
implementations are almost identical, both wrappers around the libiberty
hashtab. The ctf_dynhash has many more capabilities than the ctf_hash
(iteration, deletion, etc etc) and has no downsides other than starting
at a fixed, arbitrary small size.
That limitation is easy to lift (via a new ctf_dynhash_create_sized()),
following which we can throw away nearly all the ctf_hash
implementation, and all the code to choose between readable and writable
hashtabs; the few convenience functions that are still useful (for
insertion of name -> type mappings) can also be generalized a bit so
that the extra string verification they do is potentially available to
other string lookups as well.
(libctf still has two hashtable implementations, ctf_dynhash, above,
and ctf_dynset, which is a key-only hashtab that can avoid a great many
malloc()s, used for high-volume applications in the deduplicator.)
libctf/
* ctf-create.c (ctf_create): Eliminate ctn_writable.
(ctf_dtd_insert): Likewise.
(ctf_dtd_delete): Likewise.
(ctf_rollback): Likewise.
(ctf_name_table): Eliminate ctf_names_t.
* ctf-hash.c (ctf_dynhash_create): Comment update.
Reimplement in terms of...
(ctf_dynhash_create_sized): ... this new function.
(ctf_hash_create): Remove.
(ctf_hash_size): Remove.
(ctf_hash_define_type): Remove.
(ctf_hash_destroy): Remove.
(ctf_hash_lookup_type): Rename to...
(ctf_dynhash_lookup_type): ... this.
(ctf_hash_insert_type): Rename to...
(ctf_dynhash_insert_type): ... this, moving validation to...
* ctf-string.c (ctf_strptr_validate): ... this new function.
* ctf-impl.h (struct ctf_names): Extirpate.
(struct ctf_lookup.ctl_hash): Now a ctf_dynhash_t.
(struct ctf_dict): All ctf_names_t fields are now ctf_dynhash_t.
(ctf_name_table): Now returns a ctf_dynhash_t.
(ctf_lookup_by_rawhash): Remove.
(ctf_hash_create): Likewise.
(ctf_hash_insert_type): Likewise.
(ctf_hash_define_type): Likewise.
(ctf_hash_lookup_type): Likewise.
(ctf_hash_size): Likewise.
(ctf_hash_destroy): Likewise.
(ctf_dynhash_create_sized): New.
(ctf_dynhash_insert_type): New.
(ctf_dynhash_lookup_type): New.
(ctf_strptr_validate): New.
* ctf-lookup.c (ctf_lookup_by_name_internal): Adapt.
* ctf-open.c (init_types): Adapt.
(ctf_set_ctl_hashes): Adapt.
(ctf_dict_close): Adapt.
* ctf-serialize.c (ctf_serialize): Adapt.
* ctf-types.c (ctf_lookup_by_rawhash): Remove.
Diffstat (limited to 'libctf/ctf-impl.h')
-rw-r--r-- | libctf/ctf-impl.h | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 0fe9c20..8cbb2ae 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -123,17 +123,11 @@ typedef struct ctf_dmodel size_t ctd_long; /* Size of long in bytes. */ } ctf_dmodel_t; -typedef struct ctf_names -{ - ctf_hash_t *ctn_readonly; /* Hash table when readonly. */ - ctf_dynhash_t *ctn_writable; /* Hash table when writable. */ -} ctf_names_t; - typedef struct ctf_lookup { const char *ctl_prefix; /* String prefix for this lookup. */ size_t ctl_len; /* Length of prefix string in bytes. */ - ctf_names_t *ctl_hash; /* Pointer to hash table for lookup. */ + ctf_dynhash_t *ctl_hash; /* Pointer to hash table for lookup. */ } ctf_lookup_t; typedef struct ctf_dictops @@ -382,10 +376,10 @@ struct ctf_dict ctf_dynhash_t *ctf_syn_ext_strtab; /* Maps ext-strtab offsets to names. */ void *ctf_data_mmapped; /* CTF data we mmapped, to free later. */ size_t ctf_data_mmapped_len; /* Length of CTF data we mmapped. */ - ctf_names_t ctf_structs; /* Hash table of struct types. */ - ctf_names_t ctf_unions; /* Hash table of union types. */ - ctf_names_t ctf_enums; /* Hash table of enum types. */ - ctf_names_t ctf_names; /* Hash table of remaining type names. */ + ctf_dynhash_t *ctf_structs; /* Hash table of struct types. */ + ctf_dynhash_t *ctf_unions; /* Hash table of union types. */ + ctf_dynhash_t *ctf_enums; /* Hash table of enum types. */ + ctf_dynhash_t *ctf_names; /* Hash table of remaining type names. */ ctf_lookup_t ctf_lookups[5]; /* Pointers to nametabs for name lookup. */ ctf_strs_t ctf_str[2]; /* Array of string table base and bounds. */ ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */ @@ -597,10 +591,9 @@ struct ctf_next #define LCTF_DIRTY 0x0004 /* CTF dict has been modified. */ #define LCTF_LINKING 0x0008 /* CTF link is underway: respect ctf_link_flags. */ -extern ctf_names_t *ctf_name_table (ctf_dict_t *, int); +extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int); extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t); extern ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *, int, const char *); -extern ctf_id_t ctf_lookup_by_rawhash (ctf_dict_t *, ctf_names_t *, const char *); extern void ctf_set_ctl_hashes (ctf_dict_t *); extern int ctf_symtab_skippable (ctf_link_sym_t *sym); @@ -629,19 +622,19 @@ typedef int (*ctf_hash_iter_find_f) (void *key, void *value, void *arg); typedef int (*ctf_hash_sort_f) (const ctf_next_hkv_t *, const ctf_next_hkv_t *, void *arg); -extern ctf_hash_t *ctf_hash_create (unsigned long, ctf_hash_fun, ctf_hash_eq_fun); -extern int ctf_hash_insert_type (ctf_hash_t *, ctf_dict_t *, uint32_t, uint32_t); -extern int ctf_hash_define_type (ctf_hash_t *, ctf_dict_t *, uint32_t, uint32_t); -extern ctf_id_t ctf_hash_lookup_type (ctf_hash_t *, ctf_dict_t *, const char *); -extern uint32_t ctf_hash_size (const ctf_hash_t *); -extern void ctf_hash_destroy (ctf_hash_t *); - extern ctf_dynhash_t *ctf_dynhash_create (ctf_hash_fun, ctf_hash_eq_fun, ctf_hash_free_fun, ctf_hash_free_fun); +extern ctf_dynhash_t *ctf_dynhash_create_sized (unsigned long, ctf_hash_fun, + ctf_hash_eq_fun, + ctf_hash_free_fun, + ctf_hash_free_fun); + extern int ctf_dynhash_insert (ctf_dynhash_t *, void *, void *); extern void ctf_dynhash_remove (ctf_dynhash_t *, const void *); extern size_t ctf_dynhash_elements (ctf_dynhash_t *); extern void ctf_dynhash_empty (ctf_dynhash_t *); +extern int ctf_dynhash_insert_type (ctf_dict_t *, ctf_dynhash_t *, uint32_t, uint32_t); +extern ctf_id_t ctf_dynhash_lookup_type (ctf_dynhash_t *, const char *); extern void *ctf_dynhash_lookup (ctf_dynhash_t *, const void *); extern int ctf_dynhash_lookup_kv (ctf_dynhash_t *, const void *key, const void **orig_key, void **value); @@ -720,6 +713,7 @@ extern const char *ctf_strptr (ctf_dict_t *, uint32_t); extern const char *ctf_strraw (ctf_dict_t *, uint32_t); extern const char *ctf_strraw_explicit (ctf_dict_t *, uint32_t, ctf_strs_t *); +extern const char *ctf_strptr_validate (ctf_dict_t *, uint32_t); extern int ctf_str_create_atoms (ctf_dict_t *); extern void ctf_str_free_atoms (ctf_dict_t *); extern uint32_t ctf_str_add (ctf_dict_t *, const char *); |