[PATCH v2 13/58] objtool/klp: Add test for newly introduced data
From: Song Liu <song@kernel.org>
Date: 2026-09-14 06:26:39
Subsystem:
objtool, the rest · Maintainers:
Josh Poimboeuf, Peter Zijlstra, Linus Torvalds
From: Puranjay Mohan <puranjay@kernel.org> Adding data differs from changing it: nothing in the running kernel refers to a new variable, so it is safe and has to travel into the livepatch with the function using it. Signed-off-by: Puranjay Mohan <puranjay@kernel.org> Assisted-by: Claude:claude-opus-5 Signed-off-by: Song Liu <song@kernel.org> --- .../objtool/tests/generic/fixtures/new_data.c | 18 +++++++++++++ tools/objtool/tests/generic/test-new-data.sh | 26 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tools/objtool/tests/generic/fixtures/new_data.c create mode 100755 tools/objtool/tests/generic/test-new-data.sh
diff --git a/tools/objtool/tests/generic/fixtures/new_data.c b/tools/objtool/tests/generic/fixtures/new_data.c
new file mode 100644
index 000000000000..fa861fe81386
--- /dev/null
+++ b/tools/objtool/tests/generic/fixtures/new_data.c@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Data introduced by the patch. */ + +static const char __modinfo[] + __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux"; + +#ifdef PATCHED +static const int klp_new_data[4] __attribute__((used)) = { 1, 2, 3, 4 }; +#endif + +int target(int x) +{ +#ifdef PATCHED + return x + klp_new_data[x & 3]; +#else + return x; +#endif +}
diff --git a/tools/objtool/tests/generic/test-new-data.sh b/tools/objtool/tests/generic/test-new-data.sh
new file mode 100755
index 000000000000..c7336752f09a
--- /dev/null
+++ b/tools/objtool/tests/generic/test-new-data.sh@@ -0,0 +1,26 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Data added by the patch has no counterpart in the running kernel and must be +# carried into the livepatch. + +. "$(dirname "$0")/../lib.sh" + +setup +build_pair new_data.c + +# State the premise on both sides. The array is new in the patched build and +# absent from the original; if the compiler folded it into the code instead of +# emitting it, the assertion below would fail without saying why. +has_input_symbol "$orig_obj" klp_new_data && + fail "fixture put klp_new_data in the original; nothing new to carry" +has_input_symbol "$patched_obj" klp_new_data || + fail "compiler did not emit klp_new_data; the fixture tests nothing" + +run_diff + +assert_patched target +out_symbols | grep -q 'klp_new_data' || + fail "new data was not carried into the patch" + +pass "new data carried into the patch"
--
2.53.0-Meta