]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: create, types: reftypes and pointers
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 10:31:28 +0000 (11:31 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:43 +0000 (18:07 +0100)
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.

libctf/ctf-create.c
libctf/ctf-types.c

index ba8c266dd8d3a795935319f37f7f1dfd4c670926..f2b98b8ddb9bf23eea1c88eb63a155ec9af27bcc 100644 (file)
@@ -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
index 275e5c00e159a36116e0c31adcef9ddf8c202e94..2ee073e37a65b81fc70a48e01dc110b8171e1d7b 100644 (file)
@@ -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, &ltp) != 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