diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2025-02-11 14:32:40 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2025-02-28 14:16:38 +0000 |
commit | 83e8a5d39be92d052986fe9d687a049db8f9f8c5 (patch) | |
tree | 47acc84bf6453cdeedfbc5223a28d0ec52027848 /libctf/ctf-create.c | |
parent | bf89fce0cf9f94f451f584877019d2c7ba227154 (diff) | |
download | binutils-83e8a5d39be92d052986fe9d687a049db8f9f8c5.zip binutils-83e8a5d39be92d052986fe9d687a049db8f9f8c5.tar.gz binutils-83e8a5d39be92d052986fe9d687a049db8f9f8c5.tar.bz2 |
libctf: fix slices of slices and of enums
Slices had a bunch of horrible usability problems. In particular, while
towers of cv-quals are resolved away by functions that need to do it, towers
of cv-quals with slices in the middle are not resolved away by functions
like ctf_enum_value that can see through slices: resolving volatile -> slice
-> const -> enum will leave it with a 'const', which will error pointlessly,
annoying callers, who reasonably expect slices to be more invisible than
this. (The user-callable ctf_type_resolve still does not resolve away
slices, because this is the only way users can see that the slices are there
at all.)
This is induced by a fix for another wart: ctf_add_enumerator does not
resolve anything away at all, so you can't even add enumerators to const or
volatile enums -- and more problematically, you can't add enumerators to
enums with an explicit encoding without resolving away the types by hand,
since ctf_add_enum_encoded works by returning a slice! ctf_add_enumerator
now resolves away all of those, so any cvr-or-typedef-or-slice-qual
terminating in an enum can be added to, exactly as callers likely expect.
(New tests added.)
libctf/
* ctf-create.c (ctf_add_enumerator): Resolve away cvr-qualness.
* ctf-types.c (ctf_type_resolve_unsliced): Don't terminate at
the first slice.
* testsuite/libctf-writable/slice-of-slice.*: New test.
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r-- | libctf/ctf-create.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index 6d2479c..25dd44d 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -1044,7 +1044,7 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name, int value) { ctf_dict_t *ofp = fp; - ctf_dtdef_t *dtd = ctf_dtd_lookup (fp, enid); + ctf_dtdef_t *dtd; unsigned char *old_vlen; ctf_enum_t *en; @@ -1053,6 +1053,10 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name, if (name == NULL) return (ctf_set_errno (fp, EINVAL)); + if ((enid = ctf_type_resolve_unsliced (fp, enid)) == CTF_ERR) + return -1; /* errno is set for us. */ + + dtd = ctf_dtd_lookup (fp, enid); if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, enid)) fp = fp->ctf_parent; |