libctf: dump CTF array dimensions in the right order

Before GCC PR114186, all looked good in the land of
multidimensional arrays: you wrote

int a[5][10];

and ctf_type_aname() et al would print it as

int [5][10]

Unfortunately this was two bugs in one. GCC was emitting the array as if
it were int a[10][5], i.e. as this:

a -> [10] -> [5] -> int

rather than

a -> [5] -> [10] -> int

as it should be. libctf was hiding this by printing them in the wrong
order, concealing the bug from anyone using objdump --ctf or anything
but actual type graph traversal. Once this was fixed for GCC, the bug
was visible in libctf: multidimensional arrays were printed backwards!
(But this is just a print-time bug: the underlying bug, that something
traversing the type graph would see the array in backwards order, was
fixed by the fix to GCC.)

Fix this libctf bug, printing the arrays the right way round. In a
possibly futile attempt to retain some vestige of backwards
compatibility, introduce a new bug-compat flag CTF_F_ARRNELEMS, which,
if on, indicates that PR114186 is fixed and GCC is emitting array
elements the right way round. (Unfortunately, the fix went in without
this flag, so some GCCs will still emit CTF that will cause libctf to
print them wrong, even with this fix -- but it's no wronger than it was
before, and new GCC and new binutils, as well as GCC older than any fix
for PR114186 and new binutils, will print things properly. Someone
traversing the type graph will see things right after the GCC fix, wrong
before it, and there isn't really any reliable way to tell which you
have, though if CTF_F_ARRNELEMS is set, you definitely have a fixed GCC.
The test checks for this, but it's not something we expect actual users
to ever do -- CTF dict flags are an internal implementation detail with
no user-visible API for a reason.)

[nca: log message, test compat with older compilers]

include/
	* ctf.h (CTF_F_ARRNELEMS): New bug-compat flag.
	(CTF_F_MAX): Adjust.

libctf/
	PR libctf/32161
	* ctf-decl.c (ctf_decl_push): Prepend if this is an array and
	the bug-compat flag is set.
	* ctf-dump.c (ctf_dump_header): Dump the new bug-compat flag.
	* testsuite/libctf-lookup/multidim-array*: New test.
6 files changed