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

objtool: Fix ANNOTATE_REACHABLE to be a normal annotation

Currently REACHABLE is weird for being on the instruction after the
instruction it modifies.

Since all REACHABLE annotations have an explicit instruction, flip
them around.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/20241128094312.494176035@infradead.org

+8 -32
+1 -1
arch/loongarch/include/asm/bug.h
··· 45 45 #define __WARN_FLAGS(flags) \ 46 46 do { \ 47 47 instrumentation_begin(); \ 48 - __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE);\ 48 + __BUG_FLAGS(BUGFLAG_WARNING|(flags), ANNOTATE_REACHABLE(10001b));\ 49 49 instrumentation_end(); \ 50 50 } while (0) 51 51
+2 -3
arch/x86/entry/entry_64.S
··· 308 308 movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ 309 309 .endif 310 310 311 - call \cfunc 312 - 313 311 /* For some configurations \cfunc ends up being a noreturn. */ 314 312 ANNOTATE_REACHABLE 313 + call \cfunc 315 314 316 315 jmp error_return 317 316 .endm ··· 528 529 movq %rsp, %rdi /* pt_regs pointer into first argument */ 529 530 movq ORIG_RAX(%rsp), %rsi /* get error code into 2nd argument*/ 530 531 movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */ 531 - call \cfunc 532 532 533 533 /* For some configurations \cfunc ends up being a noreturn. */ 534 534 ANNOTATE_REACHABLE 535 + call \cfunc 535 536 536 537 jmp paranoid_exit 537 538
+1 -1
arch/x86/include/asm/bug.h
··· 92 92 do { \ 93 93 __auto_type __flags = BUGFLAG_WARNING|(flags); \ 94 94 instrumentation_begin(); \ 95 - _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE); \ 95 + _BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE(1b)); \ 96 96 instrumentation_end(); \ 97 97 } while (0) 98 98
+2 -2
arch/x86/include/asm/irq_stack.h
··· 100 100 } 101 101 102 102 #define ASM_CALL_ARG0 \ 103 - "call %c[__func] \n" \ 104 - ANNOTATE_REACHABLE 103 + "1: call %c[__func] \n" \ 104 + ANNOTATE_REACHABLE(1b) 105 105 106 106 #define ASM_CALL_ARG1 \ 107 107 "movq %[arg1], %%rdi \n" \
+2 -2
include/linux/objtool.h
··· 177 177 */ 178 178 #define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) 179 179 /* 180 - * This should be used directly after an instruction that is considered 180 + * This should be used to refer to an instruction that is considered 181 181 * terminating, like a noreturn CALL or UD2 when we know they are not -- eg 182 182 * WARN using UD2. 183 183 */ 184 - #define ANNOTATE_REACHABLE ASM_ANNOTATE(ANNOTYPE_REACHABLE) 184 + #define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) 185 185 186 186 #else 187 187 #define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR
-23
tools/objtool/check.c
··· 614 614 return 0; 615 615 } 616 616 617 - static struct instruction *find_last_insn(struct objtool_file *file, 618 - struct section *sec) 619 - { 620 - struct instruction *insn = NULL; 621 - unsigned int offset; 622 - unsigned int end = (sec->sh.sh_size > 10) ? sec->sh.sh_size - 10 : 0; 623 - 624 - for (offset = sec->sh.sh_size - 1; offset >= end && !insn; offset--) 625 - insn = find_insn(file, sec, offset); 626 - 627 - return insn; 628 - } 629 - 630 617 static int create_static_call_sections(struct objtool_file *file) 631 618 { 632 619 struct static_call_site *site; ··· 2267 2280 2268 2281 offset = reloc->sym->offset + reloc_addend(reloc); 2269 2282 insn = find_insn(file, reloc->sym->sec, offset); 2270 - 2271 - /* 2272 - * Reachable annotations are 'funneh' and act on the previous instruction :/ 2273 - */ 2274 - if (type == ANNOTYPE_REACHABLE) { 2275 - if (insn) 2276 - insn = prev_insn_same_sec(file, insn); 2277 - else if (offset == reloc->sym->sec->sh.sh_size) 2278 - insn = find_last_insn(file, reloc->sym->sec); 2279 - } 2280 2283 2281 2284 if (!insn) { 2282 2285 WARN("bad .discard.annotate_insn entry: %d of type %d", reloc_idx(reloc), type);