All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Alan Maguire <alan.maguire@oracle.com>,
	Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	dwarves@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH dwarves 2/2] tests: Add test for parameters described by entry values
Date: Fri, 25 Sep 2026 14:36:24 -0700	[thread overview]
Message-ID: <20260925213624.2188373-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20260925213619.2187751-1-yonghong.song@linux.dev>

Cover the case where clang leaves the entry PC out of a parameter's
location list because the parameter is moved into a callee-saved register
during the prologue.  f_lazy() reproduces the shape found in the kernel:
@lazy arrives in RSI, the first location list entry starts past the
function entry and names the callee-saved register, and only the
DW_OP_entry_value entries name RSI.

Without the entry value being preferred, @lazy looks like it is in an
unexpected register and f_lazy() is dropped from BTF altogether.

The test results on x86_64:
  $ VERBOSE=1 ./clang_parm_entry_value.sh
  Validation of BTF encoding of parameters described by entry values.
     BTF: bool f_lazy(struct task * p, bool lazy, const struct aux  * aux);
  Test ./clang_parm_entry_value.sh passed

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
 tests/clang_parm_entry_value.sh | 84 +++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100755 tests/clang_parm_entry_value.sh

diff --git a/tests/clang_parm_entry_value.sh b/tests/clang_parm_entry_value.sh
new file mode 100755
index 0000000..9fe81a7
--- /dev/null
+++ b/tests/clang_parm_entry_value.sh
@@ -0,0 +1,84 @@
+#!/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 "Validation of BTF encoding of parameters described by entry values."
+
+entry_value="${outdir}/entry_value"
+CC=$(which clang 2>/dev/null)
+
+if [[ -z "$CC" ]]; then
+	info_log "skip: clang not available"
+	test_skip
+fi
+
+arch=$(uname -m)
+if [[ "$arch" != "x86_64" ]]; then
+	info_log "skip: test is x86_64 only, running on $arch"
+	test_skip
+fi
+
+# clang can leave the entry PC out of a parameter's location list when the
+# parameter is moved into a callee-saved register during the prologue.  The
+# first location list entry then names that callee-saved register rather than
+# the ABI argument register, and only the DW_OP_entry_value entries tell which
+# argument register the parameter really arrived in.  pahole has to use the
+# entry value, otherwise the parameter looks like it is in an unexpected
+# register and the whole function is dropped from BTF.
+cat > ${entry_value}.c << EOF
+typedef _Bool bool;
+struct sched;
+struct aux;
+struct task { long a; bool lazy; };
+
+extern struct sched *get_sched(const struct aux *aux);
+extern void rcu_lock(void);
+extern void rcu_unlock(void);
+extern int on_sched(struct sched *s, struct task *p);
+
+__attribute__((noinline)) bool f_lazy(struct task *p, bool lazy, const struct aux *aux)
+{
+	struct sched *sch;
+
+	rcu_lock();
+	sch = get_sched(aux);
+	if (__builtin_expect(!(sch && on_sched(sch, p)), 0)) {
+		rcu_unlock();
+		return 0;
+	}
+	__atomic_store_n(&p->lazy, lazy, __ATOMIC_RELAXED);
+	rcu_unlock();
+	return 1;
+}
+
+bool (*keep[])() = { (bool(*)())f_lazy };
+EOF
+
+${CC} -g -O2 -c -o ${entry_value}.o ${entry_value}.c 2>/dev/null
+if [[ $? -ne 0 ]]; then
+	info_log "skip: clang could not compile ${entry_value}.c"
+	test_skip
+fi
+
+LLVM_OBJCOPY=objcopy pahole -J --btf_features=consistent_func ${entry_value}.o
+if [[ $? -ne 0 ]]; then
+	error_log "Could not encode BTF for ${entry_value}.o"
+	test_fail
+fi
+
+encoded=$(pfunct --all --format_path=btf ${entry_value}.o | grep " f_lazy(")
+if [[ -n "$VERBOSE" ]]; then
+	printf "   BTF: %s\n" "$encoded"
+fi
+if [[ -z "$encoded" ]]; then
+	error_log "f_lazy() is missing from BTF"
+	test_fail
+fi
+
+test_pass
-- 
2.53.0-Meta


  reply	other threads:[~2026-09-25 21:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 21:36 [PATCH dwarves 1/2] dwarf_loader: Trust the entry value register over the first location entry Yonghong Song
2026-09-25 21:36 ` Yonghong Song [this message]
2026-09-26  7:45 ` Alexei Starovoitov
2026-09-27  5:49   ` Yonghong Song
2026-09-27  8:37     ` Tejun Heo
2026-09-29  6:11     ` Alexei Starovoitov
2026-09-29 17:59       ` Yonghong Song

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=20260925213624.2188373-1-yonghong.song@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=kernel-team@fb.com \
    /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.