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

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Improve tracing of alternative instructions

When tracing function validation, improve the reporting of
alternative instruction by more clearly showing the different
alternatives beginning and end.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-16-alexandre.chartre@oracle.com

authored by

Alexandre Chartre and committed by
Peter Zijlstra
350c7ab8 9b580acc

+125 -13
+6 -12
tools/objtool/check.c
··· 3564 3564 3565 3565 /* ANNOTATE_IGNORE_ALTERNATIVE */ 3566 3566 if (insn->alt_group->ignore) { 3567 - TRACE_INSN(insn, "alt group ignored"); 3567 + TRACE_ALT(insn, "alt group ignored"); 3568 3568 return true; 3569 3569 } 3570 3570 ··· 3680 3680 struct instruction *prev_insn, struct instruction *next_insn, 3681 3681 bool *dead_end) 3682 3682 { 3683 - /* prev_state is not used if there is no disassembly support */ 3683 + /* prev_state and alt_name are not used if there is no disassembly support */ 3684 3684 struct insn_state prev_state __maybe_unused; 3685 + char *alt_name __maybe_unused = NULL; 3685 3686 struct alternative *alt; 3686 3687 u8 visited; 3687 3688 int ret; ··· 3769 3768 return 1; 3770 3769 3771 3770 if (insn->alts) { 3772 - int i, num_alts; 3773 - 3774 - num_alts = 0; 3775 - for (alt = insn->alts; alt; alt = alt->next) 3776 - num_alts++; 3777 - 3778 - i = 1; 3779 3771 for (alt = insn->alts; alt; alt = alt->next) { 3780 - TRACE_INSN(insn, "alternative %d/%d", i, num_alts); 3772 + TRACE_ALT_BEGIN(insn, alt, alt_name); 3781 3773 ret = validate_branch(file, func, alt->insn, *statep); 3774 + TRACE_ALT_END(insn, alt, alt_name); 3782 3775 if (ret) { 3783 3776 BT_INSN(insn, "(alt)"); 3784 3777 return ret; 3785 3778 } 3786 - i++; 3787 3779 } 3788 - TRACE_INSN(insn, "alternative DEFAULT"); 3780 + TRACE_ALT_INFO_NOADDR(insn, "/ ", "DEFAULT"); 3789 3781 } 3790 3782 3791 3783 if (skip_alt_group(insn))
+64 -1
tools/objtool/include/objtool/trace.h
··· 19 19 fprintf(stderr, fmt, ##__VA_ARGS__); \ 20 20 }) 21 21 22 + /* 23 + * Print the instruction address and a message. The instruction 24 + * itself is not printed. 25 + */ 26 + #define TRACE_ADDR(insn, fmt, ...) \ 27 + ({ \ 28 + if (trace) { \ 29 + disas_print_info(stderr, insn, trace_depth - 1, \ 30 + fmt "\n", ##__VA_ARGS__); \ 31 + } \ 32 + }) 33 + 34 + /* 35 + * Print the instruction address, the instruction and a message. 36 + */ 22 37 #define TRACE_INSN(insn, fmt, ...) \ 23 38 ({ \ 24 39 if (trace) { \ 25 40 disas_print_insn(stderr, objtool_disas_ctx, \ 26 - insn, trace_depth - 1, \ 41 + insn, trace_depth - 1, \ 27 42 fmt, ##__VA_ARGS__); \ 28 43 fprintf(stderr, "\n"); \ 29 44 insn->trace = 1; \ ··· 49 34 ({ \ 50 35 if (trace) \ 51 36 trace_insn_state(insn, sprev, snext); \ 37 + }) 38 + 39 + #define TRACE_ALT_FMT(pfx, fmt) pfx "<%s.%lx> " fmt 40 + #define TRACE_ALT_ARG(insn) disas_alt_type_name(insn), (insn)->offset 41 + 42 + #define TRACE_ALT(insn, fmt, ...) \ 43 + TRACE_INSN(insn, TRACE_ALT_FMT("", fmt), \ 44 + TRACE_ALT_ARG(insn), ##__VA_ARGS__) 45 + 46 + #define TRACE_ALT_INFO(insn, pfx, fmt, ...) \ 47 + TRACE_ADDR(insn, TRACE_ALT_FMT(pfx, fmt), \ 48 + TRACE_ALT_ARG(insn), ##__VA_ARGS__) 49 + 50 + #define TRACE_ALT_INFO_NOADDR(insn, pfx, fmt, ...) \ 51 + TRACE_ADDR(NULL, TRACE_ALT_FMT(pfx, fmt), \ 52 + TRACE_ALT_ARG(insn), ##__VA_ARGS__) 53 + 54 + #define TRACE_ALT_BEGIN(insn, alt, alt_name) \ 55 + ({ \ 56 + if (trace) { \ 57 + alt_name = disas_alt_name(alt); \ 58 + trace_alt_begin(insn, alt, alt_name); \ 59 + } \ 60 + }) 61 + 62 + #define TRACE_ALT_END(insn, alt, alt_name) \ 63 + ({ \ 64 + if (trace) { \ 65 + trace_alt_end(insn, alt, alt_name); \ 66 + free(alt_name); \ 67 + } \ 52 68 }) 53 69 54 70 static inline void trace_enable(void) ··· 107 61 108 62 void trace_insn_state(struct instruction *insn, struct insn_state *sprev, 109 63 struct insn_state *snext); 64 + void trace_alt_begin(struct instruction *orig_insn, struct alternative *alt, 65 + char *alt_name); 66 + void trace_alt_end(struct instruction *orig_insn, struct alternative *alt, 67 + char *alt_name); 110 68 111 69 #else /* DISAS */ 112 70 113 71 #define TRACE(fmt, ...) ({}) 72 + #define TRACE_ADDR(insn, fmt, ...) ({}) 114 73 #define TRACE_INSN(insn, fmt, ...) ({}) 115 74 #define TRACE_INSN_STATE(insn, sprev, snext) ({}) 75 + #define TRACE_ALT(insn, fmt, ...) ({}) 76 + #define TRACE_ALT_INFO(insn, fmt, ...) ({}) 77 + #define TRACE_ALT_INFO_NOADDR(insn, fmt, ...) ({}) 78 + #define TRACE_ALT_BEGIN(insn, alt, alt_name) ({}) 79 + #define TRACE_ALT_END(insn, alt, alt_name) ({}) 80 + 116 81 117 82 static inline void trace_enable(void) {} 118 83 static inline void trace_disable(void) {} 119 84 static inline void trace_depth_inc(void) {} 120 85 static inline void trace_depth_dec(void) {} 86 + static inline void trace_alt_begin(struct instruction *orig_insn, 87 + struct alternative *alt, 88 + char *alt_name) {}; 89 + static inline void trace_alt_end(struct instruction *orig_insn, 90 + struct alternative *alt, 91 + char *alt_name) {}; 121 92 122 93 #endif 123 94
+55
tools/objtool/trace.c
··· 146 146 147 147 insn->trace = 1; 148 148 } 149 + 150 + void trace_alt_begin(struct instruction *orig_insn, struct alternative *alt, 151 + char *alt_name) 152 + { 153 + struct instruction *alt_insn; 154 + char suffix[2]; 155 + 156 + alt_insn = alt->insn; 157 + 158 + if (alt->type == ALT_TYPE_EX_TABLE) { 159 + /* 160 + * When there is an exception table then the instruction 161 + * at the original location is executed but it can cause 162 + * an exception. In that case, the execution will be 163 + * redirected to the alternative instruction. 164 + * 165 + * The instruction at the original location can have 166 + * instruction alternatives, so we just print the location 167 + * of the instruction that can cause the exception and 168 + * not the instruction itself. 169 + */ 170 + TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s for instruction at 0x%lx <%s+0x%lx>", 171 + alt_name, 172 + orig_insn->offset, orig_insn->sym->name, 173 + orig_insn->offset - orig_insn->sym->offset); 174 + } else { 175 + TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s", alt_name); 176 + } 177 + 178 + if (alt->type == ALT_TYPE_JUMP_TABLE) { 179 + /* 180 + * For a jump alternative, if the default instruction is 181 + * a NOP then it is replaced with the jmp instruction, 182 + * otherwise it is replaced with a NOP instruction. 183 + */ 184 + trace_depth++; 185 + if (orig_insn->type == INSN_NOP) { 186 + suffix[0] = (orig_insn->len == 5) ? 'q' : '\0'; 187 + TRACE_ADDR(orig_insn, "jmp%-3s %lx <%s+0x%lx>", suffix, 188 + alt_insn->offset, alt_insn->sym->name, 189 + alt_insn->offset - alt_insn->sym->offset); 190 + } else { 191 + TRACE_ADDR(orig_insn, "nop%d", orig_insn->len); 192 + trace_depth--; 193 + } 194 + } 195 + } 196 + 197 + void trace_alt_end(struct instruction *orig_insn, struct alternative *alt, 198 + char *alt_name) 199 + { 200 + if (alt->type == ALT_TYPE_JUMP_TABLE && orig_insn->type == INSN_NOP) 201 + trace_depth--; 202 + TRACE_ALT_INFO_NOADDR(orig_insn, "\\ ", "%s", alt_name); 203 + }