Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
00089c04 JT |
2 | #ifndef _LINUX_OBJTOOL_H |
3 | #define _LINUX_OBJTOOL_H | |
9a99417a | 4 | |
f7515d9f | 5 | #include <linux/objtool_types.h> |
ee819aed | 6 | |
03f16cd0 | 7 | #ifdef CONFIG_OBJTOOL |
5567c6c3 | 8 | |
e2ef1158 PZ |
9 | #include <asm/asm.h> |
10 | ||
5567c6c3 | 11 | #ifndef __ASSEMBLY__ |
ee819aed | 12 | |
fb799447 | 13 | #define UNWIND_HINT(type, sp_reg, sp_offset, signal) \ |
ee819aed JT |
14 | "987: \n\t" \ |
15 | ".pushsection .discard.unwind_hints\n\t" \ | |
16 | /* struct unwind_hint */ \ | |
17 | ".long 987b - .\n\t" \ | |
18 | ".short " __stringify(sp_offset) "\n\t" \ | |
19 | ".byte " __stringify(sp_reg) "\n\t" \ | |
20 | ".byte " __stringify(type) "\n\t" \ | |
ffb1b4a4 | 21 | ".byte " __stringify(signal) "\n\t" \ |
ee819aed JT |
22 | ".balign 4 \n\t" \ |
23 | ".popsection\n\t" | |
24 | ||
9a99417a JP |
25 | /* |
26 | * This macro marks the given function's stack frame as "non-standard", which | |
27 | * tells objtool to ignore the function when doing stack metadata validation. | |
28 | * It should only be used in special cases where you're 100% sure it won't | |
29 | * affect the reliability of frame pointers and kernel stack traces. | |
30 | * | |
d6a21f2d | 31 | * For more information, see tools/objtool/Documentation/objtool.txt. |
9a99417a JP |
32 | */ |
33 | #define STACK_FRAME_NON_STANDARD(func) \ | |
33def849 | 34 | static void __used __section(".discard.func_stack_frame_non_standard") \ |
9a99417a JP |
35 | *__func_stack_frame_non_standard_##func = func |
36 | ||
e028c4f7 JP |
37 | /* |
38 | * STACK_FRAME_NON_STANDARD_FP() is a frame-pointer-specific function ignore | |
39 | * for the case where a function is intentionally missing frame pointer setup, | |
40 | * but otherwise needs objtool/ORC coverage when frame pointers are disabled. | |
41 | */ | |
42 | #ifdef CONFIG_FRAME_POINTER | |
43 | #define STACK_FRAME_NON_STANDARD_FP(func) STACK_FRAME_NON_STANDARD(func) | |
44 | #else | |
45 | #define STACK_FRAME_NON_STANDARD_FP(func) | |
46 | #endif | |
47 | ||
c8c301ab PZ |
48 | #define ANNOTATE_NOENDBR \ |
49 | "986: \n\t" \ | |
50 | ".pushsection .discard.noendbr\n\t" \ | |
b8ec60e1 | 51 | ".long 986b\n\t" \ |
c8c301ab PZ |
52 | ".popsection\n\t" |
53 | ||
dca5da2a PZ |
54 | #define ASM_REACHABLE \ |
55 | "998:\n\t" \ | |
56 | ".pushsection .discard.reachable\n\t" \ | |
b8ec60e1 | 57 | ".long 998b\n\t" \ |
dca5da2a PZ |
58 | ".popsection\n\t" |
59 | ||
5567c6c3 JT |
60 | #else /* __ASSEMBLY__ */ |
61 | ||
8aa8eb2a AC |
62 | /* |
63 | * This macro indicates that the following intra-function call is valid. | |
64 | * Any non-annotated intra-function call will cause objtool to issue a warning. | |
65 | */ | |
66 | #define ANNOTATE_INTRA_FUNCTION_CALL \ | |
67 | 999: \ | |
68 | .pushsection .discard.intra_function_calls; \ | |
b8ec60e1 | 69 | .long 999b; \ |
8aa8eb2a AC |
70 | .popsection; |
71 | ||
ee819aed JT |
72 | /* |
73 | * In asm, there are two kinds of code: normal C-type callable functions and | |
74 | * the rest. The normal callable functions can be called by other code, and | |
75 | * don't do anything unusual with the stack. Such normal callable functions | |
76 | * are annotated with the ENTRY/ENDPROC macros. Most asm code falls in this | |
77 | * category. In this case, no special debugging annotations are needed because | |
78 | * objtool can automatically generate the ORC data for the ORC unwinder to read | |
79 | * at runtime. | |
80 | * | |
81 | * Anything which doesn't fall into the above category, such as syscall and | |
82 | * interrupt handlers, tends to not be called directly by other functions, and | |
83 | * often does unusual non-C-function-type things with the stack pointer. Such | |
84 | * code needs to be annotated such that objtool can understand it. The | |
85 | * following CFI hint macros are for this type of code. | |
86 | * | |
87 | * These macros provide hints to objtool about the state of the stack at each | |
88 | * instruction. Objtool starts from the hints and follows the code flow, | |
89 | * making automatic CFI adjustments when it sees pushes and pops, filling out | |
90 | * the debuginfo as necessary. It will also warn if it sees any | |
91 | * inconsistencies. | |
92 | */ | |
fb799447 | 93 | .macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0 |
1c0c1faf | 94 | .Lhere_\@: |
ee819aed JT |
95 | .pushsection .discard.unwind_hints |
96 | /* struct unwind_hint */ | |
1c0c1faf | 97 | .long .Lhere_\@ - . |
ee819aed JT |
98 | .short \sp_offset |
99 | .byte \sp_reg | |
100 | .byte \type | |
ffb1b4a4 | 101 | .byte \signal |
ee819aed JT |
102 | .balign 4 |
103 | .popsection | |
104 | .endm | |
105 | ||
081df943 JP |
106 | .macro STACK_FRAME_NON_STANDARD func:req |
107 | .pushsection .discard.func_stack_frame_non_standard, "aw" | |
1c0c1faf | 108 | .long \func - . |
081df943 JP |
109 | .popsection |
110 | .endm | |
111 | ||
7b6c7a87 JP |
112 | .macro STACK_FRAME_NON_STANDARD_FP func:req |
113 | #ifdef CONFIG_FRAME_POINTER | |
114 | STACK_FRAME_NON_STANDARD \func | |
115 | #endif | |
116 | .endm | |
117 | ||
c8c301ab PZ |
118 | .macro ANNOTATE_NOENDBR |
119 | .Lhere_\@: | |
120 | .pushsection .discard.noendbr | |
b8ec60e1 | 121 | .long .Lhere_\@ |
c8c301ab PZ |
122 | .popsection |
123 | .endm | |
124 | ||
4708ea14 JP |
125 | /* |
126 | * Use objtool to validate the entry requirement that all code paths do | |
127 | * VALIDATE_UNRET_END before RET. | |
128 | * | |
129 | * NOTE: The macro must be used at the beginning of a global symbol, otherwise | |
130 | * it will be ignored. | |
131 | */ | |
132 | .macro VALIDATE_UNRET_BEGIN | |
eeb9f34d | 133 | #if defined(CONFIG_NOINSTR_VALIDATION) && \ |
a033eec9 | 134 | (defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO)) |
4708ea14 JP |
135 | .Lhere_\@: |
136 | .pushsection .discard.validate_unret | |
137 | .long .Lhere_\@ - . | |
138 | .popsection | |
139 | #endif | |
140 | .endm | |
141 | ||
dca5da2a PZ |
142 | .macro REACHABLE |
143 | .Lhere_\@: | |
144 | .pushsection .discard.reachable | |
b8ec60e1 | 145 | .long .Lhere_\@ |
dca5da2a PZ |
146 | .popsection |
147 | .endm | |
148 | ||
5567c6c3 JT |
149 | #endif /* __ASSEMBLY__ */ |
150 | ||
03f16cd0 | 151 | #else /* !CONFIG_OBJTOOL */ |
9a99417a | 152 | |
ee819aed JT |
153 | #ifndef __ASSEMBLY__ |
154 | ||
fb799447 | 155 | #define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t" |
9a99417a | 156 | #define STACK_FRAME_NON_STANDARD(func) |
e028c4f7 | 157 | #define STACK_FRAME_NON_STANDARD_FP(func) |
c8c301ab | 158 | #define ANNOTATE_NOENDBR |
dca5da2a | 159 | #define ASM_REACHABLE |
ee819aed | 160 | #else |
8aa8eb2a | 161 | #define ANNOTATE_INTRA_FUNCTION_CALL |
fb799447 | 162 | .macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0 |
ee819aed | 163 | .endm |
081df943 JP |
164 | .macro STACK_FRAME_NON_STANDARD func:req |
165 | .endm | |
c8c301ab PZ |
166 | .macro ANNOTATE_NOENDBR |
167 | .endm | |
dca5da2a PZ |
168 | .macro REACHABLE |
169 | .endm | |
ee819aed | 170 | #endif |
9a99417a | 171 | |
03f16cd0 | 172 | #endif /* CONFIG_OBJTOOL */ |
9a99417a | 173 | |
00089c04 | 174 | #endif /* _LINUX_OBJTOOL_H */ |