[PATCH RESEND] Bugfix 32161 CTF array dimensions dumped backwards
Bruce McCulloch
bruce.mcculloch@oracle.com
Fri Nov 1 16:32:54 GMT 2024
More information about the Binutils mailing list
Fri Nov 1 16:32:54 GMT 2024
- Previous message (by thread): [PATCH v1] ld, LoongArch: print error about linking without -fPIC or -fPIE flag in more detail
- Next message (by thread): Support the Sortix operating system
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello All, This is a re-send of an old patch that fixes 32161 for CTF, in which the dimensions of multidimensional arrays were being output backwards. This is due to a longstanding issue in GCC, where the dimensions of multidimensional arrays were being reported in backwards order. As of 14.2, the GCC error has been corrected, but that leaves CTF being incorrect. This patch fixes the error by reversing the order in which the decl list is traversed when dealing with array dimension types. There is no additional overhead. Tests have also been included. Bruce McCulloch --- libctf/ChangeLog | 7 ++++ libctf/ctf-decl.c | 6 ++-- .../libctf-lookup/multidim-array-ctf.c | 2 ++ .../testsuite/libctf-lookup/multidim-array.c | 32 +++++++++++++++++++ .../testsuite/libctf-lookup/multidim-array.lk | 8 +++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 libctf/testsuite/libctf-lookup/multidim-array-ctf.c create mode 100644 libctf/testsuite/libctf-lookup/multidim-array.c create mode 100644 libctf/testsuite/libctf-lookup/multidim-array.lk diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 5c53be7ec7a..2f19ee8806a 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,10 @@ +2024-09-09 Bruce McCulloch <bruce.mcculloch@oracle.com> + + * ctf-decl.c (ctf_decl_push): print array dimensions in the right order. + * testsuite/libctf-lookup/multidim-array.lk: Add. + * testsuite/libctf-lookup/multidim-array.c: Add. + * testsuite/libctf-lookup/multidim-array-ctf.c: Add. + 2024-07-20 Nick Clifton <nickc@redhat.com> * 2.43 branch point. diff --git a/libctf/ctf-decl.c b/libctf/ctf-decl.c index 2fd4bde1864..772d337b1ee 100644 --- a/libctf/ctf-decl.c +++ b/libctf/ctf-decl.c @@ -154,9 +154,11 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type) cd->cd_qualp = prec; /* By convention qualifiers of base types precede the type specifier (e.g. - const int vs. int const) even though the two forms are equivalent. */ + const int vs. int const) even though the two forms are equivalent. + 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) + 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/testsuite/libctf-lookup/multidim-array-ctf.c b/libctf/testsuite/libctf-lookup/multidim-array-ctf.c new file mode 100644 index 00000000000..e450e8112bd --- /dev/null +++ b/libctf/testsuite/libctf-lookup/multidim-array-ctf.c @@ -0,0 +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 new file mode 100644 index 00000000000..825e86d07f3 --- /dev/null +++ b/libctf/testsuite/libctf-lookup/multidim-array.c @@ -0,0 +1,32 @@ +#include <ctf-api.h> +#include <stdio.h> +#include <stdlib.h> + +int +main (int argc, char *argv[]) +{ + ctf_archive_t *ctf; + ctf_dict_t *fp; + int err; + ctf_dump_state_t *state = NULL; + ctf_next_t *it = NULL; + ctf_id_t type; + + + if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) + goto open_err; + if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) + goto open_err; + + while ((type = ctf_type_next (fp, &it, NULL, 1)) != -1) + printf("%s\n", ctf_type_aname(fp, type)); + + ctf_dict_close (fp); + ctf_close (ctf); + + return 0; + + open_err: + fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); + return 1; +} \ No newline at end of file diff --git a/libctf/testsuite/libctf-lookup/multidim-array.lk b/libctf/testsuite/libctf-lookup/multidim-array.lk new file mode 100644 index 00000000000..344ab4f3294 --- /dev/null +++ b/libctf/testsuite/libctf-lookup/multidim-array.lk @@ -0,0 +1,8 @@ +# source: multidim-array-ctf.c +int +long unsigned int +int \[9\] +int \[5\]\[9\] +int \[3\]\[5\]\[9\] +int \[2\] +int \[1\]\[2\] \ No newline at end of file -- 2.43.5
- Previous message (by thread): [PATCH v1] ld, LoongArch: print error about linking without -fPIC or -fPIE flag in more detail
- Next message (by thread): Support the Sortix operating system
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list