Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The test uses `grep -q` which incorrectly matches section symbols in newer binutils, bypassing the check for the actual object symbol.
- [Medium] The test fixture uses a predictable, linear `static const int` array which the compiler can easily optimize away into arithmetic, causing a false test failure.
--
commit 5c5aee1d82edada34865ca44a6b863b5d7f437f3
Author: Puranjay Mohan [off-list ref]
objtool/klp: Add test for newly introduced data
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.
quoted hunk ↗ jump to hunk
diff --git a/tools/objtool/tests/generic/fixtures/new_data.c b/tools/objtool/tests/generic/fixtures/new_data.c
index 0000000000000..fa861fe813869
--- /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];
[Severity: Medium]
Can the compiler fold this array lookup into arithmetic? The predictable,
linear sequence of values here makes it a target for array-to-math
optimizations (e.g. GCC at -O2 might compile klp_new_data[x & 3] as
(x & 3) + 1).
If the compiler optimizes this away into scalar arithmetic, it would eliminate
the necessary relocation to klp_new_data in the target() function. Since
objtool klp diff relies on this relocation to pull in the variable,
eliminating it would cause the test to spuriously fail.
quoted hunk ↗ jump to hunk
+#else
+ return x;
+#endif
+}
diff --git a/tools/objtool/tests/generic/test-new-data.sh b/tools/objtool/tests/generic/test-new-data.sh
index 0000000000000..c7336752f09a8
--- /dev/null
+++ b/tools/objtool/tests/generic/test-new-data.sh
[ ... ]
quoted hunk ↗ jump to hunk
+run_diff
+
+assert_patched target
+out_symbols | grep -q 'klp_new_data' ||
+ fail "new data was not carried into the patch"
[Severity: Medium]
Will this test falsely pass if the actual object symbol is dropped but the
section is preserved?
This simple grep bypasses the symbol type check (OBJECT) and matches the
section symbol in newer binutils where readelf prints section names. If
grep -q incorrectly matches the section symbol (like .rodata.klp_new_data),
it would mask regressions in objtool's handling of the object symbol itself.
+
+pass "new data carried into the patch"
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914062514.926997-1-song@kernel.org?part=13