Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 .align 4,0x90 |
| 73 | #define __ALIGN_STR ".align 4,0x90" |
| 74 | #endif |
| 75 | |
| 76 | #ifdef __ASSEMBLY__ |
| 77 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 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 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 102 | #ifndef LINKER_SCRIPT |
| 103 | #define ALIGN __ALIGN |
| 104 | #define ALIGN_STR __ALIGN_STR |
| 105 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 106 | /* === DEPRECATED annotations === */ |
| 107 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 108 | #ifndef GLOBAL |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 109 | /* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 110 | #define GLOBAL(name) \ |
| 111 | .globl name ASM_NL \ |
| 112 | name: |
| 113 | #endif |
| 114 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 115 | #ifndef ENTRY |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 116 | /* deprecated, use SYM_FUNC_START */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 117 | #define ENTRY(name) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 118 | SYM_FUNC_START(name) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 119 | #endif |
| 120 | #endif /* LINKER_SCRIPT */ |
| 121 | |
| 122 | #ifndef WEAK |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 123 | /* deprecated, use SYM_FUNC_START_WEAK* */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 124 | #define WEAK(name) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 125 | SYM_FUNC_START_WEAK(name) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 126 | #endif |
| 127 | |
| 128 | #ifndef END |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 129 | /* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 130 | #define END(name) \ |
| 131 | .size name, .-name |
| 132 | #endif |
| 133 | |
| 134 | /* If symbol 'name' is treated as a subroutine (gets called, and returns) |
| 135 | * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of |
| 136 | * static analysis tools such as stack depth analyzer. |
| 137 | */ |
| 138 | #ifndef ENDPROC |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 139 | /* deprecated, use SYM_FUNC_END */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 140 | #define ENDPROC(name) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 141 | SYM_FUNC_END(name) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 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: |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 152 | #endif |
| 153 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 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) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 158 | #endif |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 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 | .size name, .-name |
| 165 | #endif |
| 166 | |
| 167 | /* === code annotations === */ |
| 168 | |
| 169 | /* |
| 170 | * FUNC -- C-like functions (proper stack frame etc.) |
| 171 | * CODE -- non-C code (e.g. irq handlers with different, special stack etc.) |
| 172 | * |
| 173 | * Objtool validates stack for FUNC, but not for CODE. |
| 174 | * Objtool generates debug info for both FUNC & CODE, but needs special |
| 175 | * annotations for each CODE's start (to describe the actual stack frame). |
| 176 | * |
| 177 | * ALIAS -- does not generate debug info -- the aliased function will |
| 178 | */ |
| 179 | |
| 180 | /* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */ |
| 181 | #ifndef SYM_INNER_LABEL_ALIGN |
| 182 | #define SYM_INNER_LABEL_ALIGN(name, linkage) \ |
| 183 | .type name SYM_T_NONE ASM_NL \ |
| 184 | SYM_ENTRY(name, linkage, SYM_A_ALIGN) |
| 185 | #endif |
| 186 | |
| 187 | /* SYM_INNER_LABEL -- only for labels in the middle of code */ |
| 188 | #ifndef SYM_INNER_LABEL |
| 189 | #define SYM_INNER_LABEL(name, linkage) \ |
| 190 | .type name SYM_T_NONE ASM_NL \ |
| 191 | SYM_ENTRY(name, linkage, SYM_A_NONE) |
| 192 | #endif |
| 193 | |
| 194 | /* |
| 195 | * SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one |
| 196 | * function |
| 197 | */ |
| 198 | #ifndef SYM_FUNC_START_LOCAL_ALIAS |
| 199 | #define SYM_FUNC_START_LOCAL_ALIAS(name) \ |
| 200 | SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN) |
| 201 | #endif |
| 202 | |
| 203 | /* |
| 204 | * SYM_FUNC_START_ALIAS -- use where there are two global names for one |
| 205 | * function |
| 206 | */ |
| 207 | #ifndef SYM_FUNC_START_ALIAS |
| 208 | #define SYM_FUNC_START_ALIAS(name) \ |
| 209 | SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) |
| 210 | #endif |
| 211 | |
| 212 | /* SYM_FUNC_START -- use for global functions */ |
| 213 | #ifndef SYM_FUNC_START |
| 214 | /* |
| 215 | * The same as SYM_FUNC_START_ALIAS, but we will need to distinguish these two |
| 216 | * later. |
| 217 | */ |
| 218 | #define SYM_FUNC_START(name) \ |
| 219 | SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) |
| 220 | #endif |
| 221 | |
| 222 | /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */ |
| 223 | #ifndef SYM_FUNC_START_NOALIGN |
| 224 | #define SYM_FUNC_START_NOALIGN(name) \ |
| 225 | SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE) |
| 226 | #endif |
| 227 | |
| 228 | /* SYM_FUNC_START_LOCAL -- use for local functions */ |
| 229 | #ifndef SYM_FUNC_START_LOCAL |
| 230 | /* the same as SYM_FUNC_START_LOCAL_ALIAS, see comment near SYM_FUNC_START */ |
| 231 | #define SYM_FUNC_START_LOCAL(name) \ |
| 232 | SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN) |
| 233 | #endif |
| 234 | |
| 235 | /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */ |
| 236 | #ifndef SYM_FUNC_START_LOCAL_NOALIGN |
| 237 | #define SYM_FUNC_START_LOCAL_NOALIGN(name) \ |
| 238 | SYM_START(name, SYM_L_LOCAL, SYM_A_NONE) |
| 239 | #endif |
| 240 | |
| 241 | /* SYM_FUNC_START_WEAK -- use for weak functions */ |
| 242 | #ifndef SYM_FUNC_START_WEAK |
| 243 | #define SYM_FUNC_START_WEAK(name) \ |
| 244 | SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN) |
| 245 | #endif |
| 246 | |
| 247 | /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */ |
| 248 | #ifndef SYM_FUNC_START_WEAK_NOALIGN |
| 249 | #define SYM_FUNC_START_WEAK_NOALIGN(name) \ |
| 250 | SYM_START(name, SYM_L_WEAK, SYM_A_NONE) |
| 251 | #endif |
| 252 | |
| 253 | /* SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed function */ |
| 254 | #ifndef SYM_FUNC_END_ALIAS |
| 255 | #define SYM_FUNC_END_ALIAS(name) \ |
| 256 | SYM_END(name, SYM_T_FUNC) |
| 257 | #endif |
| 258 | |
| 259 | /* |
| 260 | * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START, |
| 261 | * SYM_FUNC_START_WEAK, ... |
| 262 | */ |
| 263 | #ifndef SYM_FUNC_END |
| 264 | /* the same as SYM_FUNC_END_ALIAS, see comment near SYM_FUNC_START */ |
| 265 | #define SYM_FUNC_END(name) \ |
| 266 | SYM_END(name, SYM_T_FUNC) |
| 267 | #endif |
| 268 | |
| 269 | /* SYM_CODE_START -- use for non-C (special) functions */ |
| 270 | #ifndef SYM_CODE_START |
| 271 | #define SYM_CODE_START(name) \ |
| 272 | SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) |
| 273 | #endif |
| 274 | |
| 275 | /* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */ |
| 276 | #ifndef SYM_CODE_START_NOALIGN |
| 277 | #define SYM_CODE_START_NOALIGN(name) \ |
| 278 | SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE) |
| 279 | #endif |
| 280 | |
| 281 | /* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */ |
| 282 | #ifndef SYM_CODE_START_LOCAL |
| 283 | #define SYM_CODE_START_LOCAL(name) \ |
| 284 | SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN) |
| 285 | #endif |
| 286 | |
| 287 | /* |
| 288 | * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions, |
| 289 | * w/o alignment |
| 290 | */ |
| 291 | #ifndef SYM_CODE_START_LOCAL_NOALIGN |
| 292 | #define SYM_CODE_START_LOCAL_NOALIGN(name) \ |
| 293 | SYM_START(name, SYM_L_LOCAL, SYM_A_NONE) |
| 294 | #endif |
| 295 | |
| 296 | /* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */ |
| 297 | #ifndef SYM_CODE_END |
| 298 | #define SYM_CODE_END(name) \ |
| 299 | SYM_END(name, SYM_T_NONE) |
| 300 | #endif |
| 301 | |
| 302 | /* === data annotations === */ |
| 303 | |
| 304 | /* SYM_DATA_START -- global data symbol */ |
| 305 | #ifndef SYM_DATA_START |
| 306 | #define SYM_DATA_START(name) \ |
| 307 | SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE) |
| 308 | #endif |
| 309 | |
| 310 | /* SYM_DATA_START -- local data symbol */ |
| 311 | #ifndef SYM_DATA_START_LOCAL |
| 312 | #define SYM_DATA_START_LOCAL(name) \ |
| 313 | SYM_START(name, SYM_L_LOCAL, SYM_A_NONE) |
| 314 | #endif |
| 315 | |
| 316 | /* SYM_DATA_END -- the end of SYM_DATA_START symbol */ |
| 317 | #ifndef SYM_DATA_END |
| 318 | #define SYM_DATA_END(name) \ |
| 319 | SYM_END(name, SYM_T_OBJECT) |
| 320 | #endif |
| 321 | |
| 322 | /* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */ |
| 323 | #ifndef SYM_DATA_END_LABEL |
| 324 | #define SYM_DATA_END_LABEL(name, linkage, label) \ |
| 325 | linkage(label) ASM_NL \ |
| 326 | .type label SYM_T_OBJECT ASM_NL \ |
| 327 | label: \ |
| 328 | SYM_END(name, SYM_T_OBJECT) |
| 329 | #endif |
| 330 | |
| 331 | /* SYM_DATA -- start+end wrapper around simple global data */ |
| 332 | #ifndef SYM_DATA |
| 333 | #define SYM_DATA(name, data...) \ |
| 334 | SYM_DATA_START(name) ASM_NL \ |
| 335 | data ASM_NL \ |
| 336 | SYM_DATA_END(name) |
| 337 | #endif |
| 338 | |
| 339 | /* SYM_DATA_LOCAL -- start+end wrapper around simple local data */ |
| 340 | #ifndef SYM_DATA_LOCAL |
| 341 | #define SYM_DATA_LOCAL(name, data...) \ |
| 342 | SYM_DATA_START_LOCAL(name) ASM_NL \ |
| 343 | data ASM_NL \ |
| 344 | SYM_DATA_END(name) |
| 345 | #endif |
| 346 | |
| 347 | #endif /* __ASSEMBLY__ */ |
| 348 | |
| 349 | #endif /* _LINUX_LINKAGE_H */ |