# Re: \[PATCH v2 13/58\] objtool/klp: Add test for newly introduced data

- From: Song Liu \<song@kernel.org\>
- Date: 2026-09-14 20:47:38 
- List: live-patching
- Page: https://ratatoskr.run/live-patching/2026/09/17575625
- Thread: https://ratatoskr.run/sashiko-reviews/2026/09/17575625/t.md

```text
On Sun, Sep 13, 2026 at 11:38 PM [ref] wrote:
>
> 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 [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.
>
> > 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.

This doesn't seem to happen, but fixed in v3 with something like:

klp_new_data[4] = { 7, 3, 11, 5 };

Also added a check if klp_new_data doesn't exist.

>
> > +#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
>
> [ ... ]
>
> > +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?
>
Replaced this with "assert_symbol klp_new_data".

Thanks,
Song
```
