]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/ctf: check return value of ctf_type_align
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 28 Feb 2026 03:51:52 +0000 (22:51 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 9 Mar 2026 19:00:03 +0000 (15:00 -0400)
I tried to build the Linux kernel with -gctf.  I am not sure if the
result is good, because I got plenty of warnings like:

    ld: warning: orphan section `.ctf' from `vmlinux.o' being placed in section `.ctf'

Nevertheless, I tried to load it in GDB, and it didn't complain.
However, when doing "maint expand-symtabs", I did hit this assert:

    /home/simark/src/binutils-gdb/gdb/gdbtypes.c:3640: internal-error: set_type_align: Assertion `(align & (align - 1)) == 0' failed.

This is because ctf_type_align returns -1 for some types, which is an
indication of an error.  Update the code to check the return value of
ctf_type_align for errors, and emit complaints if it happens.

With this patch, if I enable the complaints, I see a bunch of messages
like this:

    During symbol reading: ctf_type_align read_structure_type failed - Type is not a complete type.

Change-Id: Ibed23e7f1490d9163b8dde1318b9e45dec2906d6
Approved-By: Tom Tromey <tom@tromey.com>
gdb/ctfread.c

index c8457a70cf46ebbe9e43ecc0362d3fb453b3adbf..ed4a7383427d04fd1a19e68a53e1a2be8c0ccdb1 100644 (file)
@@ -616,7 +616,14 @@ read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
     type->set_code (TYPE_CODE_STRUCT);
 
   type->set_length (ctf_type_size (dict, tid));
-  set_type_align (type, ctf_type_align (dict, tid));
+
+  if (ssize_t align = ctf_type_align (dict, tid);
+      align >= 0)
+    set_type_align (type, align);
+  else
+    complaint (_("ctf_type_align read_structure_type failed - %s"),
+              ctf_errmsg (ctf_errno (dict)));
+
 
   return set_tid_type (objfile, tid, type);
 }
@@ -673,7 +680,13 @@ read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
     }
   rettype = fetch_tid_type (ccp, cfi.ctc_return);
   type->set_target_type (rettype);
-  set_type_align (type, ctf_type_align (dict, tid));
+
+  if (ssize_t align = ctf_type_align (dict, tid);
+      align >= 0)
+    set_type_align (type, align);
+  else
+    complaint (_("ctf_type_align read_func_kind_type failed - %s"),
+              ctf_errmsg (ctf_errno (dict)));
 
   /* Set up function's arguments.  */
   argc = cfi.ctc_argc;
@@ -723,7 +736,13 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
   type->set_length (ctf_type_size (dict, tid));
   /* Set the underlying type based on its ctf_type_size bits.  */
   type->set_target_type (objfile_int_type (objfile, type->length (), false));
-  set_type_align (type, ctf_type_align (dict, tid));
+
+  if (ssize_t align = ctf_type_align (dict, tid);
+      align >= 0)
+    set_type_align (type, align);
+  else
+    complaint (_("ctf_type_align read_enum_type failed - %s"),
+              ctf_errmsg (ctf_errno (dict)));
 
   return set_tid_type (objfile, tid, type);
 }
@@ -814,7 +833,12 @@ read_array_type (struct ctf_context *ccp, ctf_id_t tid)
   else
     type->set_length (ctf_type_size (dict, tid));
 
-  set_type_align (type, ctf_type_align (dict, tid));
+  if (ssize_t align = ctf_type_align (dict, tid);
+      align >= 0)
+    set_type_align (type, align);
+  else
+    complaint (_("ctf_type_align read_array_type failed - %s"),
+              ctf_errmsg (ctf_errno (dict)));
 
   return set_tid_type (objfile, tid, type);
 }
@@ -936,7 +960,13 @@ read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
     }
 
   type = lookup_pointer_type (target_type);
-  set_type_align (type, ctf_type_align (ccp->dict, tid));
+
+  if (ssize_t align = ctf_type_align (ccp->dict, tid);
+      align >= 0)
+    set_type_align (type, align);
+  else
+    complaint (_("ctf_type_align read_pointer_type failed - %s"),
+              ctf_errmsg (ctf_errno (ccp->dict)));
 
   return set_tid_type (objfile, tid, type);
 }