ctf_dump_objts output string

Alan Modra amodra@gmail.com
Fri Jan 30 21:19:27 GMT 2026


"Section is indexed" and "No symbol table" are generated at the
beginning of ctf_dump_objts but not output, resulting in an asan
complaint about leaked memory.  Clearly the messages should either not
be generated, or they should be output.

I chose to do the latter in this patch.  I'll happily jump the other
way if you'd prefer, Nick.

diff --git a/ld/testsuite/ld-ctf/data-func-conflicted-vars.d b/ld/testsuite/ld-ctf/data-func-conflicted-vars.d
index 4e570c6a61a..e2bd077cf9e 100644
--- a/ld/testsuite/ld-ctf/data-func-conflicted-vars.d
+++ b/ld/testsuite/ld-ctf/data-func-conflicted-vars.d
@@ -22,6 +22,7 @@ Contents of CTF section \.ctf:
     String section:	.*
 #...
   Data objects:
+    Section is indexed.
     bar -> 0x[0-9a-f]*: \(kind 6\) struct var_3 \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
     var_1 -> 0x[0-9a-f]*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
     var_666 -> 0x[0-9a-f]*: \(kind 3\) foo_t \* \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
diff --git a/ld/testsuite/ld-ctf/data-func-conflicted.d b/ld/testsuite/ld-ctf/data-func-conflicted.d
index b0db511a987..188a4361a5c 100644
--- a/ld/testsuite/ld-ctf/data-func-conflicted.d
+++ b/ld/testsuite/ld-ctf/data-func-conflicted.d
@@ -21,6 +21,7 @@ Contents of CTF section \.ctf:
     String section:	.*
 #...
   Data objects:
+    Section is indexed.
     bar -> 0x[0-9a-f]*: \(kind 6\) struct var_3 \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
     var_1 -> 0x[0-9a-f]*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
     var_666 -> 0x[0-9a-f]*: \(kind 3\) foo_t \* \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 3fd8cb87f9f..410b6f67cc1 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -445,11 +445,12 @@ ctf_dump_objts (ctf_dict_t *fp, ctf_dump_state_t *state, int functions)
   ctf_next_t *i = NULL;
   char *str = NULL;
 
-  if ((functions && fp->ctf_funcidx_names)
-      || (!functions && fp->ctf_objtidx_names))
+  if (functions ? fp->ctf_funcidx_names : fp->ctf_objtidx_names)
     str = str_append (str, _("Section is indexed.\n"));
   else if (fp->ctf_ext_symtab.cts_data == NULL)
     str = str_append (str, _("No symbol table.\n"));
+  if (str)
+    ctf_dump_append (state, str);
 
   while ((id = ctf_symbol_next (fp, &i, &name, functions)) != CTF_ERR)
     {

-- 
Alan Modra


More information about the Binutils mailing list