libctf: create, types: conflicting types

The conflicting type kind is a CTF-specific prefix kind consisting purely of
an optional translation unit name.  It takes the place of the old hidden
bit: we have already seen it used to prefix types added with a
CTF_ADD_NONROOT flag.  The deduplicator will also use them to label
conflicting types from different TUs smushed into the same dict by the
CU-mapping mechanism: unlike the hidden bit, with this scheme users can tell
which CUs the conflicting types came from.

New API:

+int ctf_type_conflicting (ctf_dict_t *, ctf_id_t, const char **cuname);
+int ctf_set_conflicting (ctf_dict_t *, ctf_id_t, const char *);

(Frankly I expect ctf_set_conflicting to be used only by deduplicators and
things like that, but if we provide an option to query something we should
also provide an option to produce it...)
This commit is contained in:
Nick Alcock
2025-04-25 11:23:46 +01:00
parent fb8917ac21
commit d5dd8997b3
4 changed files with 96 additions and 1 deletions

View File

@@ -928,6 +928,43 @@ ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp)
return 0;
}
/* Set this type as conflicting in compilation unit CUNAME. */
int
ctf_set_conflicting (ctf_dict_t *fp, ctf_id_t type, const char *cuname)
{
ctf_dict_t *ofp = fp;
ctf_dtdef_t *dtd;
ctf_type_t *prefix;
uint32_t idx;
if (ctf_lookup_by_id (&fp, type, NULL) == NULL)
return -1; /* errno is set for us. */
idx = ctf_type_to_index (fp, type);
dtd = ctf_dtd_lookup (fp, type);
/* You can only call ctf_set_conflicting on a type you have added, not a type
that was read in via ctf_open. */
if (idx < fp->ctf_stypes)
return (ctf_set_errno (ofp, ECTF_RDONLY));
if (dtd == NULL)
return (ctf_set_errno (ofp, ECTF_BADID));
if ((prefix = (ctf_type_t *) ctf_find_prefix (fp, dtd->dtd_buf,
CTF_K_CONFLICTING)) == NULL)
{
if ((prefix = ctf_add_prefix (fp, dtd, 0)) == NULL)
return -1; /* errno is set for us. */
}
prefix->ctt_name = ctf_str_add (fp, cuname);
prefix->ctt_info = CTF_TYPE_INFO (CTF_K_CONFLICTING, 0,
dtd->dtd_vlen_size < 65536
? dtd->dtd_vlen_size : 0);
return 0;
}
/* Add a type or decl tag applying to some whole type, or to some
component of a type. Component -1 is a whole type. */