btf_loader: A hack for BTF import of btf_type_tag attributes

Pahole does not print type names correctly for the following example,
when BTF loader is used:

    #define __tag1 __attribute__((btf_type_tag("tag1")))

    struct st {
      int __tag1 *a;
    } g;

Here is the pahole output:

    $ clang -target bpf -g -c test.c -o test.o
    $ pahole -F btf test.o
    BTF: idx: 2, Unknown kind 18
    struct st {
    	<ERROR                    > a;                   /*     0     8 */
        ...
    };

Note the type name for field `a`.

This commit adds a workaround for this issue: it creates a tag
instance with tag->tag set to `DW_TAG_LLVM_annotation` and `tag->type`
pointing to the type wrapped by `BTF_KIND_TYPE_TAG`, `int` for the
example above.

Note that this is not a complete replication of behavior of DWARF
loader. When DWARF is processed type tag instances are added to the
annotations list of the parent pointer type. However, this is
sufficient to fix the printing issue and helps with `btfdiff` script.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Faust <david.faust@oracle.com>
Cc: Jose Marchesi <jose.marchesi@oracle.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Link: https://lore.kernel.org/r/20230314230417.1507266-2-eddyz87@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 file changed