From: Vineet Gupta <vineet.gupta@linux.dev>
To: 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>,
Yonghong Song <yonghong.song@linux.dev>,
Vineet Gupta <vineet.gupta@linux.dev>
Subject: [PAHOLE v5 1/5] btf_loader: Handle decl tag component_idx for parameters
Date: Wed, 17 Jun 2026 17:57:27 -0700 [thread overview]
Message-ID: <20260618005731.273181-2-vineet.gupta@linux.dev> (raw)
In-Reply-To: <20260618005731.273181-1-vineet.gupta@linux.dev>
From: Alan Maguire <alan.maguire@oracle.com>
A BTF_KIND_DECL_TAG with a non-negative component_idx applies to a
specific function parameter (or struct/union member), not to the
function itself. btf_loader.c however attached every decl tag to the
type named by btf_type->type, so parameter decl tags were recorded on
the function rather than on the parameter, and pfunct never printed
them with the parameter.
Resolve a non-negative component_idx to the corresponding parameter via
new helpers ftype__parameter()/function__parameter(), and attach the
tag there. Teach the pretty printer to emit a parameter's attributes by
factoring the function-level attribute loop into tag__attributes_fprintf()
and calling it from ftype__fprintf_parms() for each parameter.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
btf_loader.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
dwarves_fprintf.c | 20 ++++++++++++++++----
2 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/btf_loader.c b/btf_loader.c
index b591219a245d..9bb52c3c5801 100644
--- a/btf_loader.c
+++ b/btf_loader.c
@@ -477,12 +477,56 @@ static struct attributes *attributes__realloc(struct attributes *attributes, con
return result;
}
+static struct tag *ftype__parameter(const struct ftype *ftype, int component_idx)
+{
+ struct parameter *pos;
+ int idx = 0;
+
+ ftype__for_each_parameter(ftype, pos) {
+ if (idx == component_idx)
+ return &pos->tag;
+ ++idx;
+ }
+
+ return NULL;
+}
+
+static struct tag *function__parameter(const struct function *func, struct cu *cu,
+ int component_idx)
+{
+ struct tag *tag;
+
+ if (component_idx < 0)
+ return NULL;
+
+ tag = cu__type(cu, func->proto.tag.type);
+ if (tag == NULL)
+ return NULL;
+
+ return ftype__parameter(tag__ftype(tag), component_idx);
+}
+
static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
{
+ int component_idx = btf_decl_tag(tp)->component_idx;
struct tag *tag = cu__type(cu, tp->type);
struct attributes *tmp;
- if (tag == NULL)
+ if (component_idx >= 0) {
+ struct tag *func_tag = cu__function(cu, tp->type);
+
+ if (func_tag != NULL) {
+ tag = function__parameter(tag__function(func_tag), cu,
+ component_idx);
+ if (tag == NULL) {
+ fprintf(stderr, "WARNING: BTF_KIND_DECL_TAG for unknown parameter %d in BTF id %d\n",
+ component_idx, tp->type);
+ return 0;
+ }
+ }
+ }
+
+ if (tag == NULL && component_idx < 0)
tag = cu__function(cu, tp->type);
if (tag == NULL)
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index 1ec478c2a027..54f483244bd2 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -1199,6 +1199,18 @@ const char *function__prototype(const struct function *func,
bf, len);
}
+static size_t tag__attributes_fprintf(const struct tag *tag, FILE *fp)
+{
+ size_t printed = 0;
+ int i;
+
+ if (tag->attributes)
+ for (i = 0; i < tag->attributes->cnt; ++i)
+ printed += fprintf(fp, "%s ", tag->attributes->values[i]);
+
+ return printed;
+}
+
size_t ftype__fprintf_parms(const struct ftype *ftype,
const struct cu *cu, int indent,
const struct conf_fprintf *conf, FILE *fp)
@@ -1240,6 +1252,7 @@ size_t ftype__fprintf_parms(const struct ftype *ftype,
if (n)
return printed + n;
if (ptype->tag == DW_TAG_subroutine_type) {
+ printed += tag__attributes_fprintf(&pos->tag, fp);
printed +=
ftype__fprintf(tag__ftype(ptype),
cu, name, 0, 1, 0,
@@ -1248,12 +1261,14 @@ size_t ftype__fprintf_parms(const struct ftype *ftype,
}
}
} else if (type->tag == DW_TAG_subroutine_type) {
+ printed += tag__attributes_fprintf(&pos->tag, fp);
printed += ftype__fprintf(tag__ftype(type), cu, name,
true, 0, 0, 0, conf, fp);
continue;
}
stype = tag__name(type, cu, sbf, sizeof(sbf), conf);
print_it:
+ printed += tag__attributes_fprintf(&pos->tag, fp);
printed += fprintf(fp, "%s%s%s", stype, name ? " " : "",
name ?: "");
}
@@ -1405,11 +1420,8 @@ static size_t function__fprintf(const struct tag *tag, const struct cu *cu,
struct ftype *ftype = func->btf ? tag__ftype(cu__type(cu, func->proto.tag.type)) : &func->proto;
size_t printed = 0;
bool inlined = !conf->strip_inline && function__declared_inline(func);
- int i;
- if (tag->attributes)
- for (i = 0; i < tag->attributes->cnt; ++i)
- printed += fprintf(fp, "%s ", tag->attributes->values[i]);
+ printed += tag__attributes_fprintf(tag, fp);
if (func->virtuality == DW_VIRTUALITY_virtual ||
func->virtuality == DW_VIRTUALITY_pure_virtual)
--
2.54.0
next prev parent reply other threads:[~2026-06-18 0:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 0:57 [PAHOLE v5 0/5] support for DW_TAG_GNU_annotation and fixes Vineet Gupta
2026-06-18 0:57 ` Vineet Gupta [this message]
2026-06-18 4:46 ` [PAHOLE v5 1/5] btf_loader: Handle decl tag component_idx for parameters Emil Tsalapatis
2026-06-18 0:57 ` [PAHOLE v5 2/5] dwarf_loader: Extract die__add_btf_type_tag() helper [NFC] Vineet Gupta
2026-06-18 0:57 ` [PAHOLE v5 3/5] dwarf_loader: Add support for DW_TAG_GNU_annotation Vineet Gupta
2026-06-18 0:57 ` [PAHOLE v5 4/5] tests: Support GCC in pfunct-btf-decl-tags test Vineet Gupta
2026-06-18 0:57 ` [PAHOLE v5 5/5] tests: Add btf_type_tag ordering test Vineet Gupta
2026-06-18 4:47 ` 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=20260618005731.273181-2-vineet.gupta@linux.dev \
--to=vineet.gupta@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=yonghong.song@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