linkage.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. .set .L__sym_size_##name, .-name ASM_NL \
  142. .size name, .L__sym_size_##name
  143. #endif
  144. /* SYM_ALIAS -- use only if you have to */
  145. #ifndef SYM_ALIAS
  146. #define SYM_ALIAS(alias, name, linkage) \
  147. linkage(alias) ASM_NL \
  148. .set alias, name ASM_NL
  149. #endif
  150. /* === code annotations === */
  151. /*
  152. * FUNC -- C-like functions (proper stack frame etc.)
  153. * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
  154. *
  155. * Objtool validates stack for FUNC, but not for CODE.
  156. * Objtool generates debug info for both FUNC & CODE, but needs special
  157. * annotations for each CODE's start (to describe the actual stack frame).
  158. *
  159. * Objtool requires that all code must be contained in an ELF symbol. Symbol
  160. * names that have a .L prefix do not emit symbol table entries. .L
  161. * prefixed symbols can be used within a code region, but should be avoided for
  162. * denoting a range of code via ``SYM_*_START/END`` annotations.
  163. *
  164. * ALIAS -- does not generate debug info -- the aliased function will
  165. */
  166. /* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
  167. #ifndef SYM_INNER_LABEL_ALIGN
  168. #define SYM_INNER_LABEL_ALIGN(name, linkage) \
  169. .type name SYM_T_NONE ASM_NL \
  170. SYM_ENTRY(name, linkage, SYM_A_ALIGN)
  171. #endif
  172. /* SYM_INNER_LABEL -- only for labels in the middle of code */
  173. #ifndef SYM_INNER_LABEL
  174. #define SYM_INNER_LABEL(name, linkage) \
  175. .type name SYM_T_NONE ASM_NL \
  176. SYM_ENTRY(name, linkage, SYM_A_NONE)
  177. #endif
  178. /* SYM_FUNC_START -- use for global functions */
  179. #ifndef SYM_FUNC_START
  180. #define SYM_FUNC_START(name) \
  181. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  182. #endif
  183. /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
  184. #ifndef SYM_FUNC_START_NOALIGN
  185. #define SYM_FUNC_START_NOALIGN(name) \
  186. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  187. #endif
  188. /* SYM_FUNC_START_LOCAL -- use for local functions */
  189. #ifndef SYM_FUNC_START_LOCAL
  190. #define SYM_FUNC_START_LOCAL(name) \
  191. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
  192. #endif
  193. /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
  194. #ifndef SYM_FUNC_START_LOCAL_NOALIGN
  195. #define SYM_FUNC_START_LOCAL_NOALIGN(name) \
  196. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  197. #endif
  198. /* SYM_FUNC_START_WEAK -- use for weak functions */
  199. #ifndef SYM_FUNC_START_WEAK
  200. #define SYM_FUNC_START_WEAK(name) \
  201. SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
  202. #endif
  203. /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
  204. #ifndef SYM_FUNC_START_WEAK_NOALIGN
  205. #define SYM_FUNC_START_WEAK_NOALIGN(name) \
  206. SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
  207. #endif
  208. /*
  209. * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
  210. * SYM_FUNC_START_WEAK, ...
  211. */
  212. #ifndef SYM_FUNC_END
  213. #define SYM_FUNC_END(name) \
  214. SYM_END(name, SYM_T_FUNC)
  215. #endif
  216. /*
  217. * SYM_FUNC_ALIAS -- define a global alias for an existing function
  218. */
  219. #ifndef SYM_FUNC_ALIAS
  220. #define SYM_FUNC_ALIAS(alias, name) \
  221. SYM_ALIAS(alias, name, SYM_L_GLOBAL)
  222. #endif
  223. /*
  224. * SYM_FUNC_ALIAS_LOCAL -- define a local alias for an existing function
  225. */
  226. #ifndef SYM_FUNC_ALIAS_LOCAL
  227. #define SYM_FUNC_ALIAS_LOCAL(alias, name) \
  228. SYM_ALIAS(alias, name, SYM_L_LOCAL)
  229. #endif
  230. /*
  231. * SYM_FUNC_ALIAS_WEAK -- define a weak global alias for an existing function
  232. */
  233. #ifndef SYM_FUNC_ALIAS_WEAK
  234. #define SYM_FUNC_ALIAS_WEAK(alias, name) \
  235. SYM_ALIAS(alias, name, SYM_L_WEAK)
  236. #endif
  237. /* SYM_CODE_START -- use for non-C (special) functions */
  238. #ifndef SYM_CODE_START
  239. #define SYM_CODE_START(name) \
  240. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  241. #endif
  242. /* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
  243. #ifndef SYM_CODE_START_NOALIGN
  244. #define SYM_CODE_START_NOALIGN(name) \
  245. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  246. #endif
  247. /* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
  248. #ifndef SYM_CODE_START_LOCAL
  249. #define SYM_CODE_START_LOCAL(name) \
  250. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
  251. #endif
  252. /*
  253. * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
  254. * w/o alignment
  255. */
  256. #ifndef SYM_CODE_START_LOCAL_NOALIGN
  257. #define SYM_CODE_START_LOCAL_NOALIGN(name) \
  258. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  259. #endif
  260. /* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
  261. #ifndef SYM_CODE_END
  262. #define SYM_CODE_END(name) \
  263. SYM_END(name, SYM_T_NONE)
  264. #endif
  265. /* === data annotations === */
  266. /* SYM_DATA_START -- global data symbol */
  267. #ifndef SYM_DATA_START
  268. #define SYM_DATA_START(name) \
  269. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
  270. #endif
  271. /* SYM_DATA_START -- local data symbol */
  272. #ifndef SYM_DATA_START_LOCAL
  273. #define SYM_DATA_START_LOCAL(name) \
  274. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
  275. #endif
  276. /* SYM_DATA_END -- the end of SYM_DATA_START symbol */
  277. #ifndef SYM_DATA_END
  278. #define SYM_DATA_END(name) \
  279. SYM_END(name, SYM_T_OBJECT)
  280. #endif
  281. /* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
  282. #ifndef SYM_DATA_END_LABEL
  283. #define SYM_DATA_END_LABEL(name, linkage, label) \
  284. linkage(label) ASM_NL \
  285. .type label SYM_T_OBJECT ASM_NL \
  286. label: \
  287. SYM_END(name, SYM_T_OBJECT)
  288. #endif
  289. /* SYM_DATA -- start+end wrapper around simple global data */
  290. #ifndef SYM_DATA
  291. #define SYM_DATA(name, data...) \
  292. SYM_DATA_START(name) ASM_NL \
  293. data ASM_NL \
  294. SYM_DATA_END(name)
  295. #endif
  296. /* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
  297. #ifndef SYM_DATA_LOCAL
  298. #define SYM_DATA_LOCAL(name, data...) \
  299. SYM_DATA_START_LOCAL(name) ASM_NL \
  300. data ASM_NL \
  301. SYM_DATA_END(name)
  302. #endif
  303. #endif /* __ASSEMBLY__ */
  304. #endif /* _LINUX_LINKAGE_H */