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

@@ -1631,6 +1631,49 @@ ctf_type_kind_forwarded (ctf_dict_t *fp, ctf_id_t type)
return ret;
}
/* Return nonzero if this type is conflicting, nonzero if it's not, < 0 on
error; if CUNAME is set, set it to the name of the conflicting compilation
unit for the passed-in type (which may be a null string if the cuname is not
known). */
int
ctf_type_conflicting (ctf_dict_t *fp, ctf_id_t type, const char **cuname)
{
ctf_dict_t *ofp = fp;
const ctf_type_t *tp;
/* The unimplemented / void type is never conflicting. */
if (type == 0)
return 0;
if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
return -1; /* errno is set for us. */
if ((tp = ctf_lookup_by_id (&fp, type, NULL)) == NULL)
return -1; /* errno is set for us. */
if (cuname)
*cuname = 0;
if (LCTF_INFO_ISROOT (fp, tp->ctt_info))
return 0;
if (!cuname)
return 1;
while (LCTF_INFO_UNPREFIXED_KIND (fp, tp->ctt_info) != CTF_K_CONFLICTING
&& LCTF_IS_PREFIXED_INFO (tp->ctt_info))
tp++;
/* We already checked that this is a non-root-visible type, so this must be
CTF_K_CONFLICTING. */
if (!ctf_assert (ofp, LCTF_IS_PREFIXED_INFO (tp->ctt_info)))
return -1; /* errno is set for us. */
*cuname = ctf_strptr (fp, tp->ctt_name);
return 1;
}
/* If the type is one that directly references another type (such as POINTER),
then return the ID of the type to which it refers. */