aboutsummaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ctf-impl.h7
-rw-r--r--libctf/ctf-string.c60
2 files changed, 47 insertions, 20 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index cd93a18..b17a2d8 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -208,13 +208,13 @@ typedef struct ctf_err_warning
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. */
@@ -393,7 +393,7 @@ struct ctf_dict
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. */
@@ -746,7 +746,6 @@ extern int ctf_str_move_refs (ctf_dict_t *fp, void *src, size_t len, void *dest)
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 *
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)