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 4/5] tests: Support GCC in pfunct-btf-decl-tags test
Date: Wed, 17 Jun 2026 17:57:30 -0700 [thread overview]
Message-ID: <20260618005731.273181-5-vineet.gupta@linux.dev> (raw)
In-Reply-To: <20260618005731.273181-1-vineet.gupta@linux.dev>
GCC 16+ supports btf_decl_tag via DW_TAG_GNU_annotation. Update the
test to run with both GCC (>= 16) and clang when available, instead
of requiring clang only.
Compile the clang case natively and encode BTF with "pahole -J" (like
the GCC case) rather than emitting BPF-target BTF directly, so both
compilers exercise the same DWARF -> BTF path.
Add a function with a parameter decl tag (qux) to cover decl tags that
carry a component_idx, and make the awk post-processing pass through
lines that have no leading tags.
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
---
Changes since v4 [4]
- Test function param decl tag [Alan]
- Missing "pahole -j" for clang [Yonghong]
- Collected the review tags [Emil, Yonghong]
[4] https://lore.kernel.org/bpf/20260602195512.1511013-3-vineet.gupta@linux.dev/
---
tests/pfunct-btf-decl-tags.sh | 93 ++++++++++++++++++++++++++---------
1 file changed, 70 insertions(+), 23 deletions(-)
diff --git a/tests/pfunct-btf-decl-tags.sh b/tests/pfunct-btf-decl-tags.sh
index 35884b4e8687..520148b2ccef 100755
--- a/tests/pfunct-btf-decl-tags.sh
+++ b/tests/pfunct-btf-decl-tags.sh
@@ -6,43 +6,60 @@
source test_lib.sh
outdir=$(make_tmpdir)
-tmpobj=$(make_tmpobj)
# Comment this out to save test data.
trap cleanup EXIT
title_log "Check that pfunct can print btf_decl_tags read from BTF."
-# gcc now also supports decl tags as of gcc commit 43dcea48b8c,
-# in upstream version 16.
-# UPTODO: add a check here for that.
+# gcc 16+ supports decl tags via DW_TAG_GNU_annotation (gcc commit ac7027f180b).
+GCC=${GCC:-gcc}
CLANG=${CLANG:-clang}
-if ! command -v $CLANG > /dev/null; then
- error_log "Need clang for test $0"
+
+use_gcc=0
+if command -v $GCC > /dev/null; then
+ gcc_ver=$($GCC -dumpversion 2>/dev/null | cut -d. -f1)
+ if [ "$gcc_ver" -ge 16 ] 2>/dev/null; then
+ use_gcc=1
+ fi
+fi
+
+use_clang=0
+if command -v $CLANG > /dev/null; then
+ use_clang=1
+fi
+
+if [ "$use_gcc" -eq 0 ] && [ "$use_clang" -eq 0 ]; then
+ error_log "Need gcc >= 16 or clang for test $0"
test_fail
fi
-(cat <<EOF
+src=$(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) {}
+void qux(int __tag(param_a) arg) {}
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;
+delete tags_arr;
+if (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;
+} else {
+ print \$0;
+}
}
EOF
)
@@ -51,19 +68,49 @@ expected=$(cat <<EOF
a b c void foo(void);
a b void bar(void);
a void buz(void);
+void qux(param_a int arg);
EOF
)
-out=$(pfunct -P -F btf $tmpobj | awk "$sort_tags" | sort)
-d=$(diff -u <(echo "$expected") <(echo "$out"))
+run_test() {
+ local compiler=$1
+ local tmpobj=$2
+
+ info_log "Testing with $compiler"
+ out=$(pfunct -P -F btf $tmpobj | awk "$sort_tags" | sort)
+ d=$(diff -u <(echo "$expected") <(echo "$out"))
+
+ if [[ "$d" == "" ]]; then
+ info_log " passed"
+ return 0
+ else
+ error_log "pfunct output does not match expected ($compiler):"
+ info_log "$d"
+ info_log
+ info_log "Complete output:"
+ info_log "$out"
+ return 1
+ fi
+}
+
+failed=0
+
+if [ "$use_gcc" -eq 1 ]; then
+ tmpobj=$(make_tmpobj)
+ echo "$src" | $GCC -c -g -x c -o $tmpobj - 2>/dev/null
+ pahole -J $tmpobj 2>/dev/null
+ run_test "$GCC (version $gcc_ver)" "$tmpobj" || failed=1
+fi
+
+if [ "$use_clang" -eq 1 ]; then
+ tmpobj=$(make_tmpobj)
+ echo "$src" | $CLANG -c -g -x c -o $tmpobj -
+ pahole -J $tmpobj 2>/dev/null
+ run_test "$CLANG" "$tmpobj" || failed=1
+fi
-if [[ "$d" == "" ]]; then
+if [ "$failed" -eq 0 ]; then
test_pass
else
- error_log "pfunct output does not match expected:"
- info_log "$d"
- info_log
- info_log "Complete output:"
- info_log "$out"
test_fail
fi
--
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 ` [PAHOLE v5 1/5] btf_loader: Handle decl tag component_idx for parameters Vineet Gupta
2026-06-18 4:46 ` 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 ` Vineet Gupta [this message]
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-5-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