diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2025-06-26 15:45:31 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2025-07-01 15:54:26 +0100 |
commit | 84b2be94e5b652d48993d3980b8a3378bd3c6cb5 (patch) | |
tree | c4a073e5385080035f1907ff588d32d9bdcfe6c0 /libctf/ctf-create.c | |
parent | a17dd69b3370d1c61ca720fe02ddaed04ed84e59 (diff) | |
download | binutils-84b2be94e5b652d48993d3980b8a3378bd3c6cb5.zip binutils-84b2be94e5b652d48993d3980b8a3378bd3c6cb5.tar.gz binutils-84b2be94e5b652d48993d3980b8a3378bd3c6cb5.tar.bz2 |
libctf: create: addition of non-root types should not return root types
If you add a non-root type to a dict, you should always get a new, unique
type ID back, even if a root-visible type with the same name already exists.
Unfortunately, if the root-visible type is a forward, and you're adding a
non-root-visible struct, union, or enum, the machinery to detect forwards
and promote them to the concrete type fires in this case and returns the
root-visible type! If this is an enum being inserted hidden because its
enumerands conflict with some other enum, this will lead to failure later
on: in any case, it's seriously counterintuitive to add a non-root- visible
type and get a root-visible one instead.
Fix this by checking the root-visible flag properly and only checking for
forwards if this type is root-visible. (This may lead to a certain degree
of proliferation of non-root-visible forwards: we can add a cleanup pass for
those later if needed.)
libctf/
* ctf-create.c (ctf_add_struct_sized): Check the root-visible flag when
doing forward promotion.
(ctf_add_union_sized): Likewise.
(ctf_add_enum): Likewise.
Reviewed-by: Bruce McCulloch <bruce.mcculloch@oracle.com>
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r-- | libctf/ctf-create.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index 25dd44d..ca984e8 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -788,7 +788,7 @@ ctf_add_struct_sized (ctf_dict_t *fp, uint32_t flag, const char *name, size_t initial_vlen = sizeof (ctf_lmember_t) * INITIAL_VLEN; /* Promote root-visible forwards to structs. */ - if (name != NULL) + if (name != NULL && flag == CTF_ADD_ROOT) type = ctf_lookup_by_rawname (fp, CTF_K_STRUCT, name); /* Prohibit promotion if this type was ctf_open()ed. */ @@ -832,7 +832,7 @@ ctf_add_union_sized (ctf_dict_t *fp, uint32_t flag, const char *name, size_t initial_vlen = sizeof (ctf_lmember_t) * INITIAL_VLEN; /* Promote root-visible forwards to unions. */ - if (name != NULL) + if (name != NULL && flag == CTF_ADD_ROOT) type = ctf_lookup_by_rawname (fp, CTF_K_UNION, name); /* Prohibit promotion if this type was ctf_open()ed. */ @@ -875,7 +875,7 @@ ctf_add_enum (ctf_dict_t *fp, uint32_t flag, const char *name) size_t initial_vlen = sizeof (ctf_enum_t) * INITIAL_VLEN; /* Promote root-visible forwards to enums. */ - if (name != NULL) + if (name != NULL && flag == CTF_ADD_ROOT) type = ctf_lookup_by_rawname (fp, CTF_K_ENUM, name); /* Prohibit promotion if this type was ctf_open()ed. */ |