[tip: objtool/core] objtool/klp: Add test for changed functions without an ftrace call site
From: tip-bot2 for Puranjay Mohan
Date: Wed Nov 25 2026 - 03:41:05 EST
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 94877d50b89cf6a579e406581db7805ec6b8ad58
Gitweb: https://git.kernel.org/tip/94877d50b89cf6a579e406581db7805ec6b8ad58
Author: Puranjay Mohan <puranjay@xxxxxxxxxx>
AuthorDate: Thu, 22 Oct 2026 10:16:36 -07:00
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Sat, 21 Nov 2026 23:38:32 -08:00
objtool/klp: Add test for changed functions without an ftrace call site
Test that klp diff rejects a changed function without an ftrace call
site, both a notrace one and an inline one emitted out of line, and
reports each of them. Also test that a fully inlined function and an
ordinary function can still be patched.
Signed-off-by: Puranjay Mohan <puranjay@xxxxxxxxxx>
Acked-by: Joe Lawrence <joe.lawrence@xxxxxxxxxx>
Acked-by: Song Liu <song@xxxxxxxxxx>
Link: https://patch.msgid.link/20261022171637.3298443-4-puranjay@xxxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
tools/objtool/tests/x86/fixtures/notrace_target.c | 71 +++++++++++++-
tools/objtool/tests/x86/test-notrace-target.sh | 74 ++++++++++++++-
2 files changed, 145 insertions(+)
create mode 100644 tools/objtool/tests/x86/fixtures/notrace_target.c
create mode 100755 tools/objtool/tests/x86/test-notrace-target.sh
diff --git a/tools/objtool/tests/x86/fixtures/notrace_target.c b/tools/objtool/tests/x86/fixtures/notrace_target.c
new file mode 100644
index 0000000..64da58c
--- /dev/null
+++ b/tools/objtool/tests/x86/fixtures/notrace_target.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+/* PATCH_<name> changes <name> in the patched build. */
+#define notrace __attribute__((__no_instrument_function__))
+
+static const char __modinfo[]
+ __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
+
+#ifndef PATCHED
+#undef PATCH_OUTLINED
+#undef PATCH_NOTRACE
+#undef PATCH_INLINED
+#undef PATCH_TRACED
+#endif
+
+#ifdef PATCH_OUTLINED
+#define OUTLINED_K 2
+#else
+#define OUTLINED_K 1
+#endif
+
+#ifdef PATCH_NOTRACE
+#define NOTRACE_K 2
+#else
+#define NOTRACE_K 1
+#endif
+
+#ifdef PATCH_INLINED
+#define INLINED_K 2
+#else
+#define INLINED_K 1
+#endif
+
+#ifdef PATCH_TRACED
+#define TRACED_K 2
+#else
+#define TRACED_K 1
+#endif
+
+int sink;
+
+/* Address taken, so emitted out of line. */
+static inline notrace int outlined(int x)
+{
+ int i;
+
+ for (i = 0; i < x; i++)
+ sink += i * OUTLINED_K;
+ return sink;
+}
+
+int (*outlined_ptr)(int) = outlined;
+
+notrace int notrace_fn(int x)
+{
+ return x * 3 + NOTRACE_K;
+}
+
+static inline int inlined(int x)
+{
+ return x + INLINED_K;
+}
+
+int inlined_user(int x)
+{
+ return inlined(x) * 5;
+}
+
+int traced(int x)
+{
+ return x * 7 + TRACED_K;
+}
diff --git a/tools/objtool/tests/x86/test-notrace-target.sh b/tools/objtool/tests/x86/test-notrace-target.sh
new file mode 100755
index 0000000..09414ae
--- /dev/null
+++ b/tools/objtool/tests/x86/test-notrace-target.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# A changed function without an ftrace call site can't be livepatched:
+# klp_enable_patch() fails with "failed to find location for function".
+# klp diff must reject it instead.
+
+. "$(dirname "$0")/../lib.sh"
+
+# mcount_entry <function>: orig.o has an __mcount_loc entry for it.
+mcount_entry()
+{
+ in_relocs "$orig_obj" | awk '/rela__mcount_loc/,/^$/' |
+ awk -v f="$1" '$5 == f || $5 == ".text." f' | grep -q .
+}
+
+# check <expected exit status> <-DPATCH_... flags>
+check()
+{
+ local expect="$1"; shift
+
+ setup
+ build_pair notrace_target.c "$@"
+
+ assert_input_symbol outlined
+ assert_input_symbol notrace_fn
+ has_input_symbol "$orig_obj" inlined &&
+ fail "inlined() was emitted out of line; the fixture tests nothing"
+ mcount_entry traced ||
+ fail "no __mcount_loc entry for traced(); the fixture tests nothing"
+ mcount_entry inlined_user ||
+ fail "no __mcount_loc entry for inlined_user(); the fixture tests nothing"
+ mcount_entry outlined &&
+ fail "outlined() has a __mcount_loc entry; it should be notrace"
+ mcount_entry notrace_fn &&
+ fail "notrace_fn() has a __mcount_loc entry; it should be notrace"
+
+ run_diff "$expect"
+}
+
+rejected()
+{
+ local n
+
+ n="$(diff_log | grep -c "error: objtool: $1: no ftrace call site, can't patch")"
+ [ "$n" = 1 ] ||
+ fail "expected '$1' rejected once, found $n: $(diff_log | tail -2)"
+}
+
+check 255 -DPATCH_OUTLINED
+rejected outlined
+cleanup
+
+check 255 -DPATCH_NOTRACE
+rejected notrace_fn
+cleanup
+
+check 255 -DPATCH_OUTLINED -DPATCH_NOTRACE
+rejected outlined
+rejected notrace_fn
+cleanup
+
+# Fully inlined: the traceable caller gets patched.
+check 0 -DPATCH_INLINED
+assert_patched inlined_user
+assert_not_patched traced
+cleanup
+
+check 0 -DPATCH_TRACED
+assert_patched traced
+assert_not_patched inlined_user
+cleanup
+
+pass "changed function without an ftrace call site rejected"