Skip to contentSkip to conversation

btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag

PATCH Applied Eduard Zingerman 3 participants 10 messages Dec 11, 2024 – Jan 3, 2025 BPF

lore
Share & tools
lore

Eduard Zingerman

author maintainer
#0 lore raw

PATCH 1/2 btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag

btf_loader issues a warning when it sees several BTF_DECL_TAGs pointing to the same type. Such situation is possible in practice after patch [0], that marks certain functions with kfunc and bpf_fastcall tags. E.g.:

  $ pfunct vmlinux -F btf -f bpf_rdonly_cast
WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_cast_to_kern_ctx already with attribute (bpf_kfunc), ignoring
WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_rdonly_cast already with attribute (bpf_kfunc), ignoring
  bpf_kfunc void * bpf_rdonly_cast(const void  * obj__ign, u32 btf_id__k);

This commit extends 'struct tag' to allow attaching multiple attributes. Define 'struct attributes' as follows:

  struct attributes {
        uint64_t cnt;
        const char *values[];
  };

In order to avoid adding counter field in 'struct tag', as not many instances of 'struct tag' would have attributes.

Same command after this patch:

  $ pfunct vmlinux -F btf -f bpf_rdonly_cast
  bpf_kfunc bpf_fastcall void * bpf_rdonly_cast(const void  * obj__ign, u32 btf_id__k);

[0] https://lore.kernel.org/dwarves/[email protected]/T/#m8a6cb49a99d1b2ba38d616495a540ae8fc5f3a76

---
 btf_loader.c           | 31 +++++++++++++++++++++++--------
 dwarf_loader.c         |  2 +-
 dwarves.c              |  3 +++
 dwarves.h              |  8 +++++++-
 dwarves_fprintf.c      |  6 ++++--
 tests/btf_functions.sh |  2 +-
 6 files changed, 39 insertions(+), 13 deletions(-)
btf_loader.c +23 -8
index 4814f29..af9e1db 100644
@@ -459,9 +459,28 @@ static int create_new_tag(struct cu *cu, int type, const struct btf_type *tp, ui
 	return 0;
 }
 
+static struct attributes *attributes__realloc(struct attributes *attributes, const char *value)
+{
+	struct attributes *result;
+	uint64_t cnt;
+	size_t sz;
+
+	cnt = attributes ? attributes->cnt : 0;
+	sz = sizeof(*attributes) + (cnt + 1) * sizeof(*attributes->values);
+	result = realloc(attributes, sz);
+	if (!result)
+		return NULL;
+	if (!attributes)
+		result->cnt = 0;
+	result->values[cnt] = value;
+	result->cnt++;
+	return result;
+}
+
 static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
 {
 	struct tag *tag = cu__type(cu, tp->type);
+	struct attributes *tmp;
 
 	if (tag == NULL)
 		tag = cu__function(cu, tp->type);
@@ -475,15 +494,11 @@ static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
 	}
 
 	const char *attribute = cu__btf_str(cu, tp->name_off);
+	tmp = attributes__realloc(tag->attributes, attribute);
+	if (!tmp)
+		return -ENOMEM;
 
-	if (tag->attribute != NULL) {
-		char bf[128];
-
-		fprintf(stderr, "WARNING: still unsuported BTF_KIND_DECL_TAG(%s) for %s already with attribute (%s), ignoring\n",
-		       attribute, tag__name(tag, cu, bf, sizeof(bf), NULL), tag->attribute);
-	} else {
-		tag->attribute = attribute;
-	}
+	tag->attributes = tmp;
 
 	return 0;
 }
dwarf_loader.c +1 -1
index 598fde4..34376b2 100644
@@ -513,7 +513,7 @@ static void tag__init(struct tag *tag, struct cu *cu, Dwarf_Die *die)
 
 	dwarf_tag__set_attr_type(dtag, abstract_origin, die, DW_AT_abstract_origin);
 	tag->recursivity_level = 0;
-	tag->attribute = NULL;
+	tag->attributes = NULL;
 
 	if (cu->extra_dbg_info) {
 		pthread_mutex_lock(&libdw__lock);
dwarves.c +3 -0
index ae512b9..f970dd2 100644
@@ -210,6 +210,9 @@ void tag__delete(struct tag *tag, struct cu *cu)
 
 	assert(list_empty(&tag->node));
 
+	if (tag->attributes)
+		free(tag->attributes);
+
 	switch (tag->tag) {
 	case DW_TAG_union_type:
 		type__delete(tag__type(tag), cu);		break;
dwarves.h +7 -1
index 1cb0d62..0a4d5a2 100644
@@ -516,10 +516,16 @@ int cu__for_all_tags(struct cu *cu,
 				     struct cu *cu, void *cookie),
 		     void *cookie);
 
+struct attributes {
+	uint64_t cnt;
+	const char *values[];
+};
+
 /** struct tag - basic representation of a debug info element
  * @priv - extra data, for instance, DWARF offset, id, decl_{file,line}
  * @top_level -
  * @shared_tags: used by struct namespace
+ * @attributes - attributes specified by BTF_DECL_TAGs targeting this tag
  */
 struct tag {
 	struct list_head node;
@@ -530,7 +536,7 @@ struct tag {
 	bool		 has_btf_type_tag:1;
 	bool		 shared_tags:1;
 	uint8_t		 recursivity_level;
-	const char	 *attribute;
+	struct attributes *attributes;
 };
 
 // To use with things like type->type_enum == perf_event_type+perf_user_event_type
dwarves_fprintf.c +4 -2
index e16a6b4..c3e7f3c 100644
@@ -1405,9 +1405,11 @@ 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->attribute)
-		printed += fprintf(fp, "%s ", tag->attribute);
+	if (tag->attributes)
+		for (i = 0; i < tag->attributes->cnt; ++i)
+			printed += fprintf(fp, "%s ", tag->attributes->values[i]);
 
 	if (func->virtuality == DW_VIRTUALITY_virtual ||
 	    func->virtuality == DW_VIRTUALITY_pure_virtual)
tests/btf_functions.sh +1 -1
index 61f8a00..c92e5ae 100755
@@ -66,7 +66,7 @@ pfunct --all --no_parm_names --format_path=dwarf $vmlinux | \
 	sort|uniq > $outdir/dwarf.funcs
 # all functions from BTF (removing bpf_kfunc prefix where found)
 pfunct --all --no_parm_names --format_path=btf $outdir/vmlinux.btf 2>/dev/null|\
-	awk '{ gsub("^bpf_kfunc ",""); print $0}'|sort|uniq > $outdir/btf.funcs
+	awk '{ gsub("^(bpf_kfunc |bpf_fastcall )+",""); print $0}'|sort|uniq > $outdir/btf.funcs
 
 exact=0
 inline=0
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH 2/2 tests: verify that pfunct prints btf_decl_tags read from BTF

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

---
 tests/pfunct-btf-decl-tags.sh | 65 +++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100755 tests/pfunct-btf-decl-tags.sh
tests/pfunct-btf-decl-tags.sh new file +65 -0
new file mode 100755
index 0000000..7e7f547
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Check that pfunct can print btf_decl_tags read from BTF
+
+tmpobj=$(mktemp /tmp/pfunct-btf-decl-tags.sh.XXXXXX.o)
+
+cleanup()
+{
+	rm $tmpobj
+}
+
+trap cleanup EXIT
+
+CLANG=${CLANG:-clang}
+if ! command -v $CLANG > /dev/null; then
+	echo "Need clang for test $0"
+	exit 1
+fi
+
+(cat <<EOF
+#define __tag(x) __attribute__((btf_decl_tag(#x)))
+
+__tag(a) __tag(b) __tag(c) void foo(void) {}
+__tag(a) __tag(b)          void bar(void) {}
+__tag(a)                   void buz(void) {}
+
+EOF
+) | $CLANG --target=bpf -c -g -x c -o $tmpobj -
+
+# tags order is not guaranteed
+sort_tags=$(cat <<EOF
+{
+match(\$0,/^(.*) (void .*)/,tags_and_proto);
+tags  = tags_and_proto[1];
+proto = tags_and_proto[2];
+split(tags, tags_arr ,/ /);
+asort(tags_arr);
+for (t in tags_arr) printf "%s ", tags_arr[t];
+print proto;
+}
+EOF
+)
+
+expected=$(cat <<EOF
+a b c void foo(void);
+a b void bar(void);
+a void buz(void);
+EOF
+)
+
+out=$(pfunct -P -F btf $tmpobj | awk "$sort_tags" | sort)
+d=$(diff -u <(echo "$expected") <(echo "$out"))
+
+if [[ "$d" == "" ]]; then
+	echo "Ok"
+	exit 0
+else
+	echo "pfunct output does not match expected:"
+	echo "$d"
+	echo
+	echo "Complete output:"
+	echo "$out"
+	exit 1
+fi
Signature · 1 line
2.47.0
Reviewed-by Tested-by on v1 2/2
#2 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

5: Ok

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

Quoted 76 lines
---
 tests/pfunct-btf-decl-tags.sh | 65 +++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100755 tests/pfunct-btf-decl-tags.sh
tests/pfunct-btf-decl-tags.sh new file +65 -0
new file mode 100755
index 0000000..7e7f547
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Check that pfunct can print btf_decl_tags read from BTF
+
+tmpobj=$(mktemp /tmp/pfunct-btf-decl-tags.sh.XXXXXX.o)
+
+cleanup()
+{
+	rm $tmpobj
+}
+
+trap cleanup EXIT
+
+CLANG=${CLANG:-clang}
+if ! command -v $CLANG > /dev/null; then
+	echo "Need clang for test $0"
+	exit 1
+fi
+
+(cat <<EOF
+#define __tag(x) __attribute__((btf_decl_tag(#x)))
+
+__tag(a) __tag(b) __tag(c) void foo(void) {}
+__tag(a) __tag(b)          void bar(void) {}
+__tag(a)                   void buz(void) {}
+
+EOF
+) | $CLANG --target=bpf -c -g -x c -o $tmpobj -
+
+# tags order is not guaranteed
+sort_tags=$(cat <<EOF
+{
+match(\$0,/^(.*) (void .*)/,tags_and_proto);
+tags  = tags_and_proto[1];
+proto = tags_and_proto[2];
+split(tags, tags_arr ,/ /);
+asort(tags_arr);
+for (t in tags_arr) printf "%s ", tags_arr[t];
+print proto;
+}
+EOF
+)
+
+expected=$(cat <<EOF
+a b c void foo(void);
+a b void bar(void);
+a void buz(void);
+EOF
+)
+
+out=$(pfunct -P -F btf $tmpobj | awk "$sort_tags" | sort)
+d=$(diff -u <(echo "$expected") <(echo "$out"))
+
+if [[ "$d" == "" ]]; then
+	echo "Ok"
+	exit 0
+else
+	echo "pfunct output does not match expected:"
+	echo "$d"
+	echo
+	echo "Complete output:"
+	echo "$out"
+	exit 1
+fi
author maintainer
#3 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

Quoted 20 lines · Alan Maguire
Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

5: Ok

Quoted 8 lines

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

Makes sense, will change.
Will wait a bit and resend v2 in the evening.
Thank you.

[...]

#4 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

In reply to Alan Maguire
Quoted 20 lines · Alan Maguire
Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

5: Ok

Quoted 8 lines

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

Thanks, applied.

- Arnaldo

#5 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 18 lines · Alan Maguire
Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

Quoted 7 lines
Quoted 7 lines

5: Ok

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

To clarify, I'm doing as Alan suggests and adding that message when the test succeeds.

Quoted 7 lines
Quoted 2 lines

Thanks, applied.

- Arnaldo

#6 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 21 lines · Arnaldo Carvalho de Melo
Quoted 20 lines · Alan Maguire
Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

5: Ok

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

To clarify, I'm doing as Alan suggests and adding that message when the test succeeds.

Running just this test:

root@number:/home/acme/git/pahole# tests/pfunct-btf-decl-tags.sh
Check that pfunct can print btf_decl_tags read from BTF: Ok
root@number:/home/acme/git/pahole#
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Thanks, applied.

- Arnaldo

author maintainer
#7 lore raw

Re: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF

In reply to Arnaldo Carvalho de Melo
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 21 lines · Arnaldo Carvalho de Melo
Quoted 20 lines · Alan Maguire
Quoted 6 lines · Eduard Zingerman

When using BTF as a source, pfunct should now be able to print btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}
Quoted 7 lines

This situation arises after recent kernel changes, where tags 'kfunc' and 'bpf_fastcall' are added to some functions. To avoid dependency on a recent kernel version test this by compiling a small C program using clang with --target=bpf, which would instruct clang to generate .BTF section.

nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see

5: Ok

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

could we just echo the comment below, i.e.

5 : Check that pfunct can print btf_decl_tags read from BTF: Ok

?

To clarify, I'm doing as Alan suggests and adding that message when the test succeeds.

Sure, thank you.
Sorry, I should have reposted v2 with this small change.

Reviewed-by Tested-by on v1 1/2
#8 lore raw
In reply to Eduard Zingerman
Quoted 23 lines · Eduard Zingerman

btf_loader issues a warning when it sees several BTF_DECL_TAGs pointing to the same type. Such situation is possible in practice after patch [0], that marks certain functions with kfunc and bpf_fastcall tags. E.g.:

  $ pfunct vmlinux -F btf -f bpf_rdonly_cast
WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_cast_to_kern_ctx already with attribute (bpf_kfunc), ignoring
WARNING: still unsuported BTF_KIND_DECL_TAG(bpf_fastcall) for bpf_rdonly_cast already with attribute (bpf_kfunc), ignoring
  bpf_kfunc void * bpf_rdonly_cast(const void  * obj__ign, u32 btf_id__k);

This commit extends 'struct tag' to allow attaching multiple attributes. Define 'struct attributes' as follows:

  struct attributes {
        uint64_t cnt;
        const char *values[];
  };

In order to avoid adding counter field in 'struct tag', as not many instances of 'struct tag' would have attributes.

Same command after this patch:

Quoted 8 lines
  $ pfunct vmlinux -F btf -f bpf_rdonly_cast
  bpf_kfunc bpf_fastcall void * bpf_rdonly_cast(const void  * obj__ign, u32 btf_id__k);

[0] https://lore.kernel.org/dwarves/[email protected]/T/#m8a6cb49a99d1b2ba38d616495a540ae8fc5f3a76

Looks good to me. I _think_ we're safe enough in assuming the tag ordering "bpf_kfunc bpf_fastcall" in the btf_functions.sh test, right?

Quoted 150 lines
---
 btf_loader.c           | 31 +++++++++++++++++++++++--------
 dwarf_loader.c         |  2 +-
 dwarves.c              |  3 +++
 dwarves.h              |  8 +++++++-
 dwarves_fprintf.c      |  6 ++++--
 tests/btf_functions.sh |  2 +-
 6 files changed, 39 insertions(+), 13 deletions(-)
btf_loader.c +23 -8
index 4814f29..af9e1db 100644
@@ -459,9 +459,28 @@ static int create_new_tag(struct cu *cu, int type, const struct btf_type *tp, ui
 	return 0;
 }
 
+static struct attributes *attributes__realloc(struct attributes *attributes, const char *value)
+{
+	struct attributes *result;
+	uint64_t cnt;
+	size_t sz;
+
+	cnt = attributes ? attributes->cnt : 0;
+	sz = sizeof(*attributes) + (cnt + 1) * sizeof(*attributes->values);
+	result = realloc(attributes, sz);
+	if (!result)
+		return NULL;
+	if (!attributes)
+		result->cnt = 0;
+	result->values[cnt] = value;
+	result->cnt++;
+	return result;
+}
+
 static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
 {
 	struct tag *tag = cu__type(cu, tp->type);
+	struct attributes *tmp;
 
 	if (tag == NULL)
 		tag = cu__function(cu, tp->type);
@@ -475,15 +494,11 @@ static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
 	}
 
 	const char *attribute = cu__btf_str(cu, tp->name_off);
+	tmp = attributes__realloc(tag->attributes, attribute);
+	if (!tmp)
+		return -ENOMEM;
 
-	if (tag->attribute != NULL) {
-		char bf[128];
-
-		fprintf(stderr, "WARNING: still unsuported BTF_KIND_DECL_TAG(%s) for %s already with attribute (%s), ignoring\n",
-		       attribute, tag__name(tag, cu, bf, sizeof(bf), NULL), tag->attribute);
-	} else {
-		tag->attribute = attribute;
-	}
+	tag->attributes = tmp;
 
 	return 0;
 }
dwarf_loader.c +1 -1
index 598fde4..34376b2 100644
@@ -513,7 +513,7 @@ static void tag__init(struct tag *tag, struct cu *cu, Dwarf_Die *die)
 
 	dwarf_tag__set_attr_type(dtag, abstract_origin, die, DW_AT_abstract_origin);
 	tag->recursivity_level = 0;
-	tag->attribute = NULL;
+	tag->attributes = NULL;
 
 	if (cu->extra_dbg_info) {
 		pthread_mutex_lock(&libdw__lock);
dwarves.c +3 -0
index ae512b9..f970dd2 100644
@@ -210,6 +210,9 @@ void tag__delete(struct tag *tag, struct cu *cu)
 
 	assert(list_empty(&tag->node));
 
+	if (tag->attributes)
+		free(tag->attributes);
+
 	switch (tag->tag) {
 	case DW_TAG_union_type:
 		type__delete(tag__type(tag), cu);		break;
dwarves.h +7 -1
index 1cb0d62..0a4d5a2 100644
@@ -516,10 +516,16 @@ int cu__for_all_tags(struct cu *cu,
 				     struct cu *cu, void *cookie),
 		     void *cookie);
 
+struct attributes {
+	uint64_t cnt;
+	const char *values[];
+};
+
 /** struct tag - basic representation of a debug info element
  * @priv - extra data, for instance, DWARF offset, id, decl_{file,line}
  * @top_level -
  * @shared_tags: used by struct namespace
+ * @attributes - attributes specified by BTF_DECL_TAGs targeting this tag
  */
 struct tag {
 	struct list_head node;
@@ -530,7 +536,7 @@ struct tag {
 	bool		 has_btf_type_tag:1;
 	bool		 shared_tags:1;
 	uint8_t		 recursivity_level;
-	const char	 *attribute;
+	struct attributes *attributes;
 };
 
 // To use with things like type->type_enum == perf_event_type+perf_user_event_type
dwarves_fprintf.c +4 -2
index e16a6b4..c3e7f3c 100644
@@ -1405,9 +1405,11 @@ 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->attribute)
-		printed += fprintf(fp, "%s ", tag->attribute);
+	if (tag->attributes)
+		for (i = 0; i < tag->attributes->cnt; ++i)
+			printed += fprintf(fp, "%s ", tag->attributes->values[i]);
 
 	if (func->virtuality == DW_VIRTUALITY_virtual ||
 	    func->virtuality == DW_VIRTUALITY_pure_virtual)
tests/btf_functions.sh +1 -1
index 61f8a00..c92e5ae 100755
@@ -66,7 +66,7 @@ pfunct --all --no_parm_names --format_path=dwarf $vmlinux | \
 	sort|uniq > $outdir/dwarf.funcs
 # all functions from BTF (removing bpf_kfunc prefix where found)
 pfunct --all --no_parm_names --format_path=btf $outdir/vmlinux.btf 2>/dev/null|\
-	awk '{ gsub("^bpf_kfunc ",""); print $0}'|sort|uniq > $outdir/btf.funcs
+	awk '{ gsub("^(bpf_kfunc |bpf_fastcall )+",""); print $0}'|sort|uniq > $outdir/btf.funcs
 
 exact=0
 inline=0
author maintainer
#9 lore raw

On Thu, 2024-12-12 at 20:29 +0000, Alan Maguire wrote:

[...]

Quoted 2 lines

Looks good to me. I _think_ we're safe enough in assuming the tag ordering "bpf_kfunc bpf_fastcall" in the btf_functions.sh test, right?

For "bpf_kfunc bpf_fastcall" yes, we should be safe.
On the other hand, I don't think the below could be simplified with this knowledge:

+ awk '{ gsub("^(bpf_kfunc |bpf_fastcall )+",""); print $0}'|sort|uniq

Because there are situations when only "bpf_kfunc" is present and when both "bpf_kfunc", "bpf_fastcall" are present.

[...]