Re: BTF type tag not emitted to BTF in some cases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 15, 2022 at 09:18:45PM IST, Yonghong Song wrote:
>
>
> On 2/10/22 4:31 PM, Yonghong Song wrote:
> >
> >
> > On 2/10/22 3:24 PM, Kumar Kartikeya Dwivedi wrote:
> > > Hello,
> > >
> > > I was trying to use BTF type tags, but I noticed that when I apply
> > > it to a
> > > non-builtin type, it isn't emitted in the 'PTR' -> 'TYPE_TAG' ->
> > > <TYPE> chain.
> > >
> > > Consider the following two cases:
> > >
> > >   ; cat tag_good.c
> > > #define __btf_id __attribute__((btf_type_tag("btf_id")))
> > > #define __ref    __attribute__((btf_type_tag("ref")))
> > >
> > > struct map_value {
> > >          long __btf_id __ref *ptr;
> > > };
> > >
> > > void func(struct map_value *, long *);
> > >
> > > int main(void)
> > > {
> > >          struct map_value v = {};
> > >
> > >          func(&v, v.ptr);
> > > }
> > >
> > > ; cat tag_bad.c
> > > #define __btf_id __attribute__((btf_type_tag("btf_id")))
> > > #define __ref    __attribute__((btf_type_tag("ref")))
> > >
> > > struct foo {
> > >          int i;
> > > };
> > >
> > > struct map_value {
> > >          struct foo __btf_id __ref *ptr;
> > > };
> > >
> > > void func(struct map_value *, struct foo *);
> > >
> > > int main(void)
> > > {
> > >          struct map_value v = {};
> > >
> > >          func(&v, v.ptr);
> > > }
> > >
> > > --
> > >
> > > In the first case, it is applied to a long, in the second, it is
> > > applied to
> > > struct foo.
> > >
> > > For the first case, we see:
> > >
> > > [1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
> > > [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
> > > [3] FUNC 'main' type_id=1 linkage=global
> > > [4] FUNC_PROTO '(anon)' ret_type_id=0 vlen=2
> > >          '(anon)' type_id=5
> > >          '(anon)' type_id=11
> > > [5] PTR '(anon)' type_id=6
> > > [6] STRUCT 'map_value' size=8 vlen=1
> > >          'ptr' type_id=9 bits_offset=0
> > > [7] TYPE_TAG 'btf_id' type_id=10
> > > [8] TYPE_TAG 'ref' type_id=7
> > > [9] PTR '(anon)' type_id=8
> > > [10] INT 'long' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED
> > > [11] PTR '(anon)' type_id=10
> > > [12] FUNC 'func' type_id=4 linkage=extern
> > >
> > > For the second, there is no TYPE_TAG:
> > >
> > >   ; ../linux/tools/bpf/bpftool/bpftool btf dump file tag_bad.o
> > > [1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
> > > [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
> > > [3] FUNC 'main' type_id=1 linkage=global
> > > [4] FUNC_PROTO '(anon)' ret_type_id=0 vlen=2
> > >          '(anon)' type_id=5
> > >          '(anon)' type_id=8
> > > [5] PTR '(anon)' type_id=6
> > > [6] STRUCT 'map_value' size=8 vlen=1
> > >          'ptr' type_id=7 bits_offset=0
> > > [7] PTR '(anon)' type_id=9
> > > [8] PTR '(anon)' type_id=9
> > > [9] STRUCT 'foo' size=4 vlen=1
> > >          'i' type_id=2 bits_offset=0
> > > [10] FUNC 'func' type_id=4 linkage=extern
> > >
> > > --
> > >
> > > Is there anything I am missing here? When I do llvm-dwarfdump for
> > > both, I see
> > > that the tag annotation is present for both:
> >
> > Thanks for trying and reporting! This should be a llvm bpf backend bug.
> > Will fix it soon.
>
> The issue is fixed in https://reviews.llvm.org/D119799 and
> the patch is merged in llvm-project main branch.
> Could you take a look again? Thanks!
>

Thanks for the quick fix Yonghong! I tested it out and it seems to work fine
now. Thanks a lot!

> >
> > >
> > > For the good case:
> > >
> > > 0x00000067:   DW_TAG_pointer_type
> > >                  DW_AT_type      (0x00000073 "long")
> > >
> > > 0x0000006c:     DW_TAG_unknown_6000
> > >                    DW_AT_name    ("btf_type_tag")
> > >                    DW_AT_const_value     ("btf_id")
> >
> > BTW, if you use the same llvm-dwarfdump from 15.0.0,
> > $ llvm-dwarfdump --version
> > LLVM (http://llvm.org/ ):
> >    LLVM version 15.0.0git
> >    Optimized build with assertions.
> >    Default target: x86_64-unknown-linux-gnu
> >    Host CPU: skylake-avx512
> >
> > You should see
> > 0x0000006c:     DW_TAG_LLVM_annotation
> >                    DW_AT_name    ("btf_type_tag")
> >                    DW_AT_const_value     ("btf_id")
> >
> > instead of
> >          DW_TAG_unknown_6000
> >
> > >
> > > 0x0000006f:     DW_TAG_unknown_6000
> > >                    DW_AT_name    ("btf_type_tag")
> > >                    DW_AT_const_value     ("ref")
> > >
> > > For the bad case:
> > >
> > > 0x00000067:   DW_TAG_pointer_type
> > >                  DW_AT_type      (0x00000073 "foo")
> > >
> > > 0x0000006c:     DW_TAG_unknown_6000
> > >                    DW_AT_name    ("btf_type_tag")
> > >                    DW_AT_const_value     ("btf_id")
> > >
> > > 0x0000006f:     DW_TAG_unknown_6000
> > >                    DW_AT_name    ("btf_type_tag")
> > >                    DW_AT_const_value     ("ref")
> > >
> > > My clang version is a very recent compile:
> > > clang version 15.0.0 (https://github.com/llvm/llvm-project.git
> > > 9e08e9298059651e4f42eb608c3de9d4ad8004b2)
> > >
> > > Thanks
> > > --
> > > Kartikeya

--
Kartikeya



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux