BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Vineet Gupta <vineet.gupta@linux.dev>, dwarves@vger.kernel.org
Cc: bpf@vger.kernel.org, Andrii Nakryiko <andrii@kernel.org>,
	acme@kernel.org, Alan Maguire <alan.maguire@oracle.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	jose.marchesi@oracle.com, David Faust <david.faust@oracle.com>
Subject: Re: [PAHOLE v4 2/3] dwarf_loader: Add support for DW_TAG_GNU_annotation
Date: Wed, 1 Jul 2026 10:14:25 -0700	[thread overview]
Message-ID: <c9beceb9-946d-47ce-9311-4b9559f21613@linux.dev> (raw)
In-Reply-To: <252c53f3-3f06-40f4-9cd3-795eb298687c@linux.dev>



On 6/30/26 1:02 PM, Vineet Gupta wrote:
> On 6/17/26 11:18 AM, Vineet Gupta wrote:
>> On 6/3/26 1:08 PM, Yonghong Song wrote:
>>> For decl tag
>>> ============
>>>
>>> $ cat decl_tag.c
>>> /* btf_decl_tag test cases.
>>>     *
>>>     * btf_decl_tag can be attached to:
>>>     *   - global (incl. static) variables
>>>     *   - functions
>>>     *   - function parameters
>>>     *   - struct/union types and their members
>>>     *   - typedefs
>>>     *
>>>     * Build:  clang -O2 -target bpf -g -c decl_tag.c -o decl_tag.o
>>>     *         /home/yhs/work/gcc-build/opt/gcc-16.1/bin/gcc -O2 
>>> -gbtf -g -c decl_tag.c -o decl_tag.o
>>>     * Dump:   bpftool btf dump file decl_tag.o
>>>     */
>>>
>>> #define __tag(x) __attribute__((btf_decl_tag(x)))
>>>
>>> /* tag on a global variable */
>>> int global_var __tag("global_var_tag");
>>>
>>> /* tag on a static variable */
>>> static int static_var __tag("static_var_tag");
>>>
>>> /* multiple tags on one declaration */
>>> int multi_tag_var __tag("tag_a") __tag("tag_b");
>>>
>>> /* tag on struct type and its members */
>>> struct foo {
>>>            int a __tag("member_a_tag");
>>>            int b __tag("member_b_tag");
>>> } __tag("struct_foo_tag");
>>>
>>> /* tag on a typedef */
>>> typedef struct foo foo_t1 __tag("typedef_foo_tag");
>>> typedef struct {int foo2;} foo_t2 __tag("typedef_foo2_tag");
>>>
>>> /* tag on a function and its parameters */
>>> __tag("func_add_tag")
>>> int add(int x __tag("param_x_tag"), int y __tag("param_y_tag"))
>>> {
>>>            return x + y;
>>> }
>>>
>>> /* keep the globals/types alive so they land in BTF */
>>> int use(foo_t1 *f, foo_t2 *g)
>>> {
>>>            return add(global_var + static_var + multi_tag_var, f->a 
>>> + g->foo2);
>>> }
>>>
>>> $ /home/yhs/work/gcc-build/opt/gcc-16.1/bin/gcc -O2 -gbtf -g -c 
>>> decl_tag.c -o decl_tag.o
>>> decl_tag.c:30:1: warning: ‘btf_decl_tag’ attribute does not apply to 
>>> types [-Wattributes]
>>>       30 | } __tag("struct_foo_tag");
>>>          | ^
>>>
>> [snip]
>>
>>> Three decl tags (struct_foo_tag, typedef_foo_tag and typedef_foo2_tag)
>>> are missing here:
>>>
>>> struct foo {
>>>            int a __tag("member_a_tag");
>>>            int b __tag("member_b_tag");
>>> } __tag("struct_foo_tag");
>>>
>>> /* tag on a typedef */
>>> typedef struct foo foo_t1 __tag("typedef_foo_tag");
>>> typedef struct {int foo2;} foo_t2 __tag("typedef_foo2_tag");
>> Semantically what does this mean ? Will the decl tag will be "applied"
>> where ever the type is instantiated ?
>
> So these are dec tags (not type tags) on typedefs.
> Are these still relevant after the change below for supporting type 
> tags on typedefs (and gcc has in flight patches to do the same).
>
>    commit 5754a48780f516cbc06eeb2a31b1e445ddd9c935
>    Author: yonghong-song <yhs@fb.com>
>    Date:   Mon Jun 15 10:51:02 2026 -0700
>         [Clang][BPF] Support btf_type_tag on typedef underlying types 
> (#203089)
>         Emil Tsalapatis suggested to add type tag for typedef like below:
>         ```
>           $ cat tag.c
>           #define __type_tag(x) __attribute__((btf_type_tag(x)))
>           struct bar { int c; int d; };
>           typedef struct bar __type_tag("a") bar_t;
>           int use(bar_t *v)
>           {
>             return v->c + v->d;
>           }
>         ```
>         This makes the code simpler -- using `bar_t *v` instead of the 
> longer
>         form `struct bar __type_tag("a") *v`.
>         So the goal is to allow type tag for typedef underlying types. 
> The
>         following describes the main changes:
>
>
> And if so, how are they semantically different and what's the use case 
> fot decl tags on typedefs.

Decl tags and type tags are different in the above. Decl tags will be something like

     decl_tag -> typedef -> ...

Type tags will be something like\

     typedef -> type_tag -> ...

You can do both decl tag and type dag for the same typedef

     decl_tag -> typedef -> type_tag -> ...

There is a selftest (progs/test_btf_decl_tag.c) which has an example with decl_tag
for typedef.

About the question what is the use case for decl tags for typedef.
The initial llvm implementation is to have more coverage so we do not need
to add them later on. I didn't monitor this and not sure whether anybody
uses it or not.

But I think gcc should implement
     typedef -> type_tag -> ...
if this is the case, I assume it should be easier for gcc to implement
     decl_tag -> typedef -> ...

>
>> OK, opened PR/125862 [1]  for future improvement.
>>
>> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125862
>
> If not, we can close this gcc PR as won't fix / not needed.
>
> Thx,
> -Vineet


  reply	other threads:[~2026-07-01 17:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 19:55 [PAHOLE v4 1/3] dwarf_loader: Extract die__add_btf_type_tag() helper [NFC] Vineet Gupta
2026-06-02 19:55 ` [PAHOLE v4 2/3] dwarf_loader: Add support for DW_TAG_GNU_annotation Vineet Gupta
2026-06-03 20:08   ` Yonghong Song
2026-06-03 20:54     ` Vineet Gupta
2026-06-03 21:40       ` Yonghong Song
2026-06-17 18:18     ` Vineet Gupta
2026-06-30 20:02       ` Vineet Gupta
2026-07-01 17:14         ` Yonghong Song [this message]
2026-06-03 20:42   ` Emil Tsalapatis
2026-06-03 21:41   ` Yonghong Song
2026-06-17 18:34     ` Vineet Gupta
2026-06-07  9:54   ` Alan Maguire
2026-06-17 20:08     ` Vineet Gupta
2026-06-02 19:55 ` [PAHOLE v4 3/3] tests: Support GCC in pfunct-btf-decl-tags test Vineet Gupta
2026-06-03 20:44   ` Emil Tsalapatis
2026-06-03 21:52   ` Yonghong Song
2026-06-03 20:18 ` [PAHOLE v4 1/3] dwarf_loader: Extract die__add_btf_type_tag() helper [NFC] Yonghong Song
2026-06-03 20:37 ` Emil Tsalapatis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c9beceb9-946d-47ce-9311-4b9559f21613@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=david.faust@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=jose.marchesi@oracle.com \
    --cc=vineet.gupta@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox