xref: /linux/tools/objtool/tests/generic/fixtures/sympos_dup.c (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * A static whose name recurs in every translation unit that includes it.
4  * Compiled once for a single-copy object and twice, partially linked, for one
5  * with duplicates -- which is the only case where sympos is non-zero.
6  *
7  * FUNC_NAME keeps the referencing functions distinct so both get patched.
8  * Only the first copy carries .modinfo; two would be a second thing to
9  * disambiguate and is not what this fixture is about.
10  */
11 
12 #ifndef FUNC_NAME
13 #define FUNC_NAME use_a
14 #endif
15 
16 #ifndef NO_MODINFO
17 static const char __modinfo[]
18 	__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
19 #endif
20 
21 /* volatile so it survives as an STT_OBJECT rather than being folded away */
22 static volatile int dup_counter = 1;
23 
FUNC_NAME(int x)24 int FUNC_NAME(int x)
25 {
26 	dup_counter += x;
27 #ifdef PATCHED
28 	return dup_counter + 1;
29 #else
30 	return dup_counter;
31 #endif
32 }
33