Linux 6.16-rc6
[linux-block.git] / arch / x86 / include / asm / linkage.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1965aae3
PA
2#ifndef _ASM_X86_LINKAGE_H
3#define _ASM_X86_LINKAGE_H
82f74e71 4
bb7f5f6c 5#include <linux/stringify.h>
c4691712 6#include <asm/ibt.h>
bb7f5f6c 7
78a9909a
IM
8#undef notrace
9#define notrace __attribute__((no_instrument_function))
10
25e73b7e
PZ
11#ifdef CONFIG_64BIT
12/*
13 * The generic version tends to create spurious ENDBR instructions under
14 * certain conditions.
15 */
16#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
17#endif
18
96a388de 19#ifdef CONFIG_X86_32
82f74e71 20#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
7ab15247
CG
21#endif /* CONFIG_X86_32 */
22
d49a0626 23#define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT, 0x90;
bb7f5f6c 24#define __ALIGN_STR __stringify(__ALIGN)
82f74e71 25
931ab636 26#if defined(CONFIG_CALL_PADDING) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
bea75b33
TG
27#define FUNCTION_PADDING .skip CONFIG_FUNCTION_ALIGNMENT, 0x90;
28#else
29#define FUNCTION_PADDING
30#endif
31
7324f74d 32#if (CONFIG_FUNCTION_ALIGNMENT > 8) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
bea75b33
TG
33# define __FUNC_ALIGN __ALIGN; FUNCTION_PADDING
34#else
35# define __FUNC_ALIGN __ALIGN
36#endif
37
38#define ASM_FUNC_ALIGN __stringify(__FUNC_ALIGN)
8eb5d34e
TG
39#define SYM_F_ALIGN __FUNC_ALIGN
40
24a295e4 41#ifdef __ASSEMBLER__
8eb5d34e 42
0911b8c5 43#if defined(CONFIG_MITIGATION_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
aa3d4803 44#define RET jmp __x86_return_thunk
aefb2f2e 45#else /* CONFIG_MITIGATION_RETPOLINE */
7b75782f 46#ifdef CONFIG_MITIGATION_SLS
e463a09a
PZ
47#define RET ret; int3
48#else
49#define RET ret
50#endif
aefb2f2e 51#endif /* CONFIG_MITIGATION_RETPOLINE */
e463a09a 52
24a295e4 53#else /* __ASSEMBLER__ */
b17c2baa 54
0911b8c5 55#if defined(CONFIG_MITIGATION_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
aa3d4803 56#define ASM_RET "jmp __x86_return_thunk\n\t"
aefb2f2e 57#else /* CONFIG_MITIGATION_RETPOLINE */
7b75782f 58#ifdef CONFIG_MITIGATION_SLS
e463a09a
PZ
59#define ASM_RET "ret; int3\n\t"
60#else
b17c2baa 61#define ASM_RET "ret\n\t"
e463a09a 62#endif
aefb2f2e 63#endif /* CONFIG_MITIGATION_RETPOLINE */
b17c2baa 64
24a295e4 65#endif /* __ASSEMBLER__ */
7ab15247 66
bea75b33 67/*
931ab636 68 * Depending on -fpatchable-function-entry=N,N usage (CONFIG_CALL_PADDING) the
bea75b33
TG
69 * CFI symbol layout changes.
70 *
71 * Without CALL_THUNKS:
72 *
73 * .align FUNCTION_ALIGNMENT
74 * __cfi_##name:
75 * .skip FUNCTION_PADDING, 0x90
76 * .byte 0xb8
77 * .long __kcfi_typeid_##name
78 * name:
79 *
80 * With CALL_THUNKS:
81 *
82 * .align FUNCTION_ALIGNMENT
83 * __cfi_##name:
84 * .byte 0xb8
85 * .long __kcfi_typeid_##name
86 * .skip FUNCTION_PADDING, 0x90
87 * name:
88 *
89 * In both cases the whole thing is FUNCTION_ALIGNMENT aligned and sized.
90 */
91
931ab636 92#ifdef CONFIG_CALL_PADDING
bea75b33
TG
93#define CFI_PRE_PADDING
94#define CFI_POST_PADDING .skip CONFIG_FUNCTION_PADDING_BYTES, 0x90;
95#else
96#define CFI_PRE_PADDING .skip CONFIG_FUNCTION_PADDING_BYTES, 0x90;
97#define CFI_POST_PADDING
98#endif
99
ccace936
ST
100#define __CFI_TYPE(name) \
101 SYM_START(__cfi_##name, SYM_L_LOCAL, SYM_A_NONE) \
bea75b33 102 CFI_PRE_PADDING \
ccace936
ST
103 .byte 0xb8 ASM_NL \
104 .long __kcfi_typeid_##name ASM_NL \
bea75b33 105 CFI_POST_PADDING \
ccace936
ST
106 SYM_FUNC_END(__cfi_##name)
107
10f4c9b9
VW
108/* UML needs to be able to override memcpy() and friends for KASAN. */
109#ifdef CONFIG_UML
110# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS_WEAK
111#else
112# define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS
113#endif
114
ccace936
ST
115/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
116#define SYM_TYPED_FUNC_START(name) \
4a2c3448 117 SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_F_ALIGN) \
ccace936
ST
118 ENDBR
119
c4691712
PZ
120/* SYM_FUNC_START -- use for global functions */
121#define SYM_FUNC_START(name) \
582077c9 122 SYM_START(name, SYM_L_GLOBAL, SYM_F_ALIGN)
c4691712
PZ
123
124/* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
125#define SYM_FUNC_START_NOALIGN(name) \
582077c9 126 SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
c4691712
PZ
127
128/* SYM_FUNC_START_LOCAL -- use for local functions */
129#define SYM_FUNC_START_LOCAL(name) \
582077c9 130 SYM_START(name, SYM_L_LOCAL, SYM_F_ALIGN)
c4691712
PZ
131
132/* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
133#define SYM_FUNC_START_LOCAL_NOALIGN(name) \
582077c9 134 SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
c4691712
PZ
135
136/* SYM_FUNC_START_WEAK -- use for weak functions */
137#define SYM_FUNC_START_WEAK(name) \
582077c9 138 SYM_START(name, SYM_L_WEAK, SYM_F_ALIGN)
c4691712
PZ
139
140/* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
141#define SYM_FUNC_START_WEAK_NOALIGN(name) \
582077c9 142 SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
c4691712 143
f932adcc
AB
144/*
145 * Expose 'sym' to the startup code in arch/x86/boot/startup/, by emitting an
146 * alias prefixed with __pi_
147 */
148#ifdef __ASSEMBLER__
149#define SYM_PIC_ALIAS(sym) SYM_ALIAS(__pi_ ## sym, sym, SYM_L_GLOBAL)
150#else
151#define SYM_PIC_ALIAS(sym) extern typeof(sym) __PASTE(__pi_, sym) __alias(sym)
152#endif
153
1965aae3 154#endif /* _ASM_X86_LINKAGE_H */
82f74e71 155