1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_LINKAGE_H
3 #define _LINUX_LINKAGE_H
5 #include <linux/compiler_types.h>
6 #include <linux/stringify.h>
7 #include <linux/export.h>
8 #include <asm/linkage.h>
10 /* Some toolchains use other characters (e.g. '`') to mark new line in macro */
16 #define CPP_ASMLINKAGE extern "C"
18 #define CPP_ASMLINKAGE
22 #define asmlinkage CPP_ASMLINKAGE
26 #define cond_syscall(x) asm( \
27 ".weak " __stringify(x) "\n\t" \
28 ".set " __stringify(x) "," \
29 __stringify(sys_ni_syscall))
33 #define SYSCALL_ALIAS(alias, name) asm( \
34 ".globl " __stringify(alias) "\n\t" \
35 ".set " __stringify(alias) "," \
39 #define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE)
40 #define __page_aligned_bss __section(".bss..page_aligned") __aligned(PAGE_SIZE)
43 * For assembly routines.
45 * Note when using these that you must specify the appropriate
46 * alignment directives yourself
48 #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw"
49 #define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw"
52 * This is used by architectures to keep arguments on the stack
53 * untouched by the compiler by keeping them live until the end.
54 * The argument stack may be owned by the assembly-language
55 * caller, not the callee, and gcc doesn't always understand
58 * We have the return value, and a maximum of six arguments.
60 * This should always be followed by a "return ret" for the
61 * protection to work (ie no more work that the compiler might
62 * end up needing stack temporaries for).
64 /* Assembly files may be compiled with -traditional .. */
66 #ifndef asmlinkage_protect
67 # define asmlinkage_protect(n, ret, args...) do { } while (0)
72 #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT
73 #define __ALIGN_STR __stringify(__ALIGN)
78 /* SYM_T_FUNC -- type used by assembler to mark functions */
80 #define SYM_T_FUNC STT_FUNC
83 /* SYM_T_OBJECT -- type used by assembler to mark data */
85 #define SYM_T_OBJECT STT_OBJECT
88 /* SYM_T_NONE -- type used by assembler to mark entries of unknown type */
90 #define SYM_T_NONE STT_NOTYPE
93 /* SYM_A_* -- align the symbol? */
94 #define SYM_A_ALIGN ALIGN
95 #define SYM_A_NONE /* nothing */
97 /* SYM_L_* -- linkage of symbols */
98 #define SYM_L_GLOBAL(name) .globl name
99 #define SYM_L_WEAK(name) .weak name
100 #define SYM_L_LOCAL(name) /* nothing */
102 #ifndef LINKER_SCRIPT
103 #define ALIGN __ALIGN
104 #define ALIGN_STR __ALIGN_STR
106 /* === DEPRECATED annotations === */
108 #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
110 /* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */
111 #define GLOBAL(name) \
117 /* deprecated, use SYM_FUNC_START */
118 #define ENTRY(name) \
121 #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
122 #endif /* LINKER_SCRIPT */
124 #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
126 /* deprecated, use SYM_FUNC_START_WEAK* */
128 SYM_FUNC_START_WEAK(name)
132 /* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */
137 /* If symbol 'name' is treated as a subroutine (gets called, and returns)
138 * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of
139 * static analysis tools such as stack depth analyzer.
142 /* deprecated, use SYM_FUNC_END */
143 #define ENDPROC(name) \
146 #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
148 /* === generic annotations === */
150 /* SYM_ENTRY -- use only if you have to for non-paired symbols */
152 #define SYM_ENTRY(name, linkage, align...) \
153 linkage(name) ASM_NL \
158 /* SYM_START -- use only if you have to */
160 #define SYM_START(name, linkage, align...) \
161 SYM_ENTRY(name, linkage, align)
164 /* SYM_END -- use only if you have to */
166 #define SYM_END(name, sym_type) \
167 .type name sym_type ASM_NL \
168 .set .L__sym_size_##name, .-name ASM_NL \
169 .size name, .L__sym_size_##name
172 /* SYM_ALIAS -- use only if you have to */
174 #define SYM_ALIAS(alias, name, linkage) \
175 linkage(alias) ASM_NL \
176 .set alias, name ASM_NL
179 /* === code annotations === */
182 * FUNC -- C-like functions (proper stack frame etc.)
183 * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
185 * Objtool validates stack for FUNC, but not for CODE.
186 * Objtool generates debug info for both FUNC & CODE, but needs special
187 * annotations for each CODE's start (to describe the actual stack frame).
189 * Objtool requires that all code must be contained in an ELF symbol. Symbol
190 * names that have a .L prefix do not emit symbol table entries. .L
191 * prefixed symbols can be used within a code region, but should be avoided for
192 * denoting a range of code via ``SYM_*_START/END`` annotations.
194 * ALIAS -- does not generate debug info -- the aliased function will
197 /* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
198 #ifndef SYM_INNER_LABEL_ALIGN
199 #define SYM_INNER_LABEL_ALIGN(name, linkage) \
200 .type name SYM_T_NONE ASM_NL \
201 SYM_ENTRY(name, linkage, SYM_A_ALIGN)
204 /* SYM_INNER_LABEL -- only for labels in the middle of code */
205 #ifndef SYM_INNER_LABEL
206 #define SYM_INNER_LABEL(name, linkage) \
207 .type name SYM_T_NONE ASM_NL \
208 SYM_ENTRY(name, linkage, SYM_A_NONE)
211 /* SYM_FUNC_START -- use for global functions */
212 #ifndef SYM_FUNC_START
213 #define SYM_FUNC_START(name) \
214 SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
217 /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
218 #ifndef SYM_FUNC_START_NOALIGN
219 #define SYM_FUNC_START_NOALIGN(name) \
220 SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
223 /* SYM_FUNC_START_LOCAL -- use for local functions */
224 #ifndef SYM_FUNC_START_LOCAL
225 #define SYM_FUNC_START_LOCAL(name) \
226 SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
229 /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
230 #ifndef SYM_FUNC_START_LOCAL_NOALIGN
231 #define SYM_FUNC_START_LOCAL_NOALIGN(name) \
232 SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
235 /* SYM_FUNC_START_WEAK -- use for weak functions */
236 #ifndef SYM_FUNC_START_WEAK
237 #define SYM_FUNC_START_WEAK(name) \
238 SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
241 /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
242 #ifndef SYM_FUNC_START_WEAK_NOALIGN
243 #define SYM_FUNC_START_WEAK_NOALIGN(name) \
244 SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
248 * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
249 * SYM_FUNC_START_WEAK, ...
252 #define SYM_FUNC_END(name) \
253 SYM_END(name, SYM_T_FUNC)
257 * SYM_FUNC_ALIAS -- define a global alias for an existing function
259 #ifndef SYM_FUNC_ALIAS
260 #define SYM_FUNC_ALIAS(alias, name) \
261 SYM_ALIAS(alias, name, SYM_L_GLOBAL)
265 * SYM_FUNC_ALIAS_LOCAL -- define a local alias for an existing function
267 #ifndef SYM_FUNC_ALIAS_LOCAL
268 #define SYM_FUNC_ALIAS_LOCAL(alias, name) \
269 SYM_ALIAS(alias, name, SYM_L_LOCAL)
273 * SYM_FUNC_ALIAS_WEAK -- define a weak global alias for an existing function
275 #ifndef SYM_FUNC_ALIAS_WEAK
276 #define SYM_FUNC_ALIAS_WEAK(alias, name) \
277 SYM_ALIAS(alias, name, SYM_L_WEAK)
280 /* SYM_CODE_START -- use for non-C (special) functions */
281 #ifndef SYM_CODE_START
282 #define SYM_CODE_START(name) \
283 SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
286 /* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
287 #ifndef SYM_CODE_START_NOALIGN
288 #define SYM_CODE_START_NOALIGN(name) \
289 SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
292 /* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
293 #ifndef SYM_CODE_START_LOCAL
294 #define SYM_CODE_START_LOCAL(name) \
295 SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
299 * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
302 #ifndef SYM_CODE_START_LOCAL_NOALIGN
303 #define SYM_CODE_START_LOCAL_NOALIGN(name) \
304 SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
307 /* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
309 #define SYM_CODE_END(name) \
310 SYM_END(name, SYM_T_NONE)
313 /* === data annotations === */
315 /* SYM_DATA_START -- global data symbol */
316 #ifndef SYM_DATA_START
317 #define SYM_DATA_START(name) \
318 SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
321 /* SYM_DATA_START -- local data symbol */
322 #ifndef SYM_DATA_START_LOCAL
323 #define SYM_DATA_START_LOCAL(name) \
324 SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
327 /* SYM_DATA_END -- the end of SYM_DATA_START symbol */
329 #define SYM_DATA_END(name) \
330 SYM_END(name, SYM_T_OBJECT)
333 /* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
334 #ifndef SYM_DATA_END_LABEL
335 #define SYM_DATA_END_LABEL(name, linkage, label) \
336 linkage(label) ASM_NL \
337 .type label SYM_T_OBJECT ASM_NL \
339 SYM_END(name, SYM_T_OBJECT)
342 /* SYM_DATA -- start+end wrapper around simple global data */
344 #define SYM_DATA(name, data...) \
345 SYM_DATA_START(name) ASM_NL \
350 /* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
351 #ifndef SYM_DATA_LOCAL
352 #define SYM_DATA_LOCAL(name, data...) \
353 SYM_DATA_START_LOCAL(name) ASM_NL \
358 #endif /* __ASSEMBLY__ */
360 #endif /* _LINUX_LINKAGE_H */