summaryrefslogtreecommitdiff
path: root/libctf/ctf-hash.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-07-13 21:31:26 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-10-03 17:04:55 +0100
commit886453cbbc86ba63d8ab1264e9684a7698243eeb (patch)
tree77880fc8d6e8c2342b6c45f8de49a4058433c89c /libctf/ctf-hash.c
parent72c83edd92ef15a19ed0c033e25bb5006ee3bdd8 (diff)
downloadbinutils-gdb-886453cbbc86ba63d8ab1264e9684a7698243eeb.tar.gz
libctf: map from old to corresponding newly-added types in ctf_add_type
This lets you call ctf_type_mapping (dest_fp, src_fp, src_type_id) and get told what type ID the corresponding type has in the target ctf_file_t. This works even if it was added by a recursive call, and because it is stored in the target ctf_file_t it works even if we had to add one type to multiple ctf_file_t's as part of conflicting type handling. We empty out this mapping after every archive is linked: because it maps input to output fps, and we only visit each input fp once, its contents are rendered entirely useless every time the source fp changes. v3: add several missing mapping additions. Add ctf_dynhash_empty, and empty after every input archive. v5: fix tabdamage. libctf/ * ctf-impl.h (ctf_file_t): New field ctf_link_type_mapping. (struct ctf_link_type_mapping_key): New. (ctf_hash_type_mapping_key): Likewise. (ctf_hash_eq_type_mapping_key): Likewise. (ctf_add_type_mapping): Likewise. (ctf_type_mapping): Likewise. (ctf_dynhash_empty): Likewise. * ctf-open.c (ctf_file_close): Update accordingly. * ctf-create.c (ctf_update): Likewise. (ctf_add_type): Populate the mapping. * ctf-hash.c (ctf_hash_type_mapping_key): Hash a type mapping key. (ctf_hash_eq_type_mapping_key): Check the key for equality. (ctf_dynhash_insert): Fix comment typo. (ctf_dynhash_empty): New. * ctf-link.c (ctf_add_type_mapping): New. (ctf_type_mapping): Likewise. (empty_link_type_mapping): New. (ctf_link_one_input_archive): Call it.
Diffstat (limited to 'libctf/ctf-hash.c')
-rw-r--r--libctf/ctf-hash.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c
index 3512d22a347..c6233eb6767 100644
--- a/libctf/ctf-hash.c
+++ b/libctf/ctf-hash.c
@@ -82,6 +82,28 @@ ctf_hash_eq_string (const void *a, const void *b)
return !strcmp((const char *) hep_a->key, (const char *) hep_b->key);
}
+/* Hash a type_mapping_key. */
+unsigned int
+ctf_hash_type_mapping_key (const void *ptr)
+{
+ ctf_helem_t *hep = (ctf_helem_t *) ptr;
+ ctf_link_type_mapping_key_t *k = (ctf_link_type_mapping_key_t *) hep->key;
+
+ return htab_hash_pointer (k->cltm_fp) + 59 * htab_hash_pointer ((void *) k->cltm_idx);
+}
+
+int
+ctf_hash_eq_type_mapping_key (const void *a, const void *b)
+{
+ ctf_helem_t *hep_a = (ctf_helem_t *) a;
+ ctf_helem_t *hep_b = (ctf_helem_t *) b;
+ ctf_link_type_mapping_key_t *key_a = (ctf_link_type_mapping_key_t *) hep_a->key;
+ ctf_link_type_mapping_key_t *key_b = (ctf_link_type_mapping_key_t *) hep_b->key;
+
+ return (key_a->cltm_fp == key_b->cltm_fp)
+ && (key_a->cltm_idx == key_b->cltm_idx);
+}
+
/* The dynhash, used for hashes whose size is not known at creation time. */
/* Free a single ctf_helem. */
@@ -164,7 +186,7 @@ ctf_dynhash_insert (ctf_dynhash_t *hp, void *key, void *value)
return errno;
/* We need to keep the key_free and value_free around in each item because the
- del function has no visiblity into the hash as a whole, only into the
+ del function has no visibility into the hash as a whole, only into the
individual items. */
slot->key_free = hp->key_free;
@@ -180,6 +202,12 @@ ctf_dynhash_remove (ctf_dynhash_t *hp, const void *key)
htab_remove_elt (hp->htab, &hep);
}
+void
+ctf_dynhash_empty (ctf_dynhash_t *hp)
+{
+ htab_empty (hp->htab);
+}
+
void *
ctf_dynhash_lookup (ctf_dynhash_t *hp, const void *key)
{