]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: create: ctf_add_type should hand back already-added non-SoUs
authorNick Alcock <nick.alcock@oracle.com>
Tue, 5 Nov 2019 13:09:57 +0000 (13:09 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 26 Jun 2020 14:56:39 +0000 (15:56 +0100)
When we add a type from a dictionary and then try to add it again, we
should hand it back unchanged unless it is a structure, union or enum
with a different number of members.  That's what the comment says we do.

Instead, we hand it back unchanged *only* if it is a structure, union or
enum with the same number of members: non-structs, unions and enums are
unconditionally added.  This causes extreme type bloating and (in
conjunction with the bug fixed by the next commit) can easily lead to
the same type being mistakenly added to a dictionary more than once
(which, for forwards, was not banned and led to dictionary corruption).

libctf/
* ctf-create.c (ctf_add_type_internal): Hand back existing types
unchanged.

libctf/ChangeLog
libctf/ctf-create.c

index 7868d0b5a9e0cc5c228958513092b2823be57367..1b019a3e5f762fa8789478d3d62d4e85d99ad6eb 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-26  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-create.c (ctf_add_type_internal): Hand back existing types
+       unchanged.
+
 2020-06-26  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-create.c (ctf_add_forward): Don't add forwards to
index c24a246c16410aff66ce9375004aa293062de5f4..7e94a254c500954243b6c1e5047703956f86a42a 100644 (file)
@@ -1665,13 +1665,17 @@ ctf_add_type_internal (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type
         kind and (if a struct or union) has the same number of members, hand it
         straight back.  */
 
-      if ((ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
-         && (kind == CTF_K_STRUCT || kind == CTF_K_UNION
-             || kind == CTF_K_ENUM))
+      if (ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
        {
-         if ((dst_tp = ctf_lookup_by_id (&tmp_fp, dst_type)) != NULL)
-           if (vlen == LCTF_INFO_VLEN (tmp_fp, dst_tp->ctt_info))
-             return tmp;
+         if (kind == CTF_K_STRUCT || kind == CTF_K_UNION
+             || kind == CTF_K_ENUM)
+           {
+             if ((dst_tp = ctf_lookup_by_id (&tmp_fp, dst_type)) != NULL)
+               if (vlen == LCTF_INFO_VLEN (tmp_fp, dst_tp->ctt_info))
+                 return tmp;
+           }
+         else
+           return tmp;
        }
     }