dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation
@ 2021-11-02 23:35 Yonghong Song
  2021-11-02 23:35 ` [PATCH dwarves v2 1/2] dwarf_loader: " Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yonghong Song @ 2021-11-02 23:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, dwarves
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, Daniel Borkmann, kernel-team

Latest llvm is able to generate DW_TAG_LLVM_annotation for typedef
declarations. Latest bpf-next supports BTF_KIND_DECL_TAG for
typedef declarations. This patch implemented dwarf DW_TAG_LLVM_annotation
to btf BTF_KIND_DECL_TAG conversion. Patch 1 is for dwarf_loader
to process DW_TAG_LLVM_annotation tags. Patch 2 is for the
dwarf->btf conversion.

Changelog:
  v1 -> v2:
   - change some "if" statements to "switch" statement.

Yonghong Song (2):
  dwarf_loader: support typedef DW_TAG_LLVM_annotation
  btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag
    attributes

 btf_encoder.c  | 17 ++++++++++++++---
 dwarf_loader.c |  7 ++-----
 2 files changed, 16 insertions(+), 8 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH dwarves v2 1/2] dwarf_loader: support typedef DW_TAG_LLVM_annotation
  2021-11-02 23:35 [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Yonghong Song
@ 2021-11-02 23:35 ` Yonghong Song
  2021-11-02 23:35 ` [PATCH dwarves v2 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes Yonghong Song
  2021-11-03  0:11 ` [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Andrii Nakryiko
  2 siblings, 0 replies; 7+ messages in thread
From: Yonghong Song @ 2021-11-02 23:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, dwarves
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, Daniel Borkmann, kernel-team

llvm commit ([1]) added support for btf_decl_tag attribute
with typedef declaration. Eventually, DW_TAG_LLVM_annotation
tag may appear inside dwarf typedef declaration tag.

kernel support for typedef BTF_KIND_DECL_TAG support
is introduced in [2]. There is no additional libbpf
change needed as the previous libbpf BTF_KIND_DECL_TAG
support is generic enough to cover new typedef use
cases.

This patch added parsing of DW_TAG_LLVM_annotation
for dwarf typedef decl.

  $ cat t.c
  $ clang -O2 -g -c t.c
  $ llvm-dwarfdump --debug-info t.o
    ......
    0x00000033:   DW_TAG_typedef
                    DW_AT_type      (0x00000051 "structure ")
                    DW_AT_name      ("__t")
                    DW_AT_decl_file ("/home/yhs/t.c")
                    DW_AT_decl_line (3)

    0x0000003e:     DW_TAG_LLVM_annotation
                      DW_AT_name    ("btf_decl_tag")
                      DW_AT_const_value     ("tag1")

    0x00000047:     DW_TAG_LLVM_annotation
                      DW_AT_name    ("btf_decl_tag")
                      DW_AT_const_value     ("tag2")

    0x00000050:     NULL

Previously, pahole will issue a warning if typedef tag
contains any child tag. I removed this warning since
it is not true any more. Note that dwarf standard doesn't
prevent typedef decl tag from having nested tags.
In the future if we need to process any tag inside
typedef tag, we can just add code to process it.

  [1] https://reviews.llvm.org/D110127
  [2] https://lore.kernel.org/bpf/20211021195628.4018847-1-yhs@fb.com

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 dwarf_loader.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/dwarf_loader.c b/dwarf_loader.c
index c5bda81..f748bd7 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -1296,11 +1296,8 @@ static struct tag *die__create_new_typedef(Dwarf_Die *die, struct cu *cu, struct
 	if (tdef == NULL)
 		return NULL;
 
-	if (dwarf_haschildren(die)) {
-		struct dwarf_tag *dtag = tdef->namespace.tag.priv;
-		fprintf(stderr, "%s: DW_TAG_typedef %llx WITH children!\n",
-			__func__, (unsigned long long)dtag->id);
-	}
+	if (add_child_llvm_annotations(die, -1, conf, &tdef->namespace.annots))
+		return NULL;
 
 	return &tdef->namespace.tag;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH dwarves v2 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes
  2021-11-02 23:35 [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Yonghong Song
  2021-11-02 23:35 ` [PATCH dwarves v2 1/2] dwarf_loader: " Yonghong Song
@ 2021-11-02 23:35 ` Yonghong Song
  2021-11-03  0:11 ` [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Andrii Nakryiko
  2 siblings, 0 replies; 7+ messages in thread
From: Yonghong Song @ 2021-11-02 23:35 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, dwarves
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, Daniel Borkmann, kernel-team

Emit BTF BTF_KIND_DECL_TAGs for btf_decl_tag attributes attached to
typedef declarations. The following is a simple example:
  $ cat t.c
    #define __tag1 __attribute__((btf_decl_tag("tag1")))
    #define __tag2 __attribute__((btf_decl_tag("tag2")))
    typedef struct { int a; int b; } __t __tag1 __tag2;
    __t g;
  $ clang -O2 -g -c t.c
  $ pahole -JV t.o
    btf_encoder__new: 't.o' doesn't have '.data..percpu' section
    Found 0 per-CPU variables!
    File t.o:
    [1] TYPEDEF __t type_id=2
    [2] STRUCT (anon) size=8
            a type_id=3 bits_offset=0
            b type_id=3 bits_offset=32
    [3] INT int size=4 nr_bits=32 encoding=SIGNED
    [4] DECL_TAG tag1 type_id=1 component_idx=-1
    [5] DECL_TAG tag2 type_id=1 component_idx=-1

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 btf_encoder.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index 40f6aa3..117656e 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -1438,9 +1438,21 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 
 	cu__for_each_type(cu, core_id, pos) {
 		struct namespace *ns;
+		const char *tag_name;
 
-		if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type)
+		switch (pos->tag) {
+		case DW_TAG_structure_type:
+			tag_name = "struct";
+			break;
+		case DW_TAG_union_type:
+			tag_name = "union";
+			break;
+		case DW_TAG_typedef:
+			tag_name = "typedef";
+			break;
+		default:
 			continue;
+		}
 
 		btf_type_id = type_id_off + core_id;
 		ns = tag__namespace(pos);
@@ -1448,8 +1460,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu)
 			tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, btf_type_id, annot->component_idx);
 			if (tag_type_id < 0) {
 				fprintf(stderr, "error: failed to encode tag '%s' to %s '%s' with component_idx %d\n",
-					annot->value, pos->tag == DW_TAG_structure_type ? "struct" : "union",
-					namespace__name(ns), annot->component_idx);
+					annot->value, tag_name, namespace__name(ns), annot->component_idx);
 				goto out;
 			}
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation
  2021-11-02 23:35 [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Yonghong Song
  2021-11-02 23:35 ` [PATCH dwarves v2 1/2] dwarf_loader: " Yonghong Song
  2021-11-02 23:35 ` [PATCH dwarves v2 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes Yonghong Song
@ 2021-11-03  0:11 ` Andrii Nakryiko
  2021-11-10  5:23   ` Yonghong Song
  2 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2021-11-03  0:11 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Arnaldo Carvalho de Melo, dwarves, Alexei Starovoitov,
	Andrii Nakryiko, bpf, Daniel Borkmann, Kernel Team

On Tue, Nov 2, 2021 at 4:35 PM Yonghong Song <yhs@fb.com> wrote:
>
> Latest llvm is able to generate DW_TAG_LLVM_annotation for typedef
> declarations. Latest bpf-next supports BTF_KIND_DECL_TAG for
> typedef declarations. This patch implemented dwarf DW_TAG_LLVM_annotation
> to btf BTF_KIND_DECL_TAG conversion. Patch 1 is for dwarf_loader
> to process DW_TAG_LLVM_annotation tags. Patch 2 is for the
> dwarf->btf conversion.
>
> Changelog:
>   v1 -> v2:
>    - change some "if" statements to "switch" statement.
>

LGTM.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> Yonghong Song (2):
>   dwarf_loader: support typedef DW_TAG_LLVM_annotation
>   btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag
>     attributes
>
>  btf_encoder.c  | 17 ++++++++++++++---
>  dwarf_loader.c |  7 ++-----
>  2 files changed, 16 insertions(+), 8 deletions(-)
>
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation
  2021-11-03  0:11 ` [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Andrii Nakryiko
@ 2021-11-10  5:23   ` Yonghong Song
  2021-11-11 17:46     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 7+ messages in thread
From: Yonghong Song @ 2021-11-10  5:23 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Arnaldo Carvalho de Melo, dwarves, Alexei Starovoitov,
	Andrii Nakryiko, bpf, Daniel Borkmann, Kernel Team



On 11/2/21 5:11 PM, Andrii Nakryiko wrote:
> On Tue, Nov 2, 2021 at 4:35 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> Latest llvm is able to generate DW_TAG_LLVM_annotation for typedef
>> declarations. Latest bpf-next supports BTF_KIND_DECL_TAG for
>> typedef declarations. This patch implemented dwarf DW_TAG_LLVM_annotation
>> to btf BTF_KIND_DECL_TAG conversion. Patch 1 is for dwarf_loader
>> to process DW_TAG_LLVM_annotation tags. Patch 2 is for the
>> dwarf->btf conversion.
>>
>> Changelog:
>>    v1 -> v2:
>>     - change some "if" statements to "switch" statement.
>>
> 
> LGTM.
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>

Arnaldo, did you get chance to look at this patch set?

> 
>> Yonghong Song (2):
>>    dwarf_loader: support typedef DW_TAG_LLVM_annotation
>>    btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag
>>      attributes
>>
>>   btf_encoder.c  | 17 ++++++++++++++---
>>   dwarf_loader.c |  7 ++-----
>>   2 files changed, 16 insertions(+), 8 deletions(-)
>>
>> --
>> 2.30.2
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation
  2021-11-10  5:23   ` Yonghong Song
@ 2021-11-11 17:46     ` Arnaldo Carvalho de Melo
  2021-11-11 18:07       ` Yonghong Song
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-11-11 17:46 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Andrii Nakryiko, Arnaldo Carvalho de Melo, dwarves,
	Alexei Starovoitov, Andrii Nakryiko, bpf, Daniel Borkmann,
	Kernel Team

Em Tue, Nov 09, 2021 at 09:23:30PM -0800, Yonghong Song escreveu:
> 
> 
> On 11/2/21 5:11 PM, Andrii Nakryiko wrote:
> > On Tue, Nov 2, 2021 at 4:35 PM Yonghong Song <yhs@fb.com> wrote:
> > > 
> > > Latest llvm is able to generate DW_TAG_LLVM_annotation for typedef
> > > declarations. Latest bpf-next supports BTF_KIND_DECL_TAG for
> > > typedef declarations. This patch implemented dwarf DW_TAG_LLVM_annotation
> > > to btf BTF_KIND_DECL_TAG conversion. Patch 1 is for dwarf_loader
> > > to process DW_TAG_LLVM_annotation tags. Patch 2 is for the
> > > dwarf->btf conversion.
> > > 
> > > Changelog:
> > >    v1 -> v2:
> > >     - change some "if" statements to "switch" statement.
> > > 
> > 
> > LGTM.
> > 
> > Acked-by: Andrii Nakryiko <andrii@kernel.org>
> 
> Arnaldo, did you get chance to look at this patch set?

Yeah, I've merged and put it in the tmp.master branch so that libbpf's
CI can have a go on it.

I'm also updating my clang/llvm build to test it.

Thanks,

- Arnaldo
 
> > 
> > > Yonghong Song (2):
> > >    dwarf_loader: support typedef DW_TAG_LLVM_annotation
> > >    btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag
> > >      attributes
> > > 
> > >   btf_encoder.c  | 17 ++++++++++++++---
> > >   dwarf_loader.c |  7 ++-----
> > >   2 files changed, 16 insertions(+), 8 deletions(-)
> > > 
> > > --
> > > 2.30.2
> > > 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation
  2021-11-11 17:46     ` Arnaldo Carvalho de Melo
@ 2021-11-11 18:07       ` Yonghong Song
  0 siblings, 0 replies; 7+ messages in thread
From: Yonghong Song @ 2021-11-11 18:07 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Andrii Nakryiko, Arnaldo Carvalho de Melo, dwarves,
	Alexei Starovoitov, Andrii Nakryiko, bpf, Daniel Borkmann,
	Kernel Team



On 11/11/21 9:46 AM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Nov 09, 2021 at 09:23:30PM -0800, Yonghong Song escreveu:
>>
>>
>> On 11/2/21 5:11 PM, Andrii Nakryiko wrote:
>>> On Tue, Nov 2, 2021 at 4:35 PM Yonghong Song <yhs@fb.com> wrote:
>>>>
>>>> Latest llvm is able to generate DW_TAG_LLVM_annotation for typedef
>>>> declarations. Latest bpf-next supports BTF_KIND_DECL_TAG for
>>>> typedef declarations. This patch implemented dwarf DW_TAG_LLVM_annotation
>>>> to btf BTF_KIND_DECL_TAG conversion. Patch 1 is for dwarf_loader
>>>> to process DW_TAG_LLVM_annotation tags. Patch 2 is for the
>>>> dwarf->btf conversion.
>>>>
>>>> Changelog:
>>>>     v1 -> v2:
>>>>      - change some "if" statements to "switch" statement.
>>>>
>>>
>>> LGTM.
>>>
>>> Acked-by: Andrii Nakryiko <andrii@kernel.org>
>>
>> Arnaldo, did you get chance to look at this patch set?
> 
> Yeah, I've merged and put it in the tmp.master branch so that libbpf's
> CI can have a go on it.
> 
> I'm also updating my clang/llvm build to test it.

Great! Thanks.

> 
> Thanks,
> 
> - Arnaldo
>   
>>>
>>>> Yonghong Song (2):
>>>>     dwarf_loader: support typedef DW_TAG_LLVM_annotation
>>>>     btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag
>>>>       attributes
>>>>
>>>>    btf_encoder.c  | 17 ++++++++++++++---
>>>>    dwarf_loader.c |  7 ++-----
>>>>    2 files changed, 16 insertions(+), 8 deletions(-)
>>>>
>>>> --
>>>> 2.30.2
>>>>
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-11 18:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 23:35 [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Yonghong Song
2021-11-02 23:35 ` [PATCH dwarves v2 1/2] dwarf_loader: " Yonghong Song
2021-11-02 23:35 ` [PATCH dwarves v2 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes Yonghong Song
2021-11-03  0:11 ` [PATCH dwarves v2 0/2] btf: support typedef DW_TAG_LLVM_annotation Andrii Nakryiko
2021-11-10  5:23   ` Yonghong Song
2021-11-11 17:46     ` Arnaldo Carvalho de Melo
2021-11-11 18:07       ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).