xref: /linux/tools/objtool/tests/x86/fixtures/static_call_no_key.c (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*841c8c57SSong Liu // SPDX-License-Identifier: GPL-2.0
2*841c8c57SSong Liu /*
3*841c8c57SSong Liu  * A static call to a trampoline whose key symbol this object cannot see.
4*841c8c57SSong Liu  *
5*841c8c57SSong Liu  * That is the normal situation for a module: __SCK__* keys are not exported,
6*841c8c57SSong Liu  * and read-only access is granted at load time instead.  objtool's static call
7*841c8c57SSong Liu  * handling has to accept it for any module, including a livepatch module built
8*841c8c57SSong Liu  * by hand rather than by klp-build.
9*841c8c57SSong Liu  *
10*841c8c57SSong Liu  * LIVEPATCH adds the .modinfo tag which makes objtool treat this as a
11*841c8c57SSong Liu  * livepatch module.
12*841c8c57SSong Liu  */
13*841c8c57SSong Liu 
14*841c8c57SSong Liu static const char __modinfo[]
15*841c8c57SSong Liu 	__attribute__((section(".modinfo"), used, aligned(1))) =
16*841c8c57SSong Liu #ifdef LIVEPATCH
17*841c8c57SSong Liu 	"\0livepatch=Y"
18*841c8c57SSong Liu #endif
19*841c8c57SSong Liu 	"\0name=klp_testmod";
20*841c8c57SSong Liu 
21*841c8c57SSong Liu /*
22*841c8c57SSong Liu  * The trampoline is undefined here, exactly as it is for a module calling a
23*841c8c57SSong Liu  * static call defined in vmlinux.  No __SCK__klp_test_call accompanies it.
24*841c8c57SSong Liu  */
25*841c8c57SSong Liu extern void __SCT__klp_test_call(void);
26*841c8c57SSong Liu 
target(int x)27*841c8c57SSong Liu int target(int x)
28*841c8c57SSong Liu {
29*841c8c57SSong Liu 	__asm__ volatile("call __SCT__klp_test_call\n\t" ::: "memory");
30*841c8c57SSong Liu 
31*841c8c57SSong Liu 	return x + 1;
32*841c8c57SSong Liu }
33