xref: /linux/tools/objtool/tests/generic/fixtures/new_export_ref.c (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*6549ce0dSSong Liu // SPDX-License-Identifier: GPL-2.0
2*6549ce0dSSong Liu /*
3*6549ce0dSSong Liu  * A reference which only exists in the patched build.  The symbol has no twin
4*6549ce0dSSong Liu  * in the original object, so what klp diff may do with it depends entirely on
5*6549ce0dSSong Liu  * whether Module.symvers says it is exported, and by what.
6*6549ce0dSSong Liu  */
7*6549ce0dSSong Liu 
8*6549ce0dSSong Liu static const char __modinfo[]
9*6549ce0dSSong Liu 	__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
10*6549ce0dSSong Liu 
11*6549ce0dSSong Liu extern int newly_referenced(int x);
12*6549ce0dSSong Liu 
13*6549ce0dSSong Liu /*
14*6549ce0dSSong Liu  * A reference both builds have.  When Module.symvers says a module exports
15*6549ce0dSSong Liu  * this one, the original already depends on that module, which is what makes
16*6549ce0dSSong Liu  * a new reference to it safe -- the loader will not let the patched module
17*6549ce0dSSong Liu  * load without it.  EXISTING_DEP leaves it out, for the case where there is
18*6549ce0dSSong Liu  * no such dependency to inherit.
19*6549ce0dSSong Liu  */
20*6549ce0dSSong Liu extern int existing_dep(int x);
21*6549ce0dSSong Liu 
target(int x)22*6549ce0dSSong Liu int target(int x)
23*6549ce0dSSong Liu {
24*6549ce0dSSong Liu #ifdef EXISTING_DEP
25*6549ce0dSSong Liu 	int base = existing_dep(x);
26*6549ce0dSSong Liu #else
27*6549ce0dSSong Liu 	int base = x;
28*6549ce0dSSong Liu #endif
29*6549ce0dSSong Liu 
30*6549ce0dSSong Liu #ifdef PATCHED
31*6549ce0dSSong Liu 	return newly_referenced(base);
32*6549ce0dSSong Liu #else
33*6549ce0dSSong Liu 	return base + 1;
34*6549ce0dSSong Liu #endif
35*6549ce0dSSong Liu }
36