File Index
Files and directories
Sign in
FILE

linkage.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/linkage.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _LINUX_LINKAGE_H
  3#define _LINUX_LINKAGE_H
  4
  5#include <linux/compiler_types.h>
  6#include <linux/stringify.h>
  7#include <linux/export.h>
  8#include <asm/linkage.h>
  9
 10/* Some toolchains use other characters (e.g. '`') to mark new line in macro */
 11#ifndef ASM_NL
 12#define ASM_NL		 ;
 13#endif
 14
 15#ifdef __cplusplus
 16#define CPP_ASMLINKAGE extern "C"
 17#else
 18#define CPP_ASMLINKAGE
 19#endif
 20
 21#ifndef asmlinkage
 22#define asmlinkage CPP_ASMLINKAGE
 23#endif
 24
 25#ifndef cond_syscall
 26#define cond_syscall(x)	asm(				\
 27	".weak " __stringify(x) "\n\t"			\
 28	".set  " __stringify(x) ","			\
 29		 __stringify(sys_ni_syscall))
 30#endif
 31
 32#ifndef SYSCALL_ALIAS
 33#define SYSCALL_ALIAS(alias, name) asm(			\
 34	".globl " __stringify(alias) "\n\t"		\
 35	".set   " __stringify(alias) ","		\
 36		  __stringify(name))
 37#endif
 38
 39#define __page_aligned_data	__section(".data..page_aligned") __aligned(PAGE_SIZE)
 40#define __page_aligned_bss	__section(".bss..page_aligned") __aligned(PAGE_SIZE)
 41
 42/*
 43 * For assembly routines.
 44 *
 45 * Note when using these that you must specify the appropriate
 46 * alignment directives yourself
 47 */
 48#define __PAGE_ALIGNED_DATA	.section ".data..page_aligned", "aw"
 49#define __PAGE_ALIGNED_BSS	.section ".bss..page_aligned", "aw"
 50
 51/*
 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
 56 * that.
 57 *
 58 * We have the return value, and a maximum of six arguments.
 59 *
 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).
 63 */
 64/* Assembly files may be compiled with -traditional .. */
 65#ifndef __ASSEMBLY__
 66#ifndef asmlinkage_protect
 67# define asmlinkage_protect(n, ret, args...)	do { } while (0)
 68#endif
 69#endif
 70
 71#ifndef __ALIGN
 72#define __ALIGN			.balign CONFIG_FUNCTION_ALIGNMENT
 73#define __ALIGN_STR		__stringify(__ALIGN)
 74#endif
 75
 76#ifdef __ASSEMBLY__
 77
 78/* SYM_T_FUNC -- type used by assembler to mark functions */
 79#ifndef SYM_T_FUNC
 80#define SYM_T_FUNC				STT_FUNC
 81#endif
 82
 83/* SYM_T_OBJECT -- type used by assembler to mark data */
 84#ifndef SYM_T_OBJECT
 85#define SYM_T_OBJECT				STT_OBJECT
 86#endif
 87
 88/* SYM_T_NONE -- type used by assembler to mark entries of unknown type */
 89#ifndef SYM_T_NONE
 90#define SYM_T_NONE				STT_NOTYPE
 91#endif
 92
 93/* SYM_A_* -- align the symbol? */
 94#define SYM_A_ALIGN				ALIGN
 95#define SYM_A_NONE				/* nothing */
 96
 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 */
101
102#ifndef LINKER_SCRIPT
103#define ALIGN __ALIGN
104#define ALIGN_STR __ALIGN_STR
105
106/* === DEPRECATED annotations === */
107
108#ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
109#ifndef GLOBAL
110/* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */
111#define GLOBAL(name) \
112	.globl name ASM_NL \
113	name:
114#endif
115
116#ifndef ENTRY
117/* deprecated, use SYM_FUNC_START */
118#define ENTRY(name) \
119	SYM_FUNC_START(name)
120#endif
121#endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
122#endif /* LINKER_SCRIPT */
123
124#ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
125#ifndef WEAK
126/* deprecated, use SYM_FUNC_START_WEAK* */
127#define WEAK(name)	   \
128	SYM_FUNC_START_WEAK(name)
129#endif
130
131#ifndef END
132/* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */
133#define END(name) \
134	.size name, .-name
135#endif
136
137#ifndef ENDPROC
138/* deprecated, use SYM_FUNC_END */
139#define ENDPROC(name) \
140	SYM_FUNC_END(name)
141#endif
142#endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
143
144/* === generic annotations === */
145
146/* SYM_ENTRY -- use only if you have to for non-paired symbols */
147#ifndef SYM_ENTRY
148#define SYM_ENTRY(name, linkage, align...)		\
149	linkage(name) ASM_NL				\
150	align ASM_NL					\
151	name:
152#endif
153
154/* SYM_START -- use only if you have to */
155#ifndef SYM_START
156#define SYM_START(name, linkage, align...)		\
157	SYM_ENTRY(name, linkage, align)
158#endif
159
160/* SYM_END -- use only if you have to */
161#ifndef SYM_END
162#define SYM_END(name, sym_type)				\
163	.type name sym_type ASM_NL			\
164	.set .L__sym_size_##name, .-name ASM_NL		\
165	.size name, .L__sym_size_##name
166#endif
167
168/* SYM_ALIAS -- use only if you have to */
169#ifndef SYM_ALIAS
170#define SYM_ALIAS(alias, name, linkage)			\
171	linkage(alias) ASM_NL				\
172	.set alias, name ASM_NL
173#endif
174
175/* === code annotations === */
176
177/*
178 * FUNC -- C-like functions (proper stack frame etc.)
179 * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
180 *
181 * Objtool validates stack for FUNC, but not for CODE.
182 * Objtool generates debug info for both FUNC & CODE, but needs special
183 * annotations for each CODE's start (to describe the actual stack frame).
184 *
185 * Objtool requires that all code must be contained in an ELF symbol. Symbol
186 * names that have a  .L prefix do not emit symbol table entries. .L
187 * prefixed symbols can be used within a code region, but should be avoided for
188 * denoting a range of code via ``SYM_*_START/END`` annotations.
189 *
190 * ALIAS -- does not generate debug info -- the aliased function will
191 */
192
193/* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
194#ifndef SYM_INNER_LABEL_ALIGN
195#define SYM_INNER_LABEL_ALIGN(name, linkage)	\
196	.type name SYM_T_NONE ASM_NL			\
197	SYM_ENTRY(name, linkage, SYM_A_ALIGN)
198#endif
199
200/* SYM_INNER_LABEL -- only for labels in the middle of code */
201#ifndef SYM_INNER_LABEL
202#define SYM_INNER_LABEL(name, linkage)		\
203	.type name SYM_T_NONE ASM_NL			\
204	SYM_ENTRY(name, linkage, SYM_A_NONE)
205#endif
206
207/* SYM_FUNC_START -- use for global functions */
208#ifndef SYM_FUNC_START
209#define SYM_FUNC_START(name)				\
210	SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
211#endif
212
213/* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
214#ifndef SYM_FUNC_START_NOALIGN
215#define SYM_FUNC_START_NOALIGN(name)			\
216	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
217#endif
218
219/* SYM_FUNC_START_LOCAL -- use for local functions */
220#ifndef SYM_FUNC_START_LOCAL
221#define SYM_FUNC_START_LOCAL(name)			\
222	SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
223#endif
224
225/* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
226#ifndef SYM_FUNC_START_LOCAL_NOALIGN
227#define SYM_FUNC_START_LOCAL_NOALIGN(name)		\
228	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
229#endif
230
231/* SYM_FUNC_START_WEAK -- use for weak functions */
232#ifndef SYM_FUNC_START_WEAK
233#define SYM_FUNC_START_WEAK(name)			\
234	SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
235#endif
236
237/* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
238#ifndef SYM_FUNC_START_WEAK_NOALIGN
239#define SYM_FUNC_START_WEAK_NOALIGN(name)		\
240	SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
241#endif
242
243/*
244 * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
245 * SYM_FUNC_START_WEAK, ...
246 */
247#ifndef SYM_FUNC_END
248#define SYM_FUNC_END(name)				\
249	SYM_END(name, SYM_T_FUNC)
250#endif
251
252/*
253 * SYM_FUNC_ALIAS -- define a global alias for an existing function
254 */
255#ifndef SYM_FUNC_ALIAS
256#define SYM_FUNC_ALIAS(alias, name)					\
257	SYM_ALIAS(alias, name, SYM_L_GLOBAL)
258#endif
259
260/*
261 * SYM_FUNC_ALIAS_LOCAL -- define a local alias for an existing function
262 */
263#ifndef SYM_FUNC_ALIAS_LOCAL
264#define SYM_FUNC_ALIAS_LOCAL(alias, name)				\
265	SYM_ALIAS(alias, name, SYM_L_LOCAL)
266#endif
267
268/*
269 * SYM_FUNC_ALIAS_WEAK -- define a weak global alias for an existing function
270 */
271#ifndef SYM_FUNC_ALIAS_WEAK
272#define SYM_FUNC_ALIAS_WEAK(alias, name)				\
273	SYM_ALIAS(alias, name, SYM_L_WEAK)
274#endif
275
276/* SYM_CODE_START -- use for non-C (special) functions */
277#ifndef SYM_CODE_START
278#define SYM_CODE_START(name)				\
279	SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
280#endif
281
282/* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
283#ifndef SYM_CODE_START_NOALIGN
284#define SYM_CODE_START_NOALIGN(name)			\
285	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
286#endif
287
288/* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
289#ifndef SYM_CODE_START_LOCAL
290#define SYM_CODE_START_LOCAL(name)			\
291	SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
292#endif
293
294/*
295 * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
296 * w/o alignment
297 */
298#ifndef SYM_CODE_START_LOCAL_NOALIGN
299#define SYM_CODE_START_LOCAL_NOALIGN(name)		\
300	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
301#endif
302
303/* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
304#ifndef SYM_CODE_END
305#define SYM_CODE_END(name)				\
306	SYM_END(name, SYM_T_NONE)
307#endif
308
309/* === data annotations === */
310
311/* SYM_DATA_START -- global data symbol */
312#ifndef SYM_DATA_START
313#define SYM_DATA_START(name)				\
314	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
315#endif
316
317/* SYM_DATA_START -- local data symbol */
318#ifndef SYM_DATA_START_LOCAL
319#define SYM_DATA_START_LOCAL(name)			\
320	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
321#endif
322
323/* SYM_DATA_END -- the end of SYM_DATA_START symbol */
324#ifndef SYM_DATA_END
325#define SYM_DATA_END(name)				\
326	SYM_END(name, SYM_T_OBJECT)
327#endif
328
329/* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
330#ifndef SYM_DATA_END_LABEL
331#define SYM_DATA_END_LABEL(name, linkage, label)	\
332	linkage(label) ASM_NL				\
333	.type label SYM_T_OBJECT ASM_NL			\
334	label:						\
335	SYM_END(name, SYM_T_OBJECT)
336#endif
337
338/* SYM_DATA -- start+end wrapper around simple global data */
339#ifndef SYM_DATA
340#define SYM_DATA(name, data...)				\
341	SYM_DATA_START(name) ASM_NL				\
342	data ASM_NL						\
343	SYM_DATA_END(name)
344#endif
345
346/* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
347#ifndef SYM_DATA_LOCAL
348#define SYM_DATA_LOCAL(name, data...)			\
349	SYM_DATA_START_LOCAL(name) ASM_NL			\
350	data ASM_NL						\
351	SYM_DATA_END(name)
352#endif
353
354#endif /* __ASSEMBLY__ */
355
356#endif /* _LINUX_LINKAGE_H */
~/ Read-only file preview.