diff options
Diffstat (limited to 'libctf/ctf-string.c')
-rw-r--r-- | libctf/ctf-string.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c index 2d96e45..4e1fd62 100644 --- a/libctf/ctf-string.c +++ b/libctf/ctf-string.c @@ -109,20 +109,25 @@ static void ctf_str_purge_atom_refs (ctf_str_atom_t *atom) { ctf_str_atom_ref_t *ref, *next; + ctf_str_atom_ref_movable_t *movref, *movnext; for (ref = ctf_list_next (&atom->csa_refs); ref != NULL; ref = next) { next = ctf_list_next (ref); ctf_list_delete (&atom->csa_refs, ref); - if (atom->csa_flags & CTF_STR_ATOM_MOVABLE) - { - ctf_str_atom_ref_movable_t *movref; - movref = (ctf_str_atom_ref_movable_t *) ref; - ctf_dynhash_remove (movref->caf_movable_refs, ref); - } - free (ref); } + + for (movref = ctf_list_next (&atom->csa_movable_refs); + movref != NULL; movref = movnext) + { + movnext = ctf_list_next (movref); + ctf_list_delete (&atom->csa_movable_refs, movref); + + ctf_dynhash_remove (movref->caf_movable_refs, movref); + + free (movref); + } } /* Free an atom. */ @@ -263,9 +268,10 @@ aref_create (ctf_dict_t *fp, ctf_str_atom_t *atom, uint32_t *ref, int flags) free (aref); return NULL; } + ctf_list_append (&atom->csa_movable_refs, movref); } - - ctf_list_append (&atom->csa_refs, aref); + else + ctf_list_append (&atom->csa_refs, aref); return aref; } @@ -489,7 +495,7 @@ ctf_str_move_refs (ctf_dict_t *fp, void *src, size_t len, void *dest) for (p = (uintptr_t) src; p - (uintptr_t) src < len; p++) { - ctf_str_atom_ref_t *ref; + ctf_str_atom_ref_movable_t *ref; if ((ref = ctf_dynhash_lookup (fp->ctf_str_movable_refs, (ctf_str_atom_ref_t *) p)) != NULL) @@ -514,6 +520,7 @@ void ctf_str_remove_ref (ctf_dict_t *fp, const char *str, uint32_t *ref) { ctf_str_atom_ref_t *aref, *anext; + ctf_str_atom_ref_movable_t *amovref, *amovnext; ctf_str_atom_t *atom = NULL; atom = ctf_dynhash_lookup (fp->ctf_str_atoms, str); @@ -529,6 +536,18 @@ ctf_str_remove_ref (ctf_dict_t *fp, const char *str, uint32_t *ref) free (aref); } } + + for (amovref = ctf_list_next (&atom->csa_movable_refs); + amovref != NULL; amovref = amovnext) + { + amovnext = ctf_list_next (amovref); + if (amovref->caf_ref == ref) + { + ctf_list_delete (&atom->csa_movable_refs, amovref); + ctf_dynhash_remove (fp->ctf_str_movable_refs, ref); + free (amovref); + } + } } /* A ctf_dynhash_iter_remove() callback that removes atoms later than a given @@ -558,11 +577,12 @@ ctf_str_purge_one_atom_refs (void *key _libctf_unused_, void *value, void *arg _libctf_unused_) { ctf_str_atom_t *atom = (ctf_str_atom_t *) value; + ctf_str_purge_atom_refs (atom); } /* Remove all the recorded refs from the atoms table. */ -void +static void ctf_str_purge_refs (ctf_dict_t *fp) { ctf_dynhash_iter (fp->ctf_str_atoms, ctf_str_purge_one_atom_refs, NULL); @@ -573,10 +593,15 @@ static void ctf_str_update_refs (ctf_str_atom_t *refs, uint32_t value) { ctf_str_atom_ref_t *ref; + ctf_str_atom_ref_movable_t *movref; for (ref = ctf_list_next (&refs->csa_refs); ref != NULL; ref = ctf_list_next (ref)) *(ref->caf_ref) = value; + + for (movref = ctf_list_next (&refs->csa_movable_refs); + movref != NULL; movref = ctf_list_next (movref)) + *(movref->caf_ref) = value; } /* Sort the strtab. */ @@ -664,8 +689,9 @@ ctf_str_write_strtab (ctf_dict_t *fp) if (!ctf_assert (fp, atom)) goto err_strtab; - if (atom->csa_str[0] == 0 || ctf_list_empty_p (&atom->csa_refs) || - atom->csa_external_offset) + if (atom->csa_str[0] == 0 || atom->csa_external_offset + || (ctf_list_empty_p (&atom->csa_refs) + && ctf_list_empty_p (&atom->csa_movable_refs))) continue; strtab->cts_len += strlen (atom->csa_str) + 1; @@ -700,8 +726,9 @@ ctf_str_write_strtab (ctf_dict_t *fp) if (!ctf_assert (fp, atom)) goto err_sorttab; - if (atom->csa_str[0] == 0 || ctf_list_empty_p (&atom->csa_refs) || - atom->csa_external_offset) + if (atom->csa_str[0] == 0 || atom->csa_external_offset + || (ctf_list_empty_p (&atom->csa_refs) + && ctf_list_empty_p (&atom->csa_movable_refs))) continue; sorttab[i++] = atom; @@ -747,7 +774,8 @@ ctf_str_write_strtab (ctf_dict_t *fp) ctf_str_atom_t *atom = (ctf_str_atom_t *) v; uint32_t offset; - if (ctf_list_empty_p (&atom->csa_refs)) + if (ctf_list_empty_p (&atom->csa_refs) && + ctf_list_empty_p (&atom->csa_movable_refs)) continue; if (atom->csa_external_offset) |