File Index
Files and directories
Sign in
FILE

objtool.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/objtool.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _LINUX_OBJTOOL_H
  3#define _LINUX_OBJTOOL_H
  4
  5#include <linux/objtool_types.h>
  6#include <linux/annotate.h>
  7
  8#ifdef CONFIG_OBJTOOL
  9
 10#ifndef __ASSEMBLY__
 11
 12#define UNWIND_HINT(type, sp_reg, sp_offset, signal)		\
 13	"987: \n\t"						\
 14	".pushsection .discard.unwind_hints\n\t"		\
 15	ANNOTATE_DATA_SPECIAL "\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"			\
 21	".byte " __stringify(signal) "\n\t"			\
 22	".balign 4 \n\t"					\
 23	".popsection\n\t"
 24
 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 *
 31 * For more information, see tools/objtool/Documentation/objtool.txt.
 32 */
 33#define STACK_FRAME_NON_STANDARD(func) \
 34	static void __used __section(".discard.func_stack_frame_non_standard") \
 35		*__func_stack_frame_non_standard_##func = func
 36
 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
 48#define ASM_REACHABLE							\
 49	"998:\n\t"							\
 50	".pushsection .discard.reachable\n\t"				\
 51	".long 998b\n\t"						\
 52	".popsection\n\t"
 53
 54#define __ASM_BREF(label)	label ## b
 55
 56#else /* __ASSEMBLY__ */
 57
 58/*
 59 * In asm, there are two kinds of code: normal C-type callable functions and
 60 * the rest.  The normal callable functions can be called by other code, and
 61 * don't do anything unusual with the stack.  Such normal callable functions
 62 * are annotated with SYM_FUNC_{START,END}.  Most asm code falls in this
 63 * category.  In this case, no special debugging annotations are needed because
 64 * objtool can automatically generate the ORC data for the ORC unwinder to read
 65 * at runtime.
 66 *
 67 * Anything which doesn't fall into the above category, such as syscall and
 68 * interrupt handlers, tends to not be called directly by other functions, and
 69 * often does unusual non-C-function-type things with the stack pointer.  Such
 70 * code needs to be annotated such that objtool can understand it.  The
 71 * following CFI hint macros are for this type of code.
 72 *
 73 * These macros provide hints to objtool about the state of the stack at each
 74 * instruction.  Objtool starts from the hints and follows the code flow,
 75 * making automatic CFI adjustments when it sees pushes and pops, filling out
 76 * the debuginfo as necessary.  It will also warn if it sees any
 77 * inconsistencies.
 78 */
 79.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0
 80.Lhere_\@:
 81	.pushsection .discard.unwind_hints
 82		ANNOTATE_DATA_SPECIAL
 83		/* struct unwind_hint */
 84		.long .Lhere_\@ - .
 85		.short \sp_offset
 86		.byte \sp_reg
 87		.byte \type
 88		.byte \signal
 89		.balign 4
 90	.popsection
 91.endm
 92
 93.macro STACK_FRAME_NON_STANDARD func:req
 94	.pushsection .discard.func_stack_frame_non_standard, "aw"
 95	.quad \func
 96	.popsection
 97.endm
 98
 99.macro STACK_FRAME_NON_STANDARD_FP func:req
100#ifdef CONFIG_FRAME_POINTER
101	STACK_FRAME_NON_STANDARD \func
102#endif
103.endm
104
105#endif /* __ASSEMBLY__ */
106
107#else /* !CONFIG_OBJTOOL */
108
109#ifndef __ASSEMBLY__
110
111#define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t"
112#define STACK_FRAME_NON_STANDARD(func)
113#define STACK_FRAME_NON_STANDARD_FP(func)
114#else
115.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0
116.endm
117.macro STACK_FRAME_NON_STANDARD func:req
118.endm
119#endif
120
121#endif /* CONFIG_OBJTOOL */
122
123#if defined(CONFIG_NOINSTR_VALIDATION) && \
124	(defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO))
125#define VALIDATE_UNRET_BEGIN	ANNOTATE_UNRET_BEGIN
126#else
127#define VALIDATE_UNRET_BEGIN
128#endif
129
130#endif /* _LINUX_OBJTOOL_H */
~/ Read-only file preview.