* BTF type tag not emitted to BTF in some cases
@ 2022-02-10 23:24 Kumar Kartikeya Dwivedi
2022-02-11 0:31 ` Yonghong Song
0 siblings, 1 reply; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2022-02-10 23:24 UTC (permalink / raw)
To: bpf; +Cc: Yonghong Song
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:
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")
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BTF type tag not emitted to BTF in some cases
2022-02-10 23:24 BTF type tag not emitted to BTF in some cases Kumar Kartikeya Dwivedi
@ 2022-02-11 0:31 ` Yonghong Song
2022-02-15 15:48 ` Yonghong Song
0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2022-02-11 0:31 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi, bpf
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.
>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BTF type tag not emitted to BTF in some cases
2022-02-11 0:31 ` Yonghong Song
@ 2022-02-15 15:48 ` Yonghong Song
2022-02-15 20:32 ` Kumar Kartikeya Dwivedi
0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2022-02-15 15:48 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi, bpf
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!
>
>>
>> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BTF type tag not emitted to BTF in some cases
2022-02-15 15:48 ` Yonghong Song
@ 2022-02-15 20:32 ` Kumar Kartikeya Dwivedi
0 siblings, 0 replies; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2022-02-15 20:32 UTC (permalink / raw)
To: Yonghong Song; +Cc: bpf
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-15 20:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 23:24 BTF type tag not emitted to BTF in some cases Kumar Kartikeya Dwivedi
2022-02-11 0:31 ` Yonghong Song
2022-02-15 15:48 ` Yonghong Song
2022-02-15 20:32 ` Kumar Kartikeya Dwivedi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.