From: Simon Marchi Date: Sat, 28 Feb 2026 03:51:52 +0000 (-0500) Subject: gdb/ctf: check return value of ctf_type_align X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52d71bb277d56a85d53c45f3c3b212f89da2f552;p=thirdparty%2Fbinutils-gdb.git gdb/ctf: check return value of ctf_type_align 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 --- diff --git a/gdb/ctfread.c b/gdb/ctfread.c index c8457a70cf4..ed4a7383427 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -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); }