aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce McCulloch <bruce.mcculloch@oracle.com>2026-02-05 12:50:28 -0800
committerNick Alcock <nick.alcock@oracle.com>2026-02-27 15:06:41 +0000
commit2af278f1235c13065cab88b135878bc144d41e6e (patch)
tree44c7ba4036db5dc82fc89d9438e968bb4939f70f
parent54098e34724fef2ce77f142f81b3015f4a1774b1 (diff)
downloadgdb-master.zip
gdb-master.tar.gz
gdb-master.tar.bz2
libctf: remove CTF_F_ARRNELEMS flagHEADmaster
This patch removes the constraint that a CTF_F_ARRNELEMS flag has to be present in order to reverse the elements of an array when dumping. The flag was never added to GCC, and having this requirement causes more problems than it solves. A quick recap of the issue: Given an array int foo[1][2][3], the expected graph is: int foo[1][2][3] -> int foo[2][3] -> int foo[3] -> int foo Prior to GCC PR114186, the emitted graph would be: int foo[1][2][3] -> int foo[1][2] -> int foo[1] -> int foo Following GCC PR114186, before the libctf fix, the output was: int foo[3][2][1] -> int foo[3][2] -> int foo[3] -> int foo So the underlying type graph was correct, but the ordering of elements was incorrect. With this fix, we emit correct ordering of the type graph, with no requirements for the compiler to signal that it has GCC PR114186. include/ * ctf.h (CTF_F_ARRNELEMS): Delete. (CTF_F_MAX): Adjust. libctf/ * ctf-decl.c (ctf_decl_push): Act as if CTF_F_ARRNELEMS is always set. * ctf-dump.c (ctf_dump_header): No longer dump its value. * testsuite/libctf-lookup/multidim-array.c: No longer detect compilers not emitting this flag (none do).
-rw-r--r--include/ctf.h3
-rw-r--r--libctf/ctf-decl.c3
-rw-r--r--libctf/ctf-dump.c8
-rw-r--r--libctf/testsuite/libctf-lookup/multidim-array.c82
4 files changed, 7 insertions, 89 deletions
diff --git a/include/ctf.h b/include/ctf.h
index 29f281d..e28a37d 100644
--- a/include/ctf.h
+++ b/include/ctf.h
@@ -213,9 +213,8 @@ typedef struct ctf_header
#define CTF_F_NEWFUNCINFO 0x2 /* New v3 func info section format. */
#define CTF_F_IDXSORTED 0x4 /* Index sections already sorted. */
#define CTF_F_DYNSTR 0x8 /* Strings come from .dynstr. */
-#define CTF_F_ARRNELEMS 0x10 /* Array elems no longer reversed. */
#define CTF_F_MAX (CTF_F_COMPRESS | CTF_F_NEWFUNCINFO | CTF_F_IDXSORTED \
- | CTF_F_DYNSTR | CTF_F_ARRNELEMS)
+ | CTF_F_DYNSTR)
typedef struct ctf_lblent
{
diff --git a/libctf/ctf-decl.c b/libctf/ctf-decl.c
index 59dfaef..e25935a 100644
--- a/libctf/ctf-decl.c
+++ b/libctf/ctf-decl.c
@@ -158,8 +158,7 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
As of gcc-14.2.0, arrays must also be prepended in order to dump with the
dimensions properly ordered. */
- if ((is_qual && prec == CTF_PREC_BASE) || ((kind == CTF_K_ARRAY) &&
- (fp->ctf_openflags & (CTF_F_ARRNELEMS))))
+ if ((is_qual && prec == CTF_PREC_BASE) || (kind == CTF_K_ARRAY))
ctf_list_prepend (&cd->cd_nodes[prec], cdp);
else
ctf_list_append (&cd->cd_nodes[prec], cdp);
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 561d17f..0037cc5 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -326,7 +326,7 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
if (fp->ctf_openflags > 0)
{
- if (asprintf (&flagstr, "%s%s%s%s%s%s%s%s%s",
+ if (asprintf (&flagstr, "%s%s%s%s%s%s%s",
fp->ctf_openflags & CTF_F_COMPRESS
? "CTF_F_COMPRESS": "",
(fp->ctf_openflags & CTF_F_COMPRESS)
@@ -343,12 +343,6 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
&& (fp->ctf_openflags & ~(CTF_F_COMPRESS | CTF_F_NEWFUNCINFO
| CTF_F_IDXSORTED))
? ", " : "",
- fp->ctf_openflags & CTF_F_ARRNELEMS
- ? "CTF_F_ARRNELEMS" : "",
- fp->ctf_openflags & (CTF_F_ARRNELEMS)
- && (fp->ctf_openflags & ~(CTF_F_COMPRESS | CTF_F_NEWFUNCINFO
- | CTF_F_IDXSORTED | CTF_F_ARRNELEMS))
- ? ", " : "",
fp->ctf_openflags & CTF_F_DYNSTR
? "CTF_F_DYNSTR" : "") < 0)
goto err;
diff --git a/libctf/testsuite/libctf-lookup/multidim-array.c b/libctf/testsuite/libctf-lookup/multidim-array.c
index 9e0cc2e..790efc8 100644
--- a/libctf/testsuite/libctf-lookup/multidim-array.c
+++ b/libctf/testsuite/libctf-lookup/multidim-array.c
@@ -4,92 +4,24 @@
#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[])
{
ctf_archive_t *ctf;
ctf_dict_t *fp;
int err;
- ctf_dump_state_t *dump_state = NULL;
- char *dumpstr;
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;
if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL)
goto open_err;
- /* 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)
- {
- if (strstr (dumpstr, "CTF_F_ARRNELEMS") != NULL)
- flagged = 1;
- free (dumpstr);
- }
-
- if (!flagged)
- {
- ctf_arinfo_t ar;
-
- if ((type = ctf_lookup_by_symbol_name (fp, "a")) == CTF_ERR)
- goto unexpected;
-
- if (ctf_array_info (fp, type, &ar) < 0)
- goto unexpected;
-
- if (ar.ctr_nelems == 3)
- {
- fprintf (stderr, "UNSUPPORTED: compiler has GCC PR114186 fixed but "
- "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));
- }
-
- 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);
- }
- }
+ /* This is expected to fail with GCC prior to PR114186. */
+ 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));
ctf_dict_close (fp);
ctf_close (ctf);
@@ -99,10 +31,4 @@ main (int argc, char *argv[])
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",
- ctf_errmsg (ctf_errno (fp)));
- return 1;
}