From: Nick Alcock Date: Fri, 25 Apr 2025 10:31:28 +0000 (+0100) Subject: libctf: create, types: reftypes and pointers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d65d03bec44d401b48fb897d9a6ee132d18fa925;p=thirdparty%2Fbinutils-gdb.git libctf: create, types: reftypes and pointers This is pure adjustment for internal API changes, and a change to the type-compatibility of pointers to type 0 now that it can be void as well as "unrepresentable". By now this dance should be quite familiar. --- diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index ba8c266dd8d..f2b98b8ddb9 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -741,25 +741,26 @@ ctf_id_t ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, uint32_t kind) { ctf_dtdef_t *dtd; - ctf_id_t type; ctf_dict_t *typedict = fp; ctf_dict_t *refdict = fp; int child = fp->ctf_flags & LCTF_CHILD; + uint32_t type_idx; + uint32_t ref_idx; if (ref == CTF_ERR || ref > CTF_MAX_TYPE) return (ctf_set_typed_errno (fp, EINVAL)); - if (ref != 0 && ctf_lookup_by_id (&refdict, ref) == NULL) + if (ref != 0 && ctf_lookup_by_id (&refdict, ref, NULL) == NULL) return CTF_ERR; /* errno is set for us. */ - if ((type = ctf_add_generic (fp, flag, NULL, kind, 0, &dtd)) == CTF_ERR) + if ((dtd = ctf_add_generic (fp, flag, NULL, kind, 0, 0, 0, NULL)) == NULL) return CTF_ERR; /* errno is set for us. */ - dtd->dtd_data.ctt_info = CTF_TYPE_INFO (kind, flag, 0); - dtd->dtd_data.ctt_type = (uint32_t) ref; + dtd->dtd_data->ctt_info = CTF_TYPE_INFO (kind, 0, 0); + dtd->dtd_data->ctt_type = (uint32_t) ref; if (kind != CTF_K_POINTER) - return type; + return dtd->dtd_type; /* If we are adding a pointer, update the ptrtab, pointing at this type from the type it points to. Note that ctf_typemax is at this point one higher @@ -767,15 +768,16 @@ ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, uint32_t kind) addition of this type. The pptrtab is lazily-updated as needed, so is not touched here. */ - typedict = ctf_get_dict (fp, type); - uint32_t type_idx = ctf_type_to_index (typedict, type); - uint32_t ref_idx = ctf_type_to_index (refdict, ref); + typedict = ctf_get_dict (fp, dtd->dtd_type); + + type_idx = ctf_type_to_index (typedict, dtd->dtd_type); + ref_idx = ctf_type_to_index (refdict, ref); if (ctf_type_ischild (fp, ref) == child && ref_idx < fp->ctf_typemax) fp->ctf_ptrtab[ref_idx] = type_idx; - return type; + return dtd->dtd_type; } ctf_id_t diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index 275e5c00e15..2ee073e37a6 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -1848,7 +1848,7 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type) ctf_id_t ntype; uint32_t idx; - if (ctf_lookup_by_id (&fp, type) == NULL) + if (ctf_lookup_by_id (&fp, type, NULL) == NULL) return CTF_ERR; /* errno is set for us. */ idx = ctf_type_to_index (fp, type); @@ -1863,7 +1863,7 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type) if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) return (ctf_set_typed_errno (ofp, ECTF_NOTYPE)); - if (ctf_lookup_by_id (&fp, type) == NULL) + if (ctf_lookup_by_id (&fp, type, NULL) == NULL) return (ctf_set_typed_errno (ofp, ECTF_NOTYPE)); idx = ctf_type_to_index (fp, type); @@ -2019,10 +2019,9 @@ ctf_type_compat (ctf_dict_t *lfp, ctf_id_t ltype, if (lkind < 0 || rkind < 0) return -1; /* errno is set for us. */ - ltp = ctf_lookup_by_id (&lfp, ltype); - rtp = ctf_lookup_by_id (&rfp, rtype); - - if (ltp != NULL && rtp != NULL) + if (ctf_lookup_by_id (&lfp, ltype, <p) != NULL && + ctf_lookup_by_id (&rfp, rtype, &rtp) != NULL + && ltp != NULL && rtp != NULL) same_names = (strcmp (ctf_strptr (lfp, ltp->ctt_name), ctf_strptr (rfp, rtp->ctt_name)) == 0); @@ -2043,8 +2042,17 @@ ctf_type_compat (ctf_dict_t *lfp, ctf_id_t ltype, && ctf_type_encoding (rfp, rtype, &re) == 0 && memcmp (&le, &re, sizeof (ctf_encoding_t)) == 0); case CTF_K_POINTER: - return (ctf_type_compat (lfp, ctf_type_reference (lfp, ltype), - rfp, ctf_type_reference (rfp, rtype))); + { + ctf_id_t lref = ctf_type_reference (lfp, ltype); + ctf_id_t rref = ctf_type_reference (rfp, rtype); + + /* void * is only compatible with itself. */ + + if (lref == 0 && rref == 0) + return 1; + else + return (ctf_type_compat (lfp, lref, rfp, rref)); + } case CTF_K_ARRAY: return (ctf_array_info (lfp, ltype, &la) == 0 && ctf_array_info (rfp, rtype, &ra) == 0