libctf: fix cv-qualified unnamed struct/union field lookup

GCC permits not only unnamed structs and unions, but cv-qualified ones.
Our earlier fix in 6c3a38777b supported
unnamed structs and unions, but only unqualified ones.

Resolving away cvr-quals of nameless fields (and, irrelevantly, typedefs)
is easy and fixes this problem.

Tests adjusted accordingly.

libctf/
	PR libctf/32746
	* ctf-types.c (ctf_member_next): Resolve away cv-quals.
	(ctf_member_info): Likewise.
	* testsuite/libctf-lookup/struct-iteration-ctf.c: Add a cv-qualified
	type or two: make sure to keep a non-qualified one.
	* testsuite/libctf-lookup/struct-iteration.c: Verify consistency
	of ctf_member_next and ctf_member_info.
	* testsuite/libctf-lookup/struct-iteration.lk: Adjust.

Tested-by: Stephen Brennan <stephen.s.brennan@oracle.com>
This commit is contained in:
Nick Alcock
2025-02-24 18:11:25 +00:00
parent 83e8a5d39b
commit fa4fe27537
4 changed files with 55 additions and 13 deletions

View File

@@ -187,10 +187,21 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
*membtype = memb.ctlm_type;
offset = (unsigned long) CTF_LMEM_OFFSET (&memb);
if (membname[0] == 0
&& (ctf_type_kind (fp, memb.ctlm_type) == CTF_K_STRUCT
|| ctf_type_kind (fp, memb.ctlm_type) == CTF_K_UNION))
i->ctn_type = memb.ctlm_type;
if (membname[0] == 0)
{
ctf_id_t resolved;
if ((resolved = ctf_type_resolve (fp, memb.ctlm_type)) == CTF_ERR)
{
if (ctf_errno (fp) != ECTF_NONREPRESENTABLE)
return -1; /* errno is set for us. */
resolved = memb.ctlm_type;
}
if (ctf_type_kind (fp, resolved) == CTF_K_STRUCT
|| ctf_type_kind (fp, resolved) == CTF_K_UNION)
i->ctn_type = resolved;
}
i->ctn_n++;
/* The callers might want automatic recursive sub-struct traversal. */
@@ -1406,16 +1417,24 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
{
ctf_lmember_t memb;
const char *membname;
ctf_id_t resolved;
if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0)
return (ctf_set_errno (ofp, ctf_errno (fp)));
membname = ctf_strptr (fp, memb.ctlm_name);
if ((resolved = ctf_type_resolve (fp, memb.ctlm_type)) == CTF_ERR)
{
if (ctf_errno (fp) != ECTF_NONREPRESENTABLE)
return (ctf_set_errno (ofp, ctf_errno (fp)));
resolved = memb.ctlm_type;
}
if (membname[0] == 0
&& (ctf_type_kind (fp, memb.ctlm_type) == CTF_K_STRUCT
|| ctf_type_kind (fp, memb.ctlm_type) == CTF_K_UNION)
&& (ctf_member_info (fp, memb.ctlm_type, name, mip) == 0))
&& (ctf_type_kind (fp, resolved) == CTF_K_STRUCT
|| ctf_type_kind (fp, resolved) == CTF_K_UNION)
&& (ctf_member_info (fp, resolved, name, mip) == 0))
{
mip->ctm_offset += (unsigned long) CTF_LMEM_OFFSET (&memb);
return 0;