xref: /linux/tools/objtool/tests/generic/fixtures/data_alignment.c (revision 8abe5c94bfeb9bb5cf02fa17a9337d2d7bbade75)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Data with an alignment stricter than its size.
4  *
5  * A cloned data section has to keep its sh_addralign.  The kernel has plenty
6  * of data whose alignment is a correctness property rather than an
7  * optimisation -- per-CPU variables, anything touched by an aligned SSE move,
8  * cacheline-aligned locks -- and a clone that lands under-aligned faults or
9  * silently shares a cacheline it was written to avoid.
10  *
11  * The object is new in the patched build, so klp diff has to clone it rather
12  * than reference the kernel's copy.
13  */
14 
15 static const char __modinfo[]
16 	__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
17 
18 #ifdef PATCHED
19 int aligned_data[2] __attribute__((aligned(64))) = { 1, 2 };
20 #endif
21 
22 int target(int x)
23 {
24 #ifdef PATCHED
25 	return x + aligned_data[0];
26 #else
27 	return x;
28 #endif
29 }
30