fprintf: Fixup multi-dimensional zero sized arrays const handling

Before:

  $ pahole -C piix_map_db /home/acme/git/build/v5.1-rc4+/drivers/ata/ata_piix.o
  struct piix_map_db {
  	const u32                  mask;                 /*     0     4 */
  	const u16                  port_enable;          /*     4     2 */

  	/* XXX 2 bytes hole, try to pack */

  	const const int            map[][4];             /*     8     0 */

  	/* size: 8, cachelines: 1, members: 3 */
  	/* sum members: 6, holes: 1, sum holes: 2 */
  	/* last cacheline: 8 bytes */
  };
  $

After:

  $ pahole -C piix_map_db /home/acme/git/build/v5.1-rc4+/drivers/ata/ata_piix.o
  struct piix_map_db {
  	const u32                  mask;                 /*     0     4 */
  	const u16                  port_enable;          /*     4     2 */

  	/* XXX 2 bytes hole, try to pack */

  	const int                  map[][4];             /*     8     0 */

  	/* size: 8, cachelines: 1, members: 3 */
  	/* sum members: 6, holes: 1, sum holes: 2 */
  	/* last cacheline: 8 bytes */
  };
  $

The DWARF tag sequence:

 <2><17e50>: Abbrev Number: 12 (DW_TAG_member)
    <17e51>   DW_AT_name        : map
    <17e55>   DW_AT_decl_file   : 1
    <17e56>   DW_AT_decl_line   : 160
    <17e57>   DW_AT_decl_column : 12
    <17e58>   DW_AT_type        : <0x17e78>
    <17e5c>   DW_AT_data_member_location: 8

 <1><17e78>: Abbrev Number: 15 (DW_TAG_const_type)
    <17e79>   DW_AT_type        : <0x17e63>

 <1><17e63>: Abbrev Number: 11 (DW_TAG_array_type)
    <17e64>   DW_AT_type        : <0xd8>

 <1><d8>: Abbrev Number: 15 (DW_TAG_const_type)
    <d9>   DW_AT_type        : <0xd1>

 <1><d1>: Abbrev Number: 120 (DW_TAG_base_type)
    <d2>   DW_AT_byte_size   : 4
    <d3>   DW_AT_encoding    : 5        (signed)
    <d4>   DW_AT_name        : int

  const -> array -> const -> int

So just make the check be at least one dimension, if the number of
elements is zero, then drop the double const.

With this btfdiff for the allyesconfig ppc64 reference kernel we're
using is again clean.

  $ pahole -F btf --sizes examples/vmlinux-aarch64 | wc -l
  51023
  $

> 50K types with output from BTF and DWARF matching.

Fixes: ccd67bdb205b ("fprintf: Print "const" for class members more early, in type__fprintf()")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 file changed