[PATCH 1/3] libctf: fix libctf/testsuite/libctf-lookup/multidim-array on older arches

Nick Alcock nick.alcock@oracle.com
Sun Oct 19 16:21:21 GMT 2025
From: Bruce McCulloch <bruce.mcculloch@oracle.com>

This patch inverts the ordering of nelems on multidimensional arrays on
versions of gcc without the CTF_F_ARRNELEMS flag. This allows those
systems which run older gcc to pass the test without modification to the
multidim-array.lk file.

libctf/ChangeLog:

	* testsuite/libctf-lookup/multidim-array.c: Test fixes.
---
 .../libctf-lookup/multidim-array-ctf.c        |  1 -
 .../testsuite/libctf-lookup/multidim-array.c  | 55 ++++++++++++++++---
 .../testsuite/libctf-lookup/multidim-array.lk |  4 --
 3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/libctf/testsuite/libctf-lookup/multidim-array-ctf.c b/libctf/testsuite/libctf-lookup/multidim-array-ctf.c
index 05b6ebe4fdd..3829fda9582 100644
--- a/libctf/testsuite/libctf-lookup/multidim-array-ctf.c
+++ b/libctf/testsuite/libctf-lookup/multidim-array-ctf.c
@@ -1,3 +1,2 @@
 int a[3][5][9];
-int b[1][2];
 
diff --git a/libctf/testsuite/libctf-lookup/multidim-array.c b/libctf/testsuite/libctf-lookup/multidim-array.c
index 2a86f2636c2..9e0cc2e99be 100644
--- a/libctf/testsuite/libctf-lookup/multidim-array.c
+++ b/libctf/testsuite/libctf-lookup/multidim-array.c
@@ -1,8 +1,23 @@
+#include "config.h"
 #include <ctf-api.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+static char *
+insert_dimension (char *old_str, int num)
+{
+  char *bracket_ptr = strchr (old_str, '[');
+  if (!bracket_ptr)
+    {
+      if (asprintf (&old_str, "int [%d]", num) < 0)
+	return NULL;
+    }
+  else if (asprintf (&old_str, "int [%d]%s", num, bracket_ptr) < 0)
+    return NULL;
+  return old_str;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -14,6 +29,7 @@ main (int argc, char *argv[])
   ctf_next_t *it = NULL;
   ctf_id_t type;
   int flagged = 0;
+  const char *name = NULL;
 
   if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
     goto open_err;
@@ -23,8 +39,8 @@ main (int argc, char *argv[])
   /* First, check for signs that the compiler is fixed but not emitting the
      relevant flag yet.  This combination is not expected to work right.  */
 
-  while ((dumpstr = ctf_dump (fp, &dump_state, CTF_SECT_HEADER,
-			      NULL, NULL)) != NULL)
+  while ((dumpstr = ctf_dump (fp, &dump_state, CTF_SECT_HEADER, NULL, NULL))
+	 != NULL)
     {
       if (strstr (dumpstr, "CTF_F_ARRNELEMS") != NULL)
 	flagged = 1;
@@ -44,28 +60,49 @@ main (int argc, char *argv[])
       if (ar.ctr_nelems == 3)
 	{
 	  fprintf (stderr, "UNSUPPORTED: compiler has GCC PR114186 fixed but "
-		   "no indicative flag\n");
+			   "no indicative flag\n");
 	  return 0;
 	}
     }
 
   /* Now check for the actual bug.  */
+  if (flagged)
+    {
+      while ((type = ctf_type_next (fp, &it, NULL, 1)) != -1)
+	if (ctf_type_kind (fp, type) == CTF_K_ARRAY)
+	  printf ("%s\n", ctf_type_aname (fp, type));
+    }
 
-  while ((type = ctf_type_next (fp, &it, NULL, 1)) != -1)
-    printf ("%s\n", ctf_type_aname (fp, type));
+  else
+    {
+      while ((type = ctf_symbol_next (fp, &it, &name, 0)) != CTF_ERR)
+	{
+	  char *outstr = strdup ("int ");
+	  while (ctf_type_kind (fp, type) == CTF_K_ARRAY)
+	    {
+	      ctf_arinfo_t ar;
+	      if (ctf_array_info (fp, type, &ar) < 0)
+		goto unexpected;
+	      outstr = insert_dimension (outstr, ar.ctr_nelems);
+	      printf ("%s\n", outstr);
+	      type = ar.ctr_contents;
+	    }
+	  free (outstr);
+	}
+    }
 
   ctf_dict_close (fp);
   ctf_close (ctf);
 
   return 0;
 
- open_err:
+open_err:
   fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
   return 1;
 
- unexpected:
-  fprintf (stderr, "Cannot look up symbol to determine compiler bugginess: %s\n",
+unexpected:
+  fprintf (stderr,
+	   "Cannot look up symbol to determine compiler bugginess: %s\n",
 	   ctf_errmsg (ctf_errno (fp)));
   return 1;
 }
-
diff --git a/libctf/testsuite/libctf-lookup/multidim-array.lk b/libctf/testsuite/libctf-lookup/multidim-array.lk
index 41b3cd9f033..7d06042691b 100644
--- a/libctf/testsuite/libctf-lookup/multidim-array.lk
+++ b/libctf/testsuite/libctf-lookup/multidim-array.lk
@@ -1,9 +1,5 @@
 # source: multidim-array-ctf.c
-int
-(long )?unsigned int
 int \[9\]
 int \[5\]\[9\]
 int \[3\]\[5\]\[9\]
-int \[2\]
-int \[1\]\[2\]
 
-- 
2.51.0.284.g117bcb8de7



More information about the Binutils mailing list