mbox series

[dwarves,v2,0/2] generate BTF_KIND_TAG types from DW_TAG_LLVM_annotation dwarf tags

Message ID 20210922021321.2286360-1-yhs@fb.com (mailing list archive)
Headers show
Series generate BTF_KIND_TAG types from DW_TAG_LLVM_annotation dwarf tags | expand

Message

Yonghong Song Sept. 22, 2021, 2:13 a.m. UTC
LLVM has implemented btf_tag attribute ([1]) which intended
to provide a "string" tag for struct/union or its member, var,
a func or its parameter. Such a "string" tag will be encoded
in dwarf. For non-BPF target like x86_64, pahole needs to
convert those dwarf btf_tag annotations to BTF so kernel
can utilize these "string" tags for bpf program verification, etc.
        
Patch 1 enhanced dwarf_loader to encode DW_TAG_LLVM_annotation
tags into internal data structure and Patch 2 will encode
such information to BTF with BTF_KIND_TAGs.

 [1] https://reviews.llvm.org/D106614

Changelog:
  v1 -> v2:
    - handle returning error cases for btf_encoder__add_tag().

Yonghong Song (2):
  dwarf_loader: parse dwarf tag DW_TAG_LLVM_annotation
  btf_encoder: generate BTF_KIND_TAG from llvm annotations

 btf_encoder.c  | 63 ++++++++++++++++++++++++++++++++++++-
 dwarf_loader.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++----
 dwarves.h      | 10 ++++++
 pahole.c       |  8 +++++
 4 files changed, 159 insertions(+), 7 deletions(-)

Comments

Arnaldo Carvalho de Melo Sept. 27, 2021, 8:40 p.m. UTC | #1
Em Tue, Sep 21, 2021 at 07:13:21PM -0700, Yonghong Song escreveu:
> LLVM has implemented btf_tag attribute ([1]) which intended
> to provide a "string" tag for struct/union or its member, var,
> a func or its parameter. Such a "string" tag will be encoded
> in dwarf. For non-BPF target like x86_64, pahole needs to
> convert those dwarf btf_tag annotations to BTF so kernel
> can utilize these "string" tags for bpf program verification, etc.
>         
> Patch 1 enhanced dwarf_loader to encode DW_TAG_LLVM_annotation
> tags into internal data structure and Patch 2 will encode
> such information to BTF with BTF_KIND_TAGs.
> 
>  [1] https://reviews.llvm.org/D106614

Applied both locally, now building HEAD llvm/clang to test everything,

- Arnaldo
 
> Changelog:
>   v1 -> v2:
>     - handle returning error cases for btf_encoder__add_tag().
> 
> Yonghong Song (2):
>   dwarf_loader: parse dwarf tag DW_TAG_LLVM_annotation
>   btf_encoder: generate BTF_KIND_TAG from llvm annotations
> 
>  btf_encoder.c  | 63 ++++++++++++++++++++++++++++++++++++-
>  dwarf_loader.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++----
>  dwarves.h      | 10 ++++++
>  pahole.c       |  8 +++++
>  4 files changed, 159 insertions(+), 7 deletions(-)
> 
> -- 
> 2.30.2
Arnaldo Carvalho de Melo Sept. 27, 2021, 8:59 p.m. UTC | #2
Em Mon, Sep 27, 2021 at 05:40:09PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Tue, Sep 21, 2021 at 07:13:21PM -0700, Yonghong Song escreveu:
> > LLVM has implemented btf_tag attribute ([1]) which intended
> > to provide a "string" tag for struct/union or its member, var,
> > a func or its parameter. Such a "string" tag will be encoded
> > in dwarf. For non-BPF target like x86_64, pahole needs to
> > convert those dwarf btf_tag annotations to BTF so kernel
> > can utilize these "string" tags for bpf program verification, etc.
> >         
> > Patch 1 enhanced dwarf_loader to encode DW_TAG_LLVM_annotation
> > tags into internal data structure and Patch 2 will encode
> > such information to BTF with BTF_KIND_TAGs.
> > 
> >  [1] https://reviews.llvm.org/D106614
> 
> Applied both locally, now building HEAD llvm/clang to test everything,

⬢[acme@toolbox pahole]$ pahole -JV t.o
Found per-CPU symbol 'g' at address 0x0
Found 1 per-CPU variables!
Found 1 functions!
File t.o:
[1] INT int size=4 nr_bits=32 encoding=SIGNED
[2] PTR (anon) type_id=3
[3] STRUCT t size=8
	a type_id=1 bitfield_size=1 bits_offset=0
	b type_id=1 bitfield_size=0 bits_offset=32
[4] TAG tag1 type_id=3 component_idx=0
[5] TAG tag2 type_id=3 component_idx=1
[6] TAG tag1 type_id=3 component_idx=-1
[7] TAG tag2 type_id=3 component_idx=-1
[8] FUNC_PROTO (anon) return=1 args=(2 a1, 1 a2)
[9] FUNC foo type_id=8
[10] TAG tag2 type_id=9 component_idx=1
[11] TAG tag1 type_id=9 component_idx=-1
search cu 't.c' for percpu global variables.
Variable 'g' from CU 't.c' at address 0x0 encoded
[12] VAR g type=1 linkage=1
[13] TAG tag1 type_id=12 component_idx=-1
[14] DATASEC .data..percpu size=4 vlen=1
	type=12 offset=0 size=4
⬢[acme@toolbox pahole]$ pahole -JV --skip_encoding_btf_tag t.o
Found per-CPU symbol 'g' at address 0x0
Found 1 per-CPU variables!
Found 1 functions!
File t.o:
[1] INT int size=4 nr_bits=32 encoding=SIGNED
[2] PTR (anon) type_id=3
[3] STRUCT t size=8
	a type_id=1 bitfield_size=1 bits_offset=0
	b type_id=1 bitfield_size=0 bits_offset=32
[4] FUNC_PROTO (anon) return=1 args=(2 a1, 1 a2)
[5] FUNC foo type_id=4
search cu 't.c' for percpu global variables.
Variable 'g' from CU 't.c' at address 0x0 encoded
[6] VAR g type=1 linkage=1
[7] DATASEC .data..percpu size=4 vlen=1
	type=6 offset=0 size=4
⬢[acme@toolbox pahole]$ clang -v
clang version 14.0.0 (https://github.com/llvm/llvm-project f7e82e4fa849376ea9226220847a098dc92d74a0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/11
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/11
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
⬢[acme@toolbox pahole]$

And the usual:

⬢[acme@toolbox pahole]$ pahole -J vmlinux
⬢[acme@toolbox pahole]$ btfdiff vmlinux
⬢[acme@toolbox pahole]$

So applied, pushing out to the tmp.master branch so that libbpf's CI can
have a go at it, then after the next run I'll push to master, thanks!

- Arnaldo