linkage.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_LINKAGE_H
  3. #define _LINUX_LINKAGE_H
  4. #include <linux/compiler_types.h>
  5. #include <linux/stringify.h>
  6. #include <linux/export.h>
  7. #include <asm/linkage.h>
  8. /* Some toolchains use other characters (e.g. '`') to mark new line in macro */
  9. #ifndef ASM_NL
  10. #define ASM_NL ;
  11. #endif
  12. #ifdef __cplusplus
  13. #define CPP_ASMLINKAGE extern "C"
  14. #else
  15. #define CPP_ASMLINKAGE
  16. #endif
  17. #ifndef asmlinkage
  18. #define asmlinkage CPP_ASMLINKAGE
  19. #endif
  20. #ifndef cond_syscall
  21. #define cond_syscall(x) asm( \
  22. ".weak " __stringify(x) "\n\t" \
  23. ".set " __stringify(x) "," \
  24. __stringify(sys_ni_syscall))
  25. #endif
  26. #ifndef SYSCALL_ALIAS
  27. #define SYSCALL_ALIAS(alias, name) asm( \
  28. ".globl " __stringify(alias) "\n\t" \
  29. ".set " __stringify(alias) "," \
  30. __stringify(name))
  31. #endif
  32. #define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE)
  33. #define __page_aligned_bss __section(".bss..page_aligned") __aligned(PAGE_SIZE)
  34. /*
  35. * For assembly routines.
  36. *
  37. * Note when using these that you must specify the appropriate
  38. * alignment directives yourself
  39. */
  40. #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw"
  41. #define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw"
  42. /*
  43. * This is used by architectures to keep arguments on the stack
  44. * untouched by the compiler by keeping them live until the end.
  45. * The argument stack may be owned by the assembly-language
  46. * caller, not the callee, and gcc doesn't always understand
  47. * that.
  48. *
  49. * We have the return value, and a maximum of six arguments.
  50. *
  51. * This should always be followed by a "return ret" for the
  52. * protection to work (ie no more work that the compiler might
  53. * end up needing stack temporaries for).
  54. */
  55. /* Assembly files may be compiled with -traditional .. */
  56. #ifndef __ASSEMBLY__
  57. #ifndef asmlinkage_protect
  58. # define asmlinkage_protect(n, ret, args...) do { } while (0)
  59. #endif
  60. #endif
  61. #ifndef __ALIGN
  62. #define __ALIGN .align 4,0x90
  63. #define __ALIGN_STR ".align 4,0x90"
  64. #endif
  65. #ifdef __ASSEMBLY__
  66. /* SYM_T_FUNC -- type used by assembler to mark functions */
  67. #ifndef SYM_T_FUNC
  68. #define SYM_T_FUNC STT_FUNC
  69. #endif
  70. /* SYM_T_OBJECT -- type used by assembler to mark data */
  71. #ifndef SYM_T_OBJECT
  72. #define SYM_T_OBJECT STT_OBJECT
  73. #endif
  74. /* SYM_T_NONE -- type used by assembler to mark entries of unknown type */
  75. #ifndef SYM_T_NONE
  76. #define SYM_T_NONE STT_NOTYPE
  77. #endif
  78. /* SYM_A_* -- align the symbol? */
  79. #define SYM_A_ALIGN ALIGN
  80. #define SYM_A_NONE /* nothing */
  81. /* SYM_L_* -- linkage of symbols */
  82. #define SYM_L_GLOBAL(name) .globl name
  83. #define SYM_L_WEAK(name) .weak name
  84. #define SYM_L_LOCAL(name) /* nothing */
  85. #ifndef LINKER_SCRIPT
  86. #define ALIGN __ALIGN
  87. #define ALIGN_STR __ALIGN_STR
  88. /* === DEPRECATED annotations === */
  89. #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
  90. #ifndef GLOBAL
  91. /* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */
  92. #define GLOBAL(name) \
  93. .globl name ASM_NL \
  94. name:
  95. #endif
  96. #ifndef ENTRY
  97. /* deprecated, use SYM_FUNC_START */
  98. #define ENTRY(name) \
  99. SYM_FUNC_START(name)
  100. #endif
  101. #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
  102. #endif /* LINKER_SCRIPT */
  103. #ifndef CONFIG_ARCH_USE_SYM_ANNOTATIONS
  104. #ifndef WEAK
  105. /* deprecated, use SYM_FUNC_START_WEAK* */
  106. #define WEAK(name) \
  107. SYM_FUNC_START_WEAK(name)
  108. #endif
  109. #ifndef END
  110. /* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */
  111. #define END(name) \
  112. .size name, .-name
  113. #endif
  114. /* If symbol 'name' is treated as a subroutine (gets called, and returns)
  115. * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of
  116. * static analysis tools such as stack depth analyzer.
  117. */
  118. #ifndef ENDPROC
  119. /* deprecated, use SYM_FUNC_END */
  120. #define ENDPROC(name) \
  121. SYM_FUNC_END(name)
  122. #endif
  123. #endif /* CONFIG_ARCH_USE_SYM_ANNOTATIONS */
  124. /* === generic annotations === */
  125. /* SYM_ENTRY -- use only if you have to for non-paired symbols */
  126. #ifndef SYM_ENTRY
  127. #define SYM_ENTRY(name, linkage, align...) \
  128. linkage(name) ASM_NL \
  129. align ASM_NL \
  130. name:
  131. #endif
  132. /* SYM_START -- use only if you have to */
  133. #ifndef SYM_START
  134. #define SYM_START(name, linkage, align...) \
  135. SYM_ENTRY(name, linkage, align)
  136. #endif
  137. /* SYM_END -- use only if you have to */
  138. #ifndef SYM_END
  139. #define SYM_END(name, sym_type) \
  140. .type name sym_type ASM_NL \
  141. .size name, .-name
  142. #endif
  143. /* === code annotations === */
  144. /*
  145. * FUNC -- C-like functions (proper stack frame etc.)
  146. * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
  147. *
  148. * Objtool validates stack for FUNC, but not for CODE.
  149. * Objtool generates debug info for both FUNC & CODE, but needs special
  150. * annotations for each CODE's start (to describe the actual stack frame).
  151. *
  152. * Objtool requires that all code must be contained in an ELF symbol. Symbol
  153. * names that have a .L prefix do not emit symbol table entries. .L
  154. * prefixed symbols can be used within a code region, but should be avoided for
  155. * denoting a range of code via ``SYM_*_START/END`` annotations.
  156. *
  157. * ALIAS -- does not generate debug info -- the aliased function will
  158. */
  159. /* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
  160. #ifndef SYM_INNER_LABEL_ALIGN
  161. #define SYM_INNER_LABEL_ALIGN(name, linkage) \
  162. .type name SYM_T_NONE ASM_NL \
  163. SYM_ENTRY(name, linkage, SYM_A_ALIGN)
  164. #endif
  165. /* SYM_INNER_LABEL -- only for labels in the middle of code */
  166. #ifndef SYM_INNER_LABEL
  167. #define SYM_INNER_LABEL(name, linkage) \
  168. .type name SYM_T_NONE ASM_NL \
  169. SYM_ENTRY(name, linkage, SYM_A_NONE)
  170. #endif
  171. /*
  172. * SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one
  173. * function
  174. */
  175. #ifndef SYM_FUNC_START_LOCAL_ALIAS
  176. #define SYM_FUNC_START_LOCAL_ALIAS(name) \
  177. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
  178. #endif
  179. /*
  180. * SYM_FUNC_START_ALIAS -- use where there are two global names for one
  181. * function
  182. */
  183. #ifndef SYM_FUNC_START_ALIAS
  184. #define SYM_FUNC_START_ALIAS(name) \
  185. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  186. #endif
  187. /* SYM_FUNC_START -- use for global functions */
  188. #ifndef SYM_FUNC_START
  189. /*
  190. * The same as SYM_FUNC_START_ALIAS, but we will need to distinguish these two
  191. * later.
  192. */
  193. #define SYM_FUNC_START(name) \
  194. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  195. #endif
  196. /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
  197. #ifndef SYM_FUNC_START_NOALIGN
  198. #define SYM_FUNC_START_NOALIGN(name) \
  199. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  200. #endif
  201. /* SYM_FUNC_START_LOCAL -- use for local functions */
  202. #ifndef SYM_FUNC_START_LOCAL
  203. /* the same as SYM_FUNC_START_LOCAL_ALIAS, see comment near SYM_FUNC_START */
  204. #define SYM_FUNC_START_LOCAL(name) \
  205. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
  206. #endif
  207. /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
  208. #ifndef SYM_FUNC_START_LOCAL_NOALIGN
  209. #define SYM_FUNC_START_LOCAL_NOALIGN(name) \
  210. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  211. #endif
  212. /* SYM_FUNC_START_WEAK -- use for weak functions */
  213. #ifndef SYM_FUNC_START_WEAK
  214. #define SYM_FUNC_START_WEAK(name) \
  215. SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
  216. #endif
  217. /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
  218. #ifndef SYM_FUNC_START_WEAK_NOALIGN
  219. #define SYM_FUNC_START_WEAK_NOALIGN(name) \
  220. SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
  221. #endif
  222. /* SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed function */
  223. #ifndef SYM_FUNC_END_ALIAS
  224. #define SYM_FUNC_END_ALIAS(name) \
  225. SYM_END(name, SYM_T_FUNC)
  226. #endif
  227. /*
  228. * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
  229. * SYM_FUNC_START_WEAK, ...
  230. */
  231. #ifndef SYM_FUNC_END
  232. /* the same as SYM_FUNC_END_ALIAS, see comment near SYM_FUNC_START */
  233. #define SYM_FUNC_END(name) \
  234. SYM_END(name, SYM_T_FUNC)
  235. #endif
  236. /* SYM_CODE_START -- use for non-C (special) functions */
  237. #ifndef SYM_CODE_START
  238. #define SYM_CODE_START(name) \
  239. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  240. #endif
  241. /* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
  242. #ifndef SYM_CODE_START_NOALIGN
  243. #define SYM_CODE_START_NOALIGN(name) \
  244. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  245. #endif
  246. /* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
  247. #ifndef SYM_CODE_START_LOCAL
  248. #define SYM_CODE_START_LOCAL(name) \
  249. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
  250. #endif
  251. /*
  252. * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
  253. * w/o alignment
  254. */
  255. #ifndef SYM_CODE_START_LOCAL_NOALIGN
  256. #define SYM_CODE_START_LOCAL_NOALIGN(name) \
  257. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  258. #endif
  259. /* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
  260. #ifndef SYM_CODE_END
  261. #define SYM_CODE_END(name) \
  262. SYM_END(name, SYM_T_NONE)
  263. #endif
  264. /* === data annotations === */
  265. /* SYM_DATA_START -- global data symbol */
  266. #ifndef SYM_DATA_START
  267. #define SYM_DATA_START(name) \
  268. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  269. #endif
  270. /* SYM_DATA_START -- local data symbol */
  271. #ifndef SYM_DATA_START_LOCAL
  272. #define SYM_DATA_START_LOCAL(name) \
  273. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  274. #endif
  275. /* SYM_DATA_END -- the end of SYM_DATA_START symbol */
  276. #ifndef SYM_DATA_END
  277. #define SYM_DATA_END(name) \
  278. SYM_END(name, SYM_T_OBJECT)
  279. #endif
  280. /* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
  281. #ifndef SYM_DATA_END_LABEL
  282. #define SYM_DATA_END_LABEL(name, linkage, label) \
  283. linkage(label) ASM_NL \
  284. .type label SYM_T_OBJECT ASM_NL \
  285. label: \
  286. SYM_END(name, SYM_T_OBJECT)
  287. #endif
  288. /* SYM_DATA -- start+end wrapper around simple global data */
  289. #ifndef SYM_DATA
  290. #define SYM_DATA(name, data...) \
  291. SYM_DATA_START(name) ASM_NL \
  292. data ASM_NL \
  293. SYM_DATA_END(name)
  294. #endif
  295. /* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
  296. #ifndef SYM_DATA_LOCAL
  297. #define SYM_DATA_LOCAL(name, data...) \
  298. SYM_DATA_START_LOCAL(name) ASM_NL \
  299. data ASM_NL \
  300. SYM_DATA_END(name)
  301. #endif
  302. #endif /* __ASSEMBLY__ */
  303. #endif /* _LINUX_LINKAGE_H */