1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_OBJTOOL_H
3 #define _LINUX_OBJTOOL_H
7 #include <linux/types.h>
10 * This struct is used by asm and inline asm code to manually annotate the
11 * location of registers on the stack.
23 * UNWIND_HINT_TYPE_CALL: Indicates that sp_reg+sp_offset resolves to PREV_SP
24 * (the caller's SP right before it made the call). Used for all callable
25 * functions, i.e. all C code and all callable asm functions.
27 * UNWIND_HINT_TYPE_REGS: Used in entry code to indicate that sp_reg+sp_offset
28 * points to a fully populated pt_regs from a syscall, interrupt, or exception.
30 * UNWIND_HINT_TYPE_REGS_PARTIAL: Used in entry code to indicate that
31 * sp_reg+sp_offset points to the iret return frame.
33 * UNWIND_HINT_FUNC: Generate the unwind metadata of a callable function.
34 * Useful for code which doesn't have an ELF function annotation.
36 #define UNWIND_HINT_TYPE_CALL 0
37 #define UNWIND_HINT_TYPE_REGS 1
38 #define UNWIND_HINT_TYPE_REGS_PARTIAL 2
39 #define UNWIND_HINT_TYPE_FUNC 3
41 #ifdef CONFIG_STACK_VALIDATION
45 #define UNWIND_HINT(sp_reg, sp_offset, type, end) \
47 ".pushsection .discard.unwind_hints\n\t" \
48 /* struct unwind_hint */ \
49 ".long 987b - .\n\t" \
50 ".short " __stringify(sp_offset) "\n\t" \
51 ".byte " __stringify(sp_reg) "\n\t" \
52 ".byte " __stringify(type) "\n\t" \
53 ".byte " __stringify(end) "\n\t" \
58 * This macro marks the given function's stack frame as "non-standard", which
59 * tells objtool to ignore the function when doing stack metadata validation.
60 * It should only be used in special cases where you're 100% sure it won't
61 * affect the reliability of frame pointers and kernel stack traces.
63 * For more information, see tools/objtool/Documentation/stack-validation.txt.
65 #define STACK_FRAME_NON_STANDARD(func) \
66 static void __used __section(".discard.func_stack_frame_non_standard") \
67 *__func_stack_frame_non_standard_##func = func
69 #else /* __ASSEMBLY__ */
72 * This macro indicates that the following intra-function call is valid.
73 * Any non-annotated intra-function call will cause objtool to issue a warning.
75 #define ANNOTATE_INTRA_FUNCTION_CALL \
77 .pushsection .discard.intra_function_calls; \
82 * In asm, there are two kinds of code: normal C-type callable functions and
83 * the rest. The normal callable functions can be called by other code, and
84 * don't do anything unusual with the stack. Such normal callable functions
85 * are annotated with the ENTRY/ENDPROC macros. Most asm code falls in this
86 * category. In this case, no special debugging annotations are needed because
87 * objtool can automatically generate the ORC data for the ORC unwinder to read
90 * Anything which doesn't fall into the above category, such as syscall and
91 * interrupt handlers, tends to not be called directly by other functions, and
92 * often does unusual non-C-function-type things with the stack pointer. Such
93 * code needs to be annotated such that objtool can understand it. The
94 * following CFI hint macros are for this type of code.
96 * These macros provide hints to objtool about the state of the stack at each
97 * instruction. Objtool starts from the hints and follows the code flow,
98 * making automatic CFI adjustments when it sees pushes and pops, filling out
99 * the debuginfo as necessary. It will also warn if it sees any
102 .macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0
104 .pushsection .discard.unwind_hints
105 /* struct unwind_hint */
106 .long .Lunwind_hint_ip_\@ - .
115 .macro STACK_FRAME_NON_STANDARD func:req
116 .pushsection .discard.func_stack_frame_non_standard, "aw"
121 #endif /* __ASSEMBLY__ */
123 #else /* !CONFIG_STACK_VALIDATION */
127 #define UNWIND_HINT(sp_reg, sp_offset, type, end) \
129 #define STACK_FRAME_NON_STANDARD(func)
131 #define ANNOTATE_INTRA_FUNCTION_CALL
132 .macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0
134 .macro STACK_FRAME_NON_STANDARD func:req
138 #endif /* CONFIG_STACK_VALIDATION */
140 #endif /* _LINUX_OBJTOOL_H */