Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_LINKAGE_H
0003 #define _LINUX_LINKAGE_H
0004 
0005 #include <linux/compiler_types.h>
0006 #include <linux/stringify.h>
0007 #include <linux/export.h>
0008 #include <asm/linkage.h>
0009 
0010 /* Some toolchains use other characters (e.g. '`') to mark new line in macro */
0011 #ifndef ASM_NL
0012 #define ASM_NL       ;
0013 #endif
0014 
0015 #ifdef __cplusplus
0016 #define CPP_ASMLINKAGE extern "C"
0017 #else
0018 #define CPP_ASMLINKAGE
0019 #endif
0020 
0021 #ifndef asmlinkage
0022 #define asmlinkage CPP_ASMLINKAGE
0023 #endif
0024 
0025 #ifndef cond_syscall
0026 #define cond_syscall(x) asm(                \
0027     ".weak " __stringify(x) "\n\t"          \
0028     ".set  " __stringify(x) ","         \
0029          __stringify(sys_ni_syscall))
0030 #endif
0031 
0032 #ifndef SYSCALL_ALIAS
0033 #define SYSCALL_ALIAS(alias, name) asm(         \
0034     ".globl " __stringify(alias) "\n\t"     \
0035     ".set   " __stringify(alias) ","        \
0036           __stringify(name))
0037 #endif
0038 
0039 #define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE)
0040 #define __page_aligned_bss  __section(".bss..page_aligned") __aligned(PAGE_SIZE)
0041 
0042 /*
0043  * For assembly routines.
0044  *
0045  * Note when using these that you must specify the appropriate
0046  * alignment directives yourself
0047  */
0048 #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw"
0049 #define __PAGE_ALIGNED_BSS  .section ".bss..page_aligned", "aw"
0050 
0051 /*
0052  * This is used by architectures to keep arguments on the stack
0053  * untouched by the compiler by keeping them live until the end.
0054  * The argument stack may be owned by the assembly-language
0055  * caller, not the callee, and gcc doesn't always understand
0056  * that.
0057  *
0058  * We have the return value, and a maximum of six arguments.
0059  *
0060  * This should always be followed by a "return ret" for the
0061  * protection to work (ie no more work that the compiler might
0062  * end up needing stack temporaries for).
0063  */
0064 /* Assembly files may be compiled with -traditional .. */
0065 #ifndef __ASSEMBLY__
0066 #ifndef asmlinkage_protect
0067 # define asmlinkage_protect(n, ret, args...)    do { } while (0)
0068 #endif
0069 #endif
0070 
0071 #ifndef __ALIGN
0072 #define __ALIGN     .align 4,0x90
0073 #define __ALIGN_STR ".align 4,0x90"
0074 #endif
0075 
0076 #ifdef __ASSEMBLY__
0077 
0078 /* SYM_T_FUNC -- type used by assembler to mark functions */
0079 #ifndef SYM_T_FUNC
0080 #define SYM_T_FUNC              STT_FUNC
0081 #endif
0082 
0083 /* SYM_T_OBJECT -- type used by assembler to mark data */
0084 #ifndef SYM_T_OBJECT
0085 #define SYM_T_OBJECT                STT_OBJECT
0086 #endif
0087 
0088 /* SYM_T_NONE -- type used by assembler to mark entries of unknown type */
0089 #ifndef SYM_T_NONE
0090 #define SYM_T_NONE              STT_NOTYPE
0091 #endif
0092 
0093 /* SYM_A_* -- align the symbol? */
0094 #define SYM_A_ALIGN             ALIGN
0095 #define SYM_A_NONE              /* nothing */
0096 
0097 /* SYM_L_* -- linkage of symbols */
0098 #define SYM_L_GLOBAL(name)          .globl name
0099 #define SYM_L_WEAK(name)            .weak name
0100 #define SYM_L_LOCAL(name)           /* nothing */
0101 
0102 #ifndef LINKER_SCRIPT
0103 #define ALIGN __ALIGN
0104 #define ALIGN_STR __ALIGN_STR
0105 
0106 /* === DEPRECATED annotations === */
0107 
0108 #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
0109 #ifndef GLOBAL
0110 /* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */
0111 #define GLOBAL(name) \
0112     .globl name ASM_NL \
0113     name:
0114 #endif
0115 
0116 #ifndef ENTRY
0117 /* deprecated, use SYM_FUNC_START */
0118 #define ENTRY(name) \
0119     SYM_FUNC_START(name)
0120 #endif
0121 #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
0122 #endif /* LINKER_SCRIPT */
0123 
0124 #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
0125 #ifndef WEAK
0126 /* deprecated, use SYM_FUNC_START_WEAK* */
0127 #define WEAK(name)     \
0128     SYM_FUNC_START_WEAK(name)
0129 #endif
0130 
0131 #ifndef END
0132 /* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */
0133 #define END(name) \
0134     .size name, .-name
0135 #endif
0136 
0137 /* If symbol 'name' is treated as a subroutine (gets called, and returns)
0138  * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of
0139  * static analysis tools such as stack depth analyzer.
0140  */
0141 #ifndef ENDPROC
0142 /* deprecated, use SYM_FUNC_END */
0143 #define ENDPROC(name) \
0144     SYM_FUNC_END(name)
0145 #endif
0146 #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
0147 
0148 /* === generic annotations === */
0149 
0150 /* SYM_ENTRY -- use only if you have to for non-paired symbols */
0151 #ifndef SYM_ENTRY
0152 #define SYM_ENTRY(name, linkage, align...)      \
0153     linkage(name) ASM_NL                \
0154     align ASM_NL                    \
0155     name:
0156 #endif
0157 
0158 /* SYM_START -- use only if you have to */
0159 #ifndef SYM_START
0160 #define SYM_START(name, linkage, align...)      \
0161     SYM_ENTRY(name, linkage, align)
0162 #endif
0163 
0164 /* SYM_END -- use only if you have to */
0165 #ifndef SYM_END
0166 #define SYM_END(name, sym_type)             \
0167     .type name sym_type ASM_NL          \
0168     .set .L__sym_size_##name, .-name ASM_NL     \
0169     .size name, .L__sym_size_##name
0170 #endif
0171 
0172 /* SYM_ALIAS -- use only if you have to */
0173 #ifndef SYM_ALIAS
0174 #define SYM_ALIAS(alias, name, linkage)         \
0175     linkage(alias) ASM_NL               \
0176     .set alias, name ASM_NL
0177 #endif
0178 
0179 /* === code annotations === */
0180 
0181 /*
0182  * FUNC -- C-like functions (proper stack frame etc.)
0183  * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
0184  *
0185  * Objtool validates stack for FUNC, but not for CODE.
0186  * Objtool generates debug info for both FUNC & CODE, but needs special
0187  * annotations for each CODE's start (to describe the actual stack frame).
0188  *
0189  * Objtool requires that all code must be contained in an ELF symbol. Symbol
0190  * names that have a  .L prefix do not emit symbol table entries. .L
0191  * prefixed symbols can be used within a code region, but should be avoided for
0192  * denoting a range of code via ``SYM_*_START/END`` annotations.
0193  *
0194  * ALIAS -- does not generate debug info -- the aliased function will
0195  */
0196 
0197 /* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
0198 #ifndef SYM_INNER_LABEL_ALIGN
0199 #define SYM_INNER_LABEL_ALIGN(name, linkage)    \
0200     .type name SYM_T_NONE ASM_NL            \
0201     SYM_ENTRY(name, linkage, SYM_A_ALIGN)
0202 #endif
0203 
0204 /* SYM_INNER_LABEL -- only for labels in the middle of code */
0205 #ifndef SYM_INNER_LABEL
0206 #define SYM_INNER_LABEL(name, linkage)      \
0207     .type name SYM_T_NONE ASM_NL            \
0208     SYM_ENTRY(name, linkage, SYM_A_NONE)
0209 #endif
0210 
0211 /* SYM_FUNC_START -- use for global functions */
0212 #ifndef SYM_FUNC_START
0213 #define SYM_FUNC_START(name)                \
0214     SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
0215 #endif
0216 
0217 /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
0218 #ifndef SYM_FUNC_START_NOALIGN
0219 #define SYM_FUNC_START_NOALIGN(name)            \
0220     SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
0221 #endif
0222 
0223 /* SYM_FUNC_START_LOCAL -- use for local functions */
0224 #ifndef SYM_FUNC_START_LOCAL
0225 #define SYM_FUNC_START_LOCAL(name)          \
0226     SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
0227 #endif
0228 
0229 /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
0230 #ifndef SYM_FUNC_START_LOCAL_NOALIGN
0231 #define SYM_FUNC_START_LOCAL_NOALIGN(name)      \
0232     SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
0233 #endif
0234 
0235 /* SYM_FUNC_START_WEAK -- use for weak functions */
0236 #ifndef SYM_FUNC_START_WEAK
0237 #define SYM_FUNC_START_WEAK(name)           \
0238     SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
0239 #endif
0240 
0241 /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
0242 #ifndef SYM_FUNC_START_WEAK_NOALIGN
0243 #define SYM_FUNC_START_WEAK_NOALIGN(name)       \
0244     SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
0245 #endif
0246 
0247 /*
0248  * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
0249  * SYM_FUNC_START_WEAK, ...
0250  */
0251 #ifndef SYM_FUNC_END
0252 #define SYM_FUNC_END(name)              \
0253     SYM_END(name, SYM_T_FUNC)
0254 #endif
0255 
0256 /*
0257  * SYM_FUNC_ALIAS -- define a global alias for an existing function
0258  */
0259 #ifndef SYM_FUNC_ALIAS
0260 #define SYM_FUNC_ALIAS(alias, name)                 \
0261     SYM_ALIAS(alias, name, SYM_L_GLOBAL)
0262 #endif
0263 
0264 /*
0265  * SYM_FUNC_ALIAS_LOCAL -- define a local alias for an existing function
0266  */
0267 #ifndef SYM_FUNC_ALIAS_LOCAL
0268 #define SYM_FUNC_ALIAS_LOCAL(alias, name)               \
0269     SYM_ALIAS(alias, name, SYM_L_LOCAL)
0270 #endif
0271 
0272 /*
0273  * SYM_FUNC_ALIAS_WEAK -- define a weak global alias for an existing function
0274  */
0275 #ifndef SYM_FUNC_ALIAS_WEAK
0276 #define SYM_FUNC_ALIAS_WEAK(alias, name)                \
0277     SYM_ALIAS(alias, name, SYM_L_WEAK)
0278 #endif
0279 
0280 /* SYM_CODE_START -- use for non-C (special) functions */
0281 #ifndef SYM_CODE_START
0282 #define SYM_CODE_START(name)                \
0283     SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
0284 #endif
0285 
0286 /* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
0287 #ifndef SYM_CODE_START_NOALIGN
0288 #define SYM_CODE_START_NOALIGN(name)            \
0289     SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
0290 #endif
0291 
0292 /* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
0293 #ifndef SYM_CODE_START_LOCAL
0294 #define SYM_CODE_START_LOCAL(name)          \
0295     SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
0296 #endif
0297 
0298 /*
0299  * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
0300  * w/o alignment
0301  */
0302 #ifndef SYM_CODE_START_LOCAL_NOALIGN
0303 #define SYM_CODE_START_LOCAL_NOALIGN(name)      \
0304     SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
0305 #endif
0306 
0307 /* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
0308 #ifndef SYM_CODE_END
0309 #define SYM_CODE_END(name)              \
0310     SYM_END(name, SYM_T_NONE)
0311 #endif
0312 
0313 /* === data annotations === */
0314 
0315 /* SYM_DATA_START -- global data symbol */
0316 #ifndef SYM_DATA_START
0317 #define SYM_DATA_START(name)                \
0318     SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
0319 #endif
0320 
0321 /* SYM_DATA_START -- local data symbol */
0322 #ifndef SYM_DATA_START_LOCAL
0323 #define SYM_DATA_START_LOCAL(name)          \
0324     SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
0325 #endif
0326 
0327 /* SYM_DATA_END -- the end of SYM_DATA_START symbol */
0328 #ifndef SYM_DATA_END
0329 #define SYM_DATA_END(name)              \
0330     SYM_END(name, SYM_T_OBJECT)
0331 #endif
0332 
0333 /* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
0334 #ifndef SYM_DATA_END_LABEL
0335 #define SYM_DATA_END_LABEL(name, linkage, label)    \
0336     linkage(label) ASM_NL               \
0337     .type label SYM_T_OBJECT ASM_NL         \
0338     label:                      \
0339     SYM_END(name, SYM_T_OBJECT)
0340 #endif
0341 
0342 /* SYM_DATA -- start+end wrapper around simple global data */
0343 #ifndef SYM_DATA
0344 #define SYM_DATA(name, data...)             \
0345     SYM_DATA_START(name) ASM_NL             \
0346     data ASM_NL                     \
0347     SYM_DATA_END(name)
0348 #endif
0349 
0350 /* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
0351 #ifndef SYM_DATA_LOCAL
0352 #define SYM_DATA_LOCAL(name, data...)           \
0353     SYM_DATA_START_LOCAL(name) ASM_NL           \
0354     data ASM_NL                     \
0355     SYM_DATA_END(name)
0356 #endif
0357 
0358 #endif /* __ASSEMBLY__ */
0359 
0360 #endif /* _LINUX_LINKAGE_H */