Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool: Add ANNOTATE_DATA_SPECIAL

In preparation for the objtool klp diff subcommand, add an
ANNOTATE_DATA_SPECIAL macro which annotates special section entries so
that objtool can determine their size and location and extract them
when needed.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

+41 -12
+37 -12
include/linux/annotate.h
··· 8 8 9 9 #ifndef __ASSEMBLY__ 10 10 11 - #define __ASM_ANNOTATE(label, type) \ 12 - ".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \ 11 + #define __ASM_ANNOTATE(section, label, type) \ 12 + ".pushsection " section ",\"M\", @progbits, 8\n\t" \ 13 13 ".long " __stringify(label) " - .\n\t" \ 14 14 ".long " __stringify(type) "\n\t" \ 15 15 ".popsection\n\t" 16 16 17 + #define ASM_ANNOTATE_LABEL(label, type) \ 18 + __ASM_ANNOTATE(".discard.annotate_insn", label, type) 19 + 17 20 #define ASM_ANNOTATE(type) \ 18 21 "911:\n\t" \ 19 - __ASM_ANNOTATE(911b, type) 22 + ASM_ANNOTATE_LABEL(911b, type) 23 + 24 + #define ASM_ANNOTATE_DATA(type) \ 25 + "912:\n\t" \ 26 + __ASM_ANNOTATE(".discard.annotate_data", 912b, type) 20 27 21 28 #else /* __ASSEMBLY__ */ 22 29 23 - .macro ANNOTATE type:req 30 + .macro __ANNOTATE section, type 24 31 .Lhere_\@: 25 - .pushsection .discard.annotate_insn,"M",@progbits,8 32 + .pushsection \section, "M", @progbits, 8 26 33 .long .Lhere_\@ - . 27 34 .long \type 28 35 .popsection 36 + .endm 37 + 38 + .macro ANNOTATE type 39 + __ANNOTATE ".discard.annotate_insn", \type 40 + .endm 41 + 42 + .macro ANNOTATE_DATA type 43 + __ANNOTATE ".discard.annotate_data", \type 29 44 .endm 30 45 31 46 #endif /* __ASSEMBLY__ */ 32 47 33 48 #else /* !CONFIG_OBJTOOL */ 34 49 #ifndef __ASSEMBLY__ 35 - #define __ASM_ANNOTATE(label, type) "" 50 + #define ASM_ANNOTATE_LABEL(label, type) "" 36 51 #define ASM_ANNOTATE(type) 52 + #define ASM_ANNOTATE_DATA(type) 37 53 #else /* __ASSEMBLY__ */ 38 - .macro ANNOTATE type:req 54 + .macro ANNOTATE type 55 + .endm 56 + .macro ANNOTATE_DATA type 39 57 .endm 40 58 #endif /* __ASSEMBLY__ */ 41 59 #endif /* !CONFIG_OBJTOOL */ ··· 65 47 * these relocations will never be used for indirect calls. 66 48 */ 67 49 #define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) 68 - #define ANNOTATE_NOENDBR_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOENDBR)) 50 + #define ANNOTATE_NOENDBR_SYM(sym) asm(ASM_ANNOTATE_LABEL(sym, ANNOTYPE_NOENDBR)) 69 51 70 52 /* 71 53 * This should be used immediately before an indirect jump/call. It tells ··· 76 58 /* 77 59 * See linux/instrumentation.h 78 60 */ 79 - #define ANNOTATE_INSTR_BEGIN(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_BEGIN) 80 - #define ANNOTATE_INSTR_END(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_END) 61 + #define ANNOTATE_INSTR_BEGIN(label) ASM_ANNOTATE_LABEL(label, ANNOTYPE_INSTR_BEGIN) 62 + #define ANNOTATE_INSTR_END(label) ASM_ANNOTATE_LABEL(label, ANNOTYPE_INSTR_END) 81 63 /* 82 64 * objtool annotation to ignore the alternatives and only consider the original 83 65 * instruction(s). ··· 101 83 * terminating, like a noreturn CALL or UD2 when we know they are not -- eg 102 84 * WARN using UD2. 103 85 */ 104 - #define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) 86 + #define ANNOTATE_REACHABLE(label) ASM_ANNOTATE_LABEL(label, ANNOTYPE_REACHABLE) 105 87 /* 106 88 * This should not be used; it annotates away CFI violations. There are a few 107 89 * valid use cases like kexec handover to the next kernel image, and there is ··· 110 92 * There are also a few real issues annotated away, like EFI because we can't 111 93 * control the EFI code. 112 94 */ 113 - #define ANNOTATE_NOCFI_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOCFI)) 95 + #define ANNOTATE_NOCFI_SYM(sym) asm(ASM_ANNOTATE_LABEL(sym, ANNOTYPE_NOCFI)) 96 + 97 + /* 98 + * Annotate a special section entry. This emables livepatch module generation 99 + * to find and extract individual special section entries as needed. 100 + */ 101 + #define ANNOTATE_DATA_SPECIAL ASM_ANNOTATE_DATA(ANNOTYPE_DATA_SPECIAL) 114 102 115 103 #else /* __ASSEMBLY__ */ 116 104 #define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR ··· 128 104 #define ANNOTATE_UNRET_BEGIN ANNOTATE type=ANNOTYPE_UNRET_BEGIN 129 105 #define ANNOTATE_REACHABLE ANNOTATE type=ANNOTYPE_REACHABLE 130 106 #define ANNOTATE_NOCFI_SYM ANNOTATE type=ANNOTYPE_NOCFI 107 + #define ANNOTATE_DATA_SPECIAL ANNOTATE_DATA type=ANNOTYPE_DATA_SPECIAL 131 108 #endif /* __ASSEMBLY__ */ 132 109 133 110 #endif /* _LINUX_ANNOTATE_H */
+2
include/linux/objtool_types.h
··· 67 67 #define ANNOTYPE_REACHABLE 8 68 68 #define ANNOTYPE_NOCFI 9 69 69 70 + #define ANNOTYPE_DATA_SPECIAL 1 71 + 70 72 #endif /* _LINUX_OBJTOOL_TYPES_H */
+2
tools/include/linux/objtool_types.h
··· 67 67 #define ANNOTYPE_REACHABLE 8 68 68 #define ANNOTYPE_NOCFI 9 69 69 70 + #define ANNOTYPE_DATA_SPECIAL 1 71 + 70 72 #endif /* _LINUX_OBJTOOL_TYPES_H */