libctf: serialize: kind suppression and prohibition

The CTF serialization machinery decides whether to write out a dict as BTF
or CTF (or, in LIBCTF_BTM_BTF mode, whether to write out a dict or fail with
ECTF_NOTBTF) in part by looking at the type kinds in the dictionary.

It is possible that you'd like to extend this check and ban specific type
kinds from the dictionary (possibly even if it's CTF); it's also possible
that you'd like to *not* fail even if a CTF-only kind is found, but rather
replace it with a still-valid stub (CTF_K_UNKNOWN / BTF_KIND_UNKNOWN) and
keep going.  (The kernel's btfarchive machinery does this to ensure that
the compiler and previous link stages have emitted only valid BTF type
kinds.)

ctf_write_suppress_kind supports both these use cases:

+int ctf_write_suppress_kind (ctf_dict_t *fp, int kind, int prohibited);

This commit adds only the core population code: the actual suppression is
spread across the serializer and will be added in the next commits.
This commit is contained in:
Nick Alcock
2025-04-25 12:42:12 +01:00
parent 2c5f74300a
commit c14bdfc7a4
4 changed files with 43 additions and 0 deletions

View File

@@ -380,6 +380,8 @@ struct ctf_dict
const ctf_dictops_t *ctf_dictops; /* Version-specific dict operations. */
ctf_header_t *ctf_header; /* The header from this CTF dict. */
ctf_header_v3_t *ctf_v3_header; /* The header from an upgraded CTF dict. */
ctf_dynset_t *ctf_write_prohibitions; /* Kinds writeout causes error for. */
ctf_dynset_t *ctf_write_suppressions; /* Kinds that are skipped on write. */
unsigned char ctf_openflags; /* Flags the dict had when opened. */
int ctf_opened_btf; /* Whether this dict was pure BTF when
opened. */