All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Khmelevskii <max@linux.ibm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org,
	Alan Maguire <alan.maguire@oracle.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH dwarves v1 2/2] tests: Add test for in-memory return values
Date: Sun, 22 Nov 2026 22:06:20 +0100	[thread overview]
Message-ID: <20261122210636.2896891-6-max@linux.ibm.com> (raw)
In-Reply-To: <20261122210636.2896891-4-max@linux.ibm.com>

Check that functions returning a value passed in memory have the
same signature in BTF and DWARF.

Signed-off-by: Maxim Khmelevskii <max@linux.ibm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com> 
---
 tests/ret_in_memory.sh | 113 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)
 create mode 100755 tests/ret_in_memory.sh

diff --git a/tests/ret_in_memory.sh b/tests/ret_in_memory.sh
new file mode 100755
index 0000000..a5faa98
--- /dev/null
+++ b/tests/ret_in_memory.sh
@@ -0,0 +1,113 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+source "$(dirname "$0")/test_lib.sh"
+
+outdir=$(make_tmpdir)
+
+# Comment this out to save test data.
+trap cleanup EXIT
+
+title_log "BTF encoding: functions returning values passed in memory"
+
+supported_arches=(
+	x86_64
+	aarch64
+	s390x
+)
+
+CC=${CC:-gcc}
+if ! command -v "${CC%% *}" > /dev/null 2>&1; then
+	info_log "skip: $CC not available"
+	test_skip
+fi
+
+arch=$(uname -m)
+if [[ " ${supported_arches[*]} " != *" $arch "* ]]; then
+	info_log "skip: test does not support $arch"
+	test_skip
+fi
+
+run_cmd()
+{
+	verbose_log "$1" >&2
+	eval "$1"
+}
+
+src="${outdir}/ret_in_memory"
+obj="${src}.o"
+btf="${src}.btf"
+
+cat > ${src}.c << EOF2
+typedef long long i64;
+struct s128 { i64 a, b; };
+
+__attribute__((noinline)) __int128 ret_i128(i64 x, i64 y)
+{
+	return (__int128)x * y;
+}
+
+__attribute__((noinline)) struct s128 ret_s128(i64 x, i64 y)
+{
+	struct s128 r = { x * y, x - y };
+	return r;
+}
+
+/* Check if DWARF abstract function works correctly */
+static struct s128 ret_origin(i64 x, i64 y)
+{
+	struct s128 r = { x, y };
+	return r;
+}
+struct s128 (*fp)(i64, i64) = ret_origin;
+
+__int128 gi;
+struct s128 gs;
+i64 xx, yy;
+
+void entry(void)
+{
+	gi = ret_i128(xx, yy);
+	gs = ret_s128(xx, yy);
+	gs = ret_origin(xx, yy);
+}
+EOF2
+
+if ! $CC -g -O2 -c -o $obj ${src}.c; then
+	error_log "$CC: could not compile ${src}.c"
+	test_fail
+fi
+
+info_log "Generate $(basename $btf)"
+if ! run_cmd "pahole -J --btf_encode_detached=$btf $obj"; then
+	error_log "could not encode BTF for $obj"
+	test_fail
+fi
+
+expected_functions=(
+	ret_i128
+	ret_s128
+	ret_origin
+)
+
+info_log "Check that each function in DWARF has a match in BTF"
+for fn in "${expected_functions[@]}"; do
+	# DWARF lists ret_origin() twice: the abstract and the concrete instance,
+	# because of that sort is needed.
+	dwarf_sig=$(run_cmd "pfunct -P $obj | grep ' ${fn}(' | sort -u")
+	btf_sig=$(run_cmd "pfunct -P --format_path=btf $btf | grep ' ${fn}('")
+	if [[ -z "$dwarf_sig" ]]; then
+		error_log "${fn}() missing from DWARF"
+		test_fail
+	fi
+	if [[ -z "$btf_sig" ]]; then
+		error_log "${fn}() missing from BTF"
+		test_fail
+	fi
+	if [[ "$btf_sig" != "$dwarf_sig" ]]; then
+		error_log "${fn}() BTF signature '$btf_sig' differs from DWARF '$dwarf_sig'"
+		test_fail
+	fi
+done
+
+test_pass
-- 
2.56.0


      parent reply	other threads:[~2026-11-22 21:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 21:06 [PATCH dwarves v1 0/2] Support in-memory return values for s390 Maxim Khmelevskii
2026-11-22 21:06 ` [PATCH dwarves v1 1/2] dwarf_loader: " Maxim Khmelevskii
2026-11-22 21:06 ` Maxim Khmelevskii [this message]

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=20261122210636.2896891-6-max@linux.ibm.com \
    --to=max@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=iii@linux.ibm.com \
    --cc=linux-debuggers@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.