diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2024-07-26 21:38:24 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2024-08-01 14:30:21 +0100 |
commit | 3c21a5bedb79de470dea02626296e7e310d272e4 (patch) | |
tree | c7499656115e6234ae367797d461c2d93bce9237 /include | |
parent | e1a8c74214d3f5a75fcf03f5dd4550ecd2085d32 (diff) | |
download | gdb-3c21a5bedb79de470dea02626296e7e310d272e4.zip gdb-3c21a5bedb79de470dea02626296e7e310d272e4.tar.gz gdb-3c21a5bedb79de470dea02626296e7e310d272e4.tar.bz2 |
libctf, include: add ctf_dict_set_flag: less enum dup checking by default
The recent change to detect duplicate enum values and return ECTF_DUPLICATE
when found turns out to perturb a great many callers. In particular, the
pahole-created kernel BTF has the same problem we historically did, and
gleefully emits duplicated enum constants in profusion. Handling the
resulting duplicate errors from BTF -> CTF converters reasonably is
unreasonably difficult (it amounts to forcing them to skip some types or
reimplement the deduplicator).
So let's step back a bit. What we care about mostly is that the
deduplicator treat enums with conflicting enumeration constants as
conflicting types: programs that want to look up enumeration constant ->
value mappings using the new APIs to do so might well want the same checks
to apply to any ctf_add_* operations they carry out (and since they're
*using* the new APIs, added at the same time as this restriction was
imposed, there is likely to be no negative consequence of this).
So we want some way to allow processes that know about duplicate detection
to opt into it, while allowing everyone else to stay clear of it: but we
want ctf_link to get this behaviour even if its caller has opted out.
So add a new concept to the API: dict-wide CTF flags, set via
ctf_dict_set_flag, obtained via ctf_dict_get_flag. They are not bitflags
but simple arbitrary integers and an on/off value, stored in an unspecified
manner (the one current flag, we translate into an LCTF_* flag value in the
internal ctf_dict ctf_flags word). If you pass in an invalid flag or value
you get a new ECTF_BADFLAG error, so the caller can easily tell whether
flags added in future are valid with a particular libctf or not.
We check this flag in ctf_add_enumerator, and set it around the link
(including on child per-CU dicts). The newish enumerator-iteration test is
souped up to check the semantics of the flag as well.
The fact that the flag can be set and unset at any time has curious
consequences. You can unset the flag, insert a pile of duplicates, then set
it and expect the new duplicates to be detected, not only by
ctf_add_enumerator but also by ctf_lookup_enumerator. This means we now
have to maintain the ctf_names and conflicting_enums enum-duplication
tracking as new enums are added, not purely as the dict is opened.
Move that code out of init_static_types_internal and into a new
ctf_track_enumerator function that addition can also call.
(None of this affects the file format or serialization machinery, which has
to be able to handle duplicate enumeration constants no matter what.)
include/
* ctf-api.h (CTF_ERRORS) [ECTF_BADFLAG]: New.
(ECTF_NERR): Update.
(CTF_STRICT_NO_DUP_ENUMERATORS): New flag.
(ctf_dict_set_flag): New function.
(ctf_dict_get_flag): Likewise.
libctf/
* ctf-impl.h (LCTF_STRICT_NO_DUP_ENUMERATORS): New flag.
(ctf_track_enumerator): Declare.
* ctf-dedup.c (ctf_dedup_emit_type): Set it.
* ctf-link.c (ctf_create_per_cu): Likewise.
(ctf_link_deduplicating_per_cu): Likewise.
(ctf_link): Likewise.
(ctf_link_write): Likewise.
* ctf-subr.c (ctf_dict_set_flag): New function.
(ctf_dict_get_flag): New function.
* ctf-open.c (init_static_types_internal): Move enum tracking to...
* ctf-create.c (ctf_track_enumerator): ... this new function.
(ctf_add_enumerator): Call it.
* libctf.ver: Add the new functions.
* testsuite/libctf-lookup/enumerator-iteration.c: Test them.
Diffstat (limited to 'include')
-rw-r--r-- | include/ctf-api.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/include/ctf-api.h b/include/ctf-api.h index d3d8dbf..dd719d1 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -243,7 +243,8 @@ typedef struct ctf_snapshot_id _CTF_ITEM (ECTF_FLAGS, "CTF header contains flags unknown to libctf.") \ _CTF_ITEM (ECTF_NEEDSBFD, "This feature needs a libctf with BFD support.") \ _CTF_ITEM (ECTF_INCOMPLETE, "Type is not a complete type.") \ - _CTF_ITEM (ECTF_NONAME, "Type name must not be empty.") + _CTF_ITEM (ECTF_NONAME, "Type name must not be empty.") \ + _CTF_ITEM (ECTF_BADFLAG, "Invalid CTF dict flag specified.") #define ECTF_BASE 1000 /* Base value for libctf errnos. */ @@ -256,7 +257,7 @@ _CTF_ERRORS #undef _CTF_FIRST }; -#define ECTF_NERR (ECTF_NONAME - ECTF_BASE + 1) /* Count of CTF errors. */ +#define ECTF_NERR (ECTF_BADFLAG - ECTF_BASE + 1) /* Count of CTF errors. */ /* The CTF data model is inferred to be the caller's data model or the data model of the given object, unless ctf_setmodel is explicitly called. */ @@ -282,6 +283,12 @@ _CTF_ERRORS #define CTF_MN_RECURSE 0x1 /* Recurse into unnamed members. */ +/* Flags for ctf_dict_set_flag. */ + +/* If set, duplicate enumerators in a single dict fail with ECTF_DUPLICATE. */ + +#define CTF_STRICT_NO_DUP_ENUMERATORS 0x1 + /* These typedefs are used to define the signature for callback functions that can be used with the iteration and visit functions below. There is also a family of iteration functions that do not require callbacks. */ @@ -350,6 +357,11 @@ extern ctf_archive_t *ctf_open (const char *filename, const char *target, int *errp); extern void ctf_close (ctf_archive_t *); +/* Set or unset dict-wide boolean flags, and get the value of these flags. */ + +extern int ctf_dict_set_flag (ctf_dict_t *, uint64_t flag, int set); +extern int ctf_dict_get_flag (ctf_dict_t *, uint64_t flag); + /* Return the data, symbol, or string sections used by a given CTF dict. */ extern ctf_sect_t ctf_getdatasect (const ctf_dict_t *); extern ctf_sect_t ctf_getsymsect (const ctf_dict_t *); |