the csa_refs in all entries are purged. */
#define CTF_STR_ATOM_FREEABLE 0x1
-#define CTF_STR_ATOM_MOVABLE 0x2
typedef struct ctf_str_atom
{
char *csa_str; /* Pointer to string (also used as hash key). */
ctf_list_t csa_refs; /* This string's refs. */
- uint32_t csa_offset; /* Strtab offset, if any. */
+ ctf_list_t csa_movable_refs; /* This string's movable refs. */
+ uint32_t csa_offset; /* Offset in this strtab, if any. */
uint32_t csa_external_offset; /* External strtab offset, if any. */
unsigned long csa_snapshot_id; /* Snapshot ID at time of creation. */
int csa_flags; /* CTF_STR_ATOM_* flags. */
ctf_strs_t ctf_str[2]; /* Array of string table base and bounds. */
ctf_strs_writable_t *ctf_dynstrtab; /* Dynamically allocated string table, if any. */
ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */
- ctf_dynhash_t *ctf_str_movable_refs; /* Hash table of void * -> ctf_str_atom_ref_t. */
+ ctf_dynhash_t *ctf_str_movable_refs; /* Hash table of void * -> ctf_str_atom_ref_movable_t. */
uint32_t ctf_str_prov_offset; /* Latest provisional offset assigned so far. */
unsigned char *ctf_base; /* CTF file pointer. */
unsigned char *ctf_dynbase; /* Freeable CTF file pointer. */
extern int ctf_str_add_external (ctf_dict_t *, const char *, uint32_t offset);
extern void ctf_str_remove_ref (ctf_dict_t *, const char *, uint32_t *ref);
extern void ctf_str_rollback (ctf_dict_t *, ctf_snapshot_id_t);
-extern void ctf_str_purge_refs (ctf_dict_t *);
extern const ctf_strs_writable_t *ctf_str_write_strtab (ctf_dict_t *);
extern struct ctf_archive_internal *
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. */
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;
}
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)
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);
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
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);
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. */
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;
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;
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)