xref: /linux/arch/x86/include/asm/linkage.h (revision f2527d8f566a45fa00ee5abd04d1c9476d4d704f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_LINKAGE_H
3 #define _ASM_X86_LINKAGE_H
4 
5 #include <linux/stringify.h>
6 #include <asm/ibt.h>
7 
8 #undef notrace
9 #define notrace __attribute__((no_instrument_function))
10 
11 #ifdef CONFIG_X86_32
12 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
13 #endif /* CONFIG_X86_32 */
14 
15 #define __ALIGN		.balign CONFIG_FUNCTION_ALIGNMENT, 0x90;
16 #define __ALIGN_STR	__stringify(__ALIGN)
17 
18 #if defined(CONFIG_CALL_PADDING) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
19 #define FUNCTION_PADDING	.skip CONFIG_FUNCTION_ALIGNMENT, 0x90;
20 #else
21 #define FUNCTION_PADDING
22 #endif
23 
24 #if (CONFIG_FUNCTION_ALIGNMENT > 8) && !defined(__DISABLE_EXPORTS) && !defined(BULID_VDSO)
25 # define __FUNC_ALIGN		__ALIGN; FUNCTION_PADDING
26 #else
27 # define __FUNC_ALIGN		__ALIGN
28 #endif
29 
30 #define ASM_FUNC_ALIGN		__stringify(__FUNC_ALIGN)
31 #define SYM_F_ALIGN		__FUNC_ALIGN
32 
33 #ifdef __ASSEMBLY__
34 
35 #if defined(CONFIG_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
36 #define RET	jmp __x86_return_thunk
37 #else /* CONFIG_RETPOLINE */
38 #ifdef CONFIG_SLS
39 #define RET	ret; int3
40 #else
41 #define RET	ret
42 #endif
43 #endif /* CONFIG_RETPOLINE */
44 
45 #else /* __ASSEMBLY__ */
46 
47 #if defined(CONFIG_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
48 #define ASM_RET	"jmp __x86_return_thunk\n\t"
49 #else /* CONFIG_RETPOLINE */
50 #ifdef CONFIG_SLS
51 #define ASM_RET	"ret; int3\n\t"
52 #else
53 #define ASM_RET	"ret\n\t"
54 #endif
55 #endif /* CONFIG_RETPOLINE */
56 
57 #endif /* __ASSEMBLY__ */
58 
59 /*
60  * Depending on -fpatchable-function-entry=N,N usage (CONFIG_CALL_PADDING) the
61  * CFI symbol layout changes.
62  *
63  * Without CALL_THUNKS:
64  *
65  * 	.align	FUNCTION_ALIGNMENT
66  * __cfi_##name:
67  * 	.skip	FUNCTION_PADDING, 0x90
68  * 	.byte   0xb8
69  * 	.long	__kcfi_typeid_##name
70  * name:
71  *
72  * With CALL_THUNKS:
73  *
74  * 	.align FUNCTION_ALIGNMENT
75  * __cfi_##name:
76  * 	.byte	0xb8
77  * 	.long	__kcfi_typeid_##name
78  * 	.skip	FUNCTION_PADDING, 0x90
79  * name:
80  *
81  * In both cases the whole thing is FUNCTION_ALIGNMENT aligned and sized.
82  */
83 
84 #ifdef CONFIG_CALL_PADDING
85 #define CFI_PRE_PADDING
86 #define CFI_POST_PADDING	.skip	CONFIG_FUNCTION_PADDING_BYTES, 0x90;
87 #else
88 #define CFI_PRE_PADDING		.skip	CONFIG_FUNCTION_PADDING_BYTES, 0x90;
89 #define CFI_POST_PADDING
90 #endif
91 
92 #define __CFI_TYPE(name)					\
93 	SYM_START(__cfi_##name, SYM_L_LOCAL, SYM_A_NONE)	\
94 	CFI_PRE_PADDING						\
95 	.byte 0xb8 ASM_NL					\
96 	.long __kcfi_typeid_##name ASM_NL			\
97 	CFI_POST_PADDING					\
98 	SYM_FUNC_END(__cfi_##name)
99 
100 /* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
101 #define SYM_TYPED_FUNC_START(name)				\
102 	SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)	\
103 	ENDBR
104 
105 /* SYM_FUNC_START -- use for global functions */
106 #define SYM_FUNC_START(name)				\
107 	SYM_START(name, SYM_L_GLOBAL, SYM_F_ALIGN)	\
108 	ENDBR
109 
110 /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
111 #define SYM_FUNC_START_NOALIGN(name)			\
112 	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)	\
113 	ENDBR
114 
115 /* SYM_FUNC_START_LOCAL -- use for local functions */
116 #define SYM_FUNC_START_LOCAL(name)			\
117 	SYM_START(name, SYM_L_LOCAL, SYM_F_ALIGN)	\
118 	ENDBR
119 
120 /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
121 #define SYM_FUNC_START_LOCAL_NOALIGN(name)		\
122 	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)	\
123 	ENDBR
124 
125 /* SYM_FUNC_START_WEAK -- use for weak functions */
126 #define SYM_FUNC_START_WEAK(name)			\
127 	SYM_START(name, SYM_L_WEAK, SYM_F_ALIGN)	\
128 	ENDBR
129 
130 /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
131 #define SYM_FUNC_START_WEAK_NOALIGN(name)		\
132 	SYM_START(name, SYM_L_WEAK, SYM_A_NONE)		\
133 	ENDBR
134 
135 #endif /* _ASM_X86_LINKAGE_H */
136 
137