1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Two translation units with a same-named static, placed so that the linker
4 * puts them in the opposite order to the one they appear in the symbol table.
5 *
6 * VARSEC selects the section the static lands in. Linking with
7 * --sort-section=name then orders them alphabetically rather than by object
8 * order, so the first symbol in the symbol table ends up at the *higher*
9 * address. That is the whole point: counting symbol table order and reading
10 * the linked image's addresses now give different answers, which is what makes
11 * it possible to tell which one klp diff used.
12 *
13 * Only use_a is patched, so exactly one sympos is emitted and there is nothing
14 * to attribute.
15 */
16
17 #ifndef FUNC_NAME
18 #define FUNC_NAME use_a
19 #endif
20 #ifndef VARSEC
21 #define VARSEC ".data.mmm"
22 #endif
23
24 #ifndef NO_MODINFO
25 static const char __modinfo[]
26 __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
27 #endif
28
29 /* volatile so it survives as an STT_OBJECT rather than being folded away */
30 static volatile int dup_counter __attribute__((section(VARSEC))) = 1;
31
FUNC_NAME(int x)32 int FUNC_NAME(int x)
33 {
34 dup_counter += x;
35 #ifdef PATCHED
36 return dup_counter + 1;
37 #else
38 return dup_counter;
39 #endif
40 }
41