From: Alan Maguire <alan.maguire@oracle.com>
To: acme@kernel.org, ast@kernel.org, andrii@kernel.org,
eddyz87@gmail.com, qmo@kernel.org
Cc: dwarves@vger.kernel.org, jolsa@kernel.org, daniel@iogearbox.net,
ihor.solodrai@linux.dev, yonghong.song@linux.dev,
song@kernel.org, martin.lau@linux.dev, memxor@gmail.com,
emil@etsalapatis.com, bpf@vger.kernel.org, nsc@kernel.org,
puranjay@kernel.org, yatsenko@meta.com,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH v3 dwarves 8/9] tests: Validate inline BTF encoding
Date: Fri, 25 Sep 2026 19:51:57 +0100 [thread overview]
Message-ID: <20260925185200.1318067-9-alan.maguire@oracle.com> (raw)
In-Reply-To: <20260925185200.1318067-1-alan.maguire@oracle.com>
Exercise nested inline calls, constant arguments, no-argument inline
functions, and repeated inline call sites. Verify that ordinary wrapper
function BTF remains present, inline functions are annotated by pfunct,
and when bpftool is available, LOCSEC contains multiple inline sites.
Also verify that pfunct:
- lists the ordinary and inline BTF functions;
- prints inline-site parameter locations from detached raw BTF using
the regN fallback;
- uses an explicitly supplied ELF file to resolve register names and
containing functions; and
- automatically uses ELF information when BTF is embedded in the ELF.
Use a single-register inline parameter rather than asserting ABI-specific
register numbers or aggregate calling conventions, allowing the test to
run across supported architectures.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Assisted-by: Codex (GPT-5.6)
---
tests/btf_inline.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
create mode 100755 tests/btf_inline.sh
diff --git a/tests/btf_inline.sh b/tests/btf_inline.sh
new file mode 100755
index 0000000..a782a65
--- /dev/null
+++ b/tests/btf_inline.sh
@@ -0,0 +1,147 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+script_dir=$(dirname "$0")
+source "$script_dir/test_lib.sh"
+
+outdir=$(make_tmpdir)
+trap cleanup EXIT
+
+title_log "Validation of additive inline BTF encoding."
+
+CC=${CC:-gcc}
+if ! command -v "$CC" >/dev/null 2>&1; then
+ info_log "skip: gcc not available"
+ test_skip
+fi
+
+if ! pahole --supported_btf_features | tr ',' '\n' | grep -Fxq inline; then
+ info_log "skip: pahole was built without BTF location support"
+ test_skip
+fi
+
+src=${outdir}/btf_inline.c
+obj=${outdir}/btf_inline
+btf=${outdir}/btf_inline.btf
+
+cat > "$src" <<'EOF'
+/* Keep the inline functions small enough to guarantee inlining at -O2. */
+static inline int scale(int value, int factor)
+{
+ return value * factor;
+}
+
+static inline int add_bias(int value, int bias)
+{
+ return scale(value, 2) + bias;
+}
+
+static volatile int inline_bias;
+
+static inline int add_global(void)
+{
+ return inline_bias;
+}
+
+static inline int combine(int value, int bias)
+{
+ return add_bias(value, bias) + add_global();
+}
+
+__attribute__((noinline)) int wrapper_once(int value, int bias)
+{
+ return combine(value, bias);
+}
+
+__attribute__((noinline)) int wrapper_twice(int value, int bias)
+{
+ return combine(value, bias) + combine(bias, value);
+}
+
+int main(void)
+{
+ return wrapper_once(1, 3) + wrapper_twice(2, 4);
+}
+EOF
+
+"$CC" -g -O2 -o "$obj" "$src"
+if [[ $? -ne 0 ]]; then
+ error_log "Could not compile $src"
+ test_fail
+fi
+
+if ! pahole --btf_features=default,inline --btf_encode_detached="$btf" "$obj"; then
+ error_log "Could not encode inline BTF for $obj"
+ test_fail
+fi
+
+# Inline location BTF augments the ordinary BTF_KIND_FUNC records for the
+# non-inline wrappers. It must cover nested calls, a constant parameter, a
+# no-argument inline function, and multiple call sites of the same inline.
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "int wrapper_once(int value, int bias);"; then
+ error_log "wrapper_once() is missing from inline BTF"
+ test_fail
+fi
+
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "int wrapper_twice(int value, int bias);"; then
+ error_log "wrapper_twice() is missing from inline BTF"
+ test_fail
+fi
+
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "inline int scale(int value, int factor);"; then
+ error_log "scale() inline location is missing from BTF"
+ test_fail
+fi
+
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "inline int add_bias(int value, int bias);"; then
+ error_log "add_bias() inline location is missing from BTF"
+ test_fail
+fi
+
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "inline int add_global(void);"; then
+ error_log "add_global() inline location is missing from BTF"
+ test_fail
+fi
+
+if ! pfunct --all --format_path=btf "$btf" 2>/dev/null | grep -Fq "inline int combine(int value, int bias);"; then
+ error_log "combine() inline location is missing from BTF"
+ test_fail
+fi
+
+if ! inline_sites=$(pfunct --inline_sites "$btf" 2>/dev/null) ||
+ ! grep -Eq 'scale\(int value \[reg[0-9]+\], int factor \[const 0x2\]\)' <<<"$inline_sites"; then
+ error_log "pfunct did not render a fallback register name for an inline parameter"
+ test_fail
+fi
+
+if ! inline_sites=$(pfunct --inline_sites --elf "$obj" "$btf" 2>/dev/null) ||
+ ! grep -Eq 'scale\(int value \[[^][,[:space:]]+\], int factor \[const 0x2\]\)' <<<"$inline_sites" ||
+ grep -Eq 'scale\(int value \[reg[0-9]+\], int factor \[const 0x2\]\)' <<<"$inline_sites" ||
+ ! grep -Eq '\[wrapper_once\+0x[0-9a-f]+, ' <<<"$inline_sites"; then
+ error_log "pfunct did not resolve inline-site registers and containing functions through ELF"
+ test_fail
+fi
+
+if command -v bpftool >/dev/null 2>&1; then
+ locsec_vlen=$(bpftool btf dump file "$btf" format raw 2>/dev/null |
+ sed -n 's/.*LOCSEC .*vlen=\([0-9][0-9]*\).*/\1/p')
+ if [[ -z "$locsec_vlen" || "$locsec_vlen" -lt 2 ]]; then
+ error_log "multiple inline call sites are missing from LOCSEC"
+ test_fail
+ fi
+fi
+
+if ! pahole -J --btf_features=default,inline "$obj"; then
+ error_log "Could not encode embedded inline BTF for $obj"
+ test_fail
+fi
+
+if ! inline_sites=$(pfunct --inline_sites "$obj" 2>/dev/null) ||
+ ! grep -Eq 'scale\(int value \[[^][,[:space:]]+\], int factor \[const 0x2\]\)' <<<"$inline_sites" ||
+ grep -Eq 'scale\(int value \[reg[0-9]+\], int factor \[const 0x2\]\)' <<<"$inline_sites" ||
+ ! grep -Eq '\[wrapper_once\+0x[0-9a-f]+, ' <<<"$inline_sites"; then
+ error_log "pfunct did not resolve inline-site registers and containing functions from embedded ELF BTF"
+ test_fail
+fi
+
+test_pass
--
2.43.5
next prev parent reply other threads:[~2026-09-25 18:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 18:51 [PATCH v3 dwarves 0/9] Encoding of inline functions using BTF Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 1/9] dwarf_loader: Add parameter list to inlined expansions Alan Maguire
2026-09-30 15:45 ` Jiri Olsa
2026-10-02 11:02 ` Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 2/9] dwarf_loader: Resolve inline expansion names during recoding Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 3/9] dwarf_loader: Collect inline expansion location data Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 4/9] pahole: Support inline BTF location encoding Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 5/9] btf_loader: Add "inline" annotation for inlined functions Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 6/9] btf_loader: Record inline sites in CU for BTF Alan Maguire
2026-09-25 18:51 ` [PATCH v3 dwarves 7/9] pfunct: Print inline site information Alan Maguire
2026-09-25 18:51 ` Alan Maguire [this message]
2026-09-25 18:51 ` [PATCH v3 dwarves 9/9] man-pages: Document --inline_sites option Alan Maguire
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=20260925185200.1318067-9-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nsc@kernel.org \
--cc=puranjay@kernel.org \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--cc=yatsenko@meta.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