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

objtool: Remove annotate_{,un}reachable()

There are no users of annotate_reachable() left.

And the annotate_unreachable() usage in unreachable() is plain wrong;
it will hide dangerous fall-through code-gen.

Remove both.

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

+2 -68
-27
include/linux/compiler.h
··· 109 109 110 110 /* Unreachable code */ 111 111 #ifdef CONFIG_OBJTOOL 112 - /* 113 - * These macros help objtool understand GCC code flow for unreachable code. 114 - * The __COUNTER__ based labels are a hack to make each instance of the macros 115 - * unique, to convince GCC not to merge duplicate inline asm statements. 116 - */ 117 - #define __stringify_label(n) #n 118 - 119 - #define __annotate_reachable(c) ({ \ 120 - asm volatile(__stringify_label(c) ":\n\t" \ 121 - ".pushsection .discard.reachable\n\t" \ 122 - ".long " __stringify_label(c) "b - .\n\t" \ 123 - ".popsection\n\t"); \ 124 - }) 125 - #define annotate_reachable() __annotate_reachable(__COUNTER__) 126 - 127 - #define __annotate_unreachable(c) ({ \ 128 - asm volatile(__stringify_label(c) ":\n\t" \ 129 - ".pushsection .discard.unreachable\n\t" \ 130 - ".long " __stringify_label(c) "b - .\n\t" \ 131 - ".popsection\n\t" : : "i" (c)); \ 132 - }) 133 - #define annotate_unreachable() __annotate_unreachable(__COUNTER__) 134 - 135 112 /* Annotate a C jump table to allow objtool to follow the code flow */ 136 113 #define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@progbits #") 137 - 138 114 #else /* !CONFIG_OBJTOOL */ 139 - #define annotate_reachable() 140 - #define annotate_unreachable() 141 115 #define __annotate_jump_table 142 116 #endif /* CONFIG_OBJTOOL */ 143 117 ··· 121 147 * control elsewhere. 122 148 */ 123 149 #define unreachable() do { \ 124 - annotate_unreachable(); \ 125 150 barrier_before_unreachable(); \ 126 151 __builtin_unreachable(); \ 127 152 } while (0)
+2 -41
tools/objtool/check.c
··· 638 638 uint64_t offset; 639 639 640 640 /* 641 - * Check for manually annotated dead ends. 642 - */ 643 - rsec = find_section_by_name(file->elf, ".rela.discard.unreachable"); 644 - if (!rsec) 645 - goto reachable; 646 - 647 - for_each_reloc(rsec, reloc) { 648 - if (reloc->sym->type == STT_SECTION) { 649 - offset = reloc_addend(reloc); 650 - } else if (reloc->sym->local_label) { 651 - offset = reloc->sym->offset; 652 - } else { 653 - WARN("unexpected relocation symbol type in %s", rsec->name); 654 - return -1; 655 - } 656 - 657 - insn = find_insn(file, reloc->sym->sec, offset); 658 - if (insn) 659 - insn = prev_insn_same_sec(file, insn); 660 - else if (offset == reloc->sym->sec->sh.sh_size) { 661 - insn = find_last_insn(file, reloc->sym->sec); 662 - if (!insn) { 663 - WARN("can't find unreachable insn at %s+0x%" PRIx64, 664 - reloc->sym->sec->name, offset); 665 - return -1; 666 - } 667 - } else { 668 - WARN("can't find unreachable insn at %s+0x%" PRIx64, 669 - reloc->sym->sec->name, offset); 670 - return -1; 671 - } 672 - 673 - insn->dead_end = true; 674 - } 675 - 676 - reachable: 677 - /* 678 - * These manually annotated reachable checks are needed for GCC 4.4, 679 - * where the Linux unreachable() macro isn't supported. In that case 680 - * GCC doesn't know the "ud2" is fatal, so it generates code as if it's 681 - * not a dead end. 641 + * UD2 defaults to being a dead-end, allow them to be annotated for 642 + * non-fatal, eg WARN. 682 643 */ 683 644 rsec = find_section_by_name(file->elf, ".rela.discard.reachable"); 684 645 if (!rsec)