History

objtool: Reorganize cmdline options

Split the existing options into two groups: actions, which actually do something; and options, which modify the actions in some way. Also there's no need to have short flags for all the non-action options. Reserve short flags for the more important actions. While at it: - change a few of the short flags to be more intuitive - make option descriptions more consistently descriptive - sort options in the source like they are when printed - move options to a global struct

Josh Poimboeuf committed 4 years ago

Commit 2daf7fa1 parent aa3d60e9 files · +108 −78Browse files

Unified · Split

9 files
  1. scripts/Makefile.build +5 −5
  2. scripts/link-vmlinux.sh +19 −11
  3. tools/objtool/arch/x86/decode.c +1 −1
  4. tools/objtool/arch/x86/special.c +1 −1
  5. tools/objtool/builtin-check.c +21 −19
  6. tools/objtool/check.c +31 −31
  7. tools/objtool/elf.c +4 −4
  8. tools/objtool/include/objtool/builtin.h +23 −3
  9. tools/objtool/objtool.c +3 −3
scripts/Makefile.build+5−5
@@ -228,14 +228,14 @@ objtool := $(objtree)/tools/objtool/objtool · 227 unmodified lines
228 228
229objtool_args = \229objtool_args = \
230 $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \230 $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
231 $(if $(part-of-module), --module) \
232 $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \231 $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \
233 $(if $(CONFIG_FRAME_POINTER),, --no-fp) \232 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
234 $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
235 $(if $(CONFIG_RETPOLINE), --retpoline) \233 $(if $(CONFIG_RETPOLINE), --retpoline) \
234 $(if $(CONFIG_SLS), --sls) \
236 $(if $(CONFIG_X86_SMAP), --uaccess) \235 $(if $(CONFIG_X86_SMAP), --uaccess) \
237 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \236 $(if $(part-of-module), --module) \
238 $(if $(CONFIG_SLS), --sls)237 $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
238 $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
239 239
240cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)240cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
241cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)241cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
scripts/link-vmlinux.sh+19−11
@@ -117,8 +117,6 @@ objtool_link() · 116 unmodified lines
117 objtoolcmd="orc generate"117 objtoolcmd="orc generate"
118 fi118 fi
119 119
120 objtoolopt="${objtoolopt} --lto"
121
122 if is_enabled CONFIG_X86_KERNEL_IBT; then120 if is_enabled CONFIG_X86_KERNEL_IBT; then
123 objtoolopt="${objtoolopt} --ibt"121 objtoolopt="${objtoolopt} --ibt"
124 fi122 fi
@@ -126,6 +124,8 @@ objtool_link() · 1 unmodified line
126 if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then124 if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
127 objtoolopt="${objtoolopt} --mcount"125 objtoolopt="${objtoolopt} --mcount"
128 fi126 fi
127
128 objtoolopt="${objtoolopt} --lto"
129 fi129 fi
130 130
131 if is_enabled CONFIG_VMLINUX_VALIDATION; then131 if is_enabled CONFIG_VMLINUX_VALIDATION; then
@@ -133,25 +133,33 @@ objtool_link() · 1 unmodified line
133 fi133 fi
134 134
135 if [ -n "${objtoolopt}" ]; then135 if [ -n "${objtoolopt}" ]; then
136
136 if [ -z "${objtoolcmd}" ]; then137 if [ -z "${objtoolcmd}" ]; then
137 objtoolcmd="check"138 objtoolcmd="check"
138 fi139 fi
139 objtoolopt="${objtoolopt} --vmlinux"140
140 if ! is_enabled CONFIG_FRAME_POINTER; then
141 objtoolopt="${objtoolopt} --no-fp"
142 fi
143 if is_enabled CONFIG_GCOV_KERNEL; then
144 objtoolopt="${objtoolopt} --no-unreachable"
145 fi
146 if is_enabled CONFIG_RETPOLINE; then141 if is_enabled CONFIG_RETPOLINE; then
147 objtoolopt="${objtoolopt} --retpoline"142 objtoolopt="${objtoolopt} --retpoline"
148 fi143 fi
144
145 if is_enabled CONFIG_SLS; then
146 objtoolopt="${objtoolopt} --sls"
147 fi
148
149 if is_enabled CONFIG_X86_SMAP; then149 if is_enabled CONFIG_X86_SMAP; then
150 objtoolopt="${objtoolopt} --uaccess"150 objtoolopt="${objtoolopt} --uaccess"
151 fi151 fi
152 if is_enabled CONFIG_SLS; then152
153 objtoolopt="${objtoolopt} --sls"153 if ! is_enabled CONFIG_FRAME_POINTER; then
154 objtoolopt="${objtoolopt} --no-fp"
154 fi155 fi
156
157 if is_enabled CONFIG_GCOV_KERNEL; then
158 objtoolopt="${objtoolopt} --no-unreachable"
159 fi
160
161 objtoolopt="${objtoolopt} --vmlinux"
162
155 info OBJTOOL ${1}163 info OBJTOOL ${1}
156 tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}164 tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}
157 fi165 fi
tools/objtool/arch/x86/decode.c+1−1
@@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec · 580 unmodified lines
581 break;581 break;
582 582
583 case 0xc7: /* mov imm, r/m */583 case 0xc7: /* mov imm, r/m */
584 if (!noinstr)584 if (!opts.noinstr)
585 break;585 break;
586 586
587 if (insn.length == 3+4+4 && !strncmp(sec->name, ".init.text", 10)) {587 if (insn.length == 3+4+4 && !strncmp(sec->name, ".init.text", 10)) {
tools/objtool/arch/x86/special.c+1−1
@@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt) · 19 unmodified lines
20 * find paths that see the STAC but take the NOP instead of20 * find paths that see the STAC but take the NOP instead of
21 * CLAC and the other way around.21 * CLAC and the other way around.
22 */22 */
23 if (uaccess)23 if (opts.uaccess)
24 alt->skip_orig = true;24 alt->skip_orig = true;
25 else25 else
26 alt->skip_alt = true;26 alt->skip_alt = true;
tools/objtool/builtin-check.c+21−19
@@ -19,12 +19,10 @@ · 18 unmodified lines
19#include <objtool/builtin.h>19#include <objtool/builtin.h>
20#include <objtool/objtool.h>20#include <objtool/objtool.h>
21 21
22bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,22struct opts opts;
23 lto, vmlinux, mcount, noinstr, backup, sls, dryrun,
24 ibt;
25 23
26static const char * const check_usage[] = {24static const char * const check_usage[] = {
27 "objtool check [<options>] file.o",25 "objtool check <actions> [<options>] file.o",
28 NULL,26 NULL,
29};27};
30 28
@@ -34,21 +32,25 @@ static const char * const env_usage[] = { · 3 unmodified lines
34};32};
35 33
36const struct option check_options[] = {34const struct option check_options[] = {
37 OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),35 OPT_GROUP("Actions:"),
38 OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),36 OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
39 OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),37 OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
40 OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),38 OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"),
41 OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),39 OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate retpoline usage"),
42 OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),40 OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mitigations"),
43 OPT_BOOLEAN('s', "stats", &stats, "print statistics"),41 OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SMAP"),
44 OPT_BOOLEAN(0, "lto", &lto, "whole-archive like runs"),42
45 OPT_BOOLEAN('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"),43 OPT_GROUP("Options:"),
46 OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),44 OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"),
47 OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"),45 OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modification"),
48 OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modification"),46 OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
49 OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"),47 OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"),
50 OPT_BOOLEAN(0, "dry-run", &dryrun, "don't write the modifications"),48 OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
51 OPT_BOOLEAN(0, "ibt", &ibt, "validate ENDBR placement"),49 OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"),
50 OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
51 OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
52 OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"),
53
52 OPT_END(),54 OPT_END(),
53};55};
54 56
tools/objtool/check.c+31−31
@@ -273,7 +273,7 @@ static void init_insn_state(struct insn_state *state, struct section *sec) · 272 unmodified lines
273 * not correctly determine insn->call_dest->sec (external symbols do273 * not correctly determine insn->call_dest->sec (external symbols do
274 * not have a section).274 * not have a section).
275 */275 */
276 if (vmlinux && noinstr && sec)276 if (opts.vmlinux && opts.noinstr && sec)
277 state->noinstr = sec->noinstr;277 state->noinstr = sec->noinstr;
278}278}
279 279
@@ -339,7 +339,7 @@ static void *cfi_hash_alloc(unsigned long size) · 59 unmodified lines
339 if (cfi_hash == (void *)-1L) {339 if (cfi_hash == (void *)-1L) {
340 WARN("mmap fail cfi_hash");340 WARN("mmap fail cfi_hash");
341 cfi_hash = NULL;341 cfi_hash = NULL;
342 } else if (stats) {342 } else if (opts.stats) {
343 printf("cfi_bits: %d\n", cfi_bits);343 printf("cfi_bits: %d\n", cfi_bits);
344 }344 }
345 345
@@ -434,7 +434,7 @@ static int decode_instructions(struct objtool_file *file) · 88 unmodified lines
434 }434 }
435 }435 }
436 436
437 if (stats)437 if (opts.stats)
438 printf("nr_insns: %lu\n", nr_insns);438 printf("nr_insns: %lu\n", nr_insns);
439 439
440 return 0;440 return 0;
@@ -497,7 +497,7 @@ static int init_pv_ops(struct objtool_file *file) · 56 unmodified lines
497 struct symbol *sym;497 struct symbol *sym;
498 int idx, nr;498 int idx, nr;
499 499
500 if (!noinstr)500 if (!opts.noinstr)
501 return 0;501 return 0;
502 502
503 file->pv_ops = NULL;503 file->pv_ops = NULL;
@@ -668,7 +668,7 @@ static int create_static_call_sections(struct objtool_file *file) · 164 unmodified lines
668 668
669 key_sym = find_symbol_by_name(file->elf, tmp);669 key_sym = find_symbol_by_name(file->elf, tmp);
670 if (!key_sym) {670 if (!key_sym) {
671 if (!module) {671 if (!opts.module) {
672 WARN("static_call: can't find static_call_key symbol: %s", tmp);672 WARN("static_call: can't find static_call_key symbol: %s", tmp);
673 return -1;673 return -1;
674 }674 }
@@ -761,7 +761,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) · 86 unmodified lines
761 list_for_each_entry(insn, &file->endbr_list, call_node)761 list_for_each_entry(insn, &file->endbr_list, call_node)
762 idx++;762 idx++;
763 763
764 if (stats) {764 if (opts.stats) {
765 printf("ibt: ENDBR at function start: %d\n", file->nr_endbr);765 printf("ibt: ENDBR at function start: %d\n", file->nr_endbr);
766 printf("ibt: ENDBR inside functions: %d\n", file->nr_endbr_int);766 printf("ibt: ENDBR inside functions: %d\n", file->nr_endbr_int);
767 printf("ibt: superfluous ENDBR: %d\n", idx);767 printf("ibt: superfluous ENDBR: %d\n", idx);
@@ -1028,7 +1028,7 @@ static void add_uaccess_safe(struct objtool_file *file) · 260 unmodified lines
1028 struct symbol *func;1028 struct symbol *func;
1029 const char **name;1029 const char **name;
1030 1030
1031 if (!uaccess)1031 if (!opts.uaccess)
1032 return;1032 return;
1033 1033
1034 for (name = uaccess_safe_builtin; *name; name++) {1034 for (name = uaccess_safe_builtin; *name; name++) {
@@ -1170,7 +1170,7 @@ static void annotate_call_site(struct objtool_file *file, · 135 unmodified lines
1170 return;1170 return;
1171 }1171 }
1172 1172
1173 if (mcount && sym->fentry) {1173 if (opts.mcount && sym->fentry) {
1174 if (sibling)1174 if (sibling)
1175 WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);1175 WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
1176 1176
@@ -1256,7 +1256,7 @@ static bool is_first_func_insn(struct objtool_file *file, struct instruction *in · 79 unmodified lines
1256 if (insn->offset == insn->func->offset)1256 if (insn->offset == insn->func->offset)
1257 return true;1257 return true;
1258 1258
1259 if (ibt) {1259 if (opts.ibt) {
1260 struct instruction *prev = prev_insn_same_sym(file, insn);1260 struct instruction *prev = prev_insn_same_sym(file, insn);
1261 1261
1262 if (prev && prev->type == INSN_ENDBR &&1262 if (prev && prev->type == INSN_ENDBR &&
@@ -1699,7 +1699,7 @@ static int add_special_section_alts(struct objtool_file *file) · 436 unmodified lines
1699 free(special_alt);1699 free(special_alt);
1700 }1700 }
1701 1701
1702 if (stats) {1702 if (opts.stats) {
1703 printf("jl\\\tNOP\tJMP\n");1703 printf("jl\\\tNOP\tJMP\n");
1704 printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short);1704 printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short);
1705 printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long);1705 printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long);
@@ -1945,7 +1945,7 @@ static int read_unwind_hints(struct objtool_file *file) · 239 unmodified lines
1945 1945
1946 insn->hint = true;1946 insn->hint = true;
1947 1947
1948 if (ibt && hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {1948 if (opts.ibt && hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {
1949 struct symbol *sym = find_symbol_by_offset(insn->sec, insn->offset);1949 struct symbol *sym = find_symbol_by_offset(insn->sec, insn->offset);
1950 1950
1951 if (sym && sym->bind == STB_GLOBAL &&1951 if (sym && sym->bind == STB_GLOBAL &&
@@ -2806,7 +2806,7 @@ static int update_cfi_state(struct instruction *insn, · 854 unmodified lines
2806 }2806 }
2807 2807
2808 /* detect when asm code uses rbp as a scratch register */2808 /* detect when asm code uses rbp as a scratch register */
2809 if (!no_fp && insn->func && op->src.reg == CFI_BP &&2809 if (!opts.no_fp && insn->func && op->src.reg == CFI_BP &&
2810 cfa->base != CFI_BP)2810 cfa->base != CFI_BP)
2811 cfi->bp_scratch = true;2811 cfi->bp_scratch = true;
2812 break;2812 break;
@@ -3363,7 +3363,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 550 unmodified lines
3363 3363
3364 ret = validate_branch(file, func, alt->insn, state);3364 ret = validate_branch(file, func, alt->insn, state);
3365 if (ret) {3365 if (ret) {
3366 if (backtrace)3366 if (opts.backtrace)
3367 BT_FUNC("(alt)", insn);3367 BT_FUNC("(alt)", insn);
3368 return ret;3368 return ret;
3369 }3369 }
@@ -3379,7 +3379,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 9 unmodified lines
3379 switch (insn->type) {3379 switch (insn->type) {
3380 3380
3381 case INSN_RETURN:3381 case INSN_RETURN:
3382 if (sls && !insn->retpoline_safe &&3382 if (opts.sls && !insn->retpoline_safe &&
3383 next_insn && next_insn->type != INSN_TRAP) {3383 next_insn && next_insn->type != INSN_TRAP) {
3384 WARN_FUNC("missing int3 after ret",3384 WARN_FUNC("missing int3 after ret",
3385 insn->sec, insn->offset);3385 insn->sec, insn->offset);
@@ -3392,7 +3392,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 6 unmodified lines
3392 if (ret)3392 if (ret)
3393 return ret;3393 return ret;
3394 3394
3395 if (!no_fp && func && !is_fentry_call(insn) &&3395 if (!opts.no_fp && func && !is_fentry_call(insn) &&
3396 !has_valid_stack_frame(&state)) {3396 !has_valid_stack_frame(&state)) {
3397 WARN_FUNC("call without frame pointer save/setup",3397 WARN_FUNC("call without frame pointer save/setup",
3398 sec, insn->offset);3398 sec, insn->offset);
@@ -3415,7 +3415,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 16 unmodified lines
3415 ret = validate_branch(file, func,3415 ret = validate_branch(file, func,
3416 insn->jump_dest, state);3416 insn->jump_dest, state);
3417 if (ret) {3417 if (ret) {
3418 if (backtrace)3418 if (opts.backtrace)
3419 BT_FUNC("(branch)", insn);3419 BT_FUNC("(branch)", insn);
3420 return ret;3420 return ret;
3421 }3421 }
@@ -3427,7 +3427,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 5 unmodified lines
3427 break;3427 break;
3428 3428
3429 case INSN_JUMP_DYNAMIC:3429 case INSN_JUMP_DYNAMIC:
3430 if (sls && !insn->retpoline_safe &&3430 if (opts.sls && !insn->retpoline_safe &&
3431 next_insn && next_insn->type != INSN_TRAP) {3431 next_insn && next_insn->type != INSN_TRAP) {
3432 WARN_FUNC("missing int3 after indirect jump",3432 WARN_FUNC("missing int3 after indirect jump",
3433 insn->sec, insn->offset);3433 insn->sec, insn->offset);
@@ -3499,7 +3499,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, · 65 unmodified lines
3499 break;3499 break;
3500 }3500 }
3501 3501
3502 if (ibt)3502 if (opts.ibt)
3503 validate_ibt_insn(file, insn);3503 validate_ibt_insn(file, insn);
3504 3504
3505 if (insn->dead_end)3505 if (insn->dead_end)
@@ -3541,7 +3541,7 @@ static int validate_unwind_hints(struct objtool_file *file, struct section *sec) · 35 unmodified lines
3541 while (&insn->list != &file->insn_list && (!sec || insn->sec == sec)) {3541 while (&insn->list != &file->insn_list && (!sec || insn->sec == sec)) {
3542 if (insn->hint && !insn->visited && !insn->ignore) {3542 if (insn->hint && !insn->visited && !insn->ignore) {
3543 ret = validate_branch(file, insn->func, insn, state);3543 ret = validate_branch(file, insn->func, insn, state);
3544 if (ret && backtrace)3544 if (ret && opts.backtrace)
3545 BT_FUNC("<=== (hint)", insn);3545 BT_FUNC("<=== (hint)", insn);
3546 warnings += ret;3546 warnings += ret;
3547 }3547 }
@@ -3571,7 +3571,7 @@ static int validate_retpoline(struct objtool_file *file) · 23 unmodified lines
3571 * loaded late, they very much do need retpoline in their3571 * loaded late, they very much do need retpoline in their
3572 * .init.text3572 * .init.text
3573 */3573 */
3574 if (!strcmp(insn->sec->name, ".init.text") && !module)3574 if (!strcmp(insn->sec->name, ".init.text") && !opts.module)
3575 continue;3575 continue;
3576 3576
3577 WARN_FUNC("indirect %s found in RETPOLINE build",3577 WARN_FUNC("indirect %s found in RETPOLINE build",
@@ -3621,7 +3621,7 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio · 43 unmodified lines
3621 * In this case we'll find a piece of code (whole function) that is not3621 * In this case we'll find a piece of code (whole function) that is not
3622 * covered by a !section symbol. Ignore them.3622 * covered by a !section symbol. Ignore them.
3623 */3623 */
3624 if (!insn->func && lto) {3624 if (!insn->func && opts.lto) {
3625 int size = find_symbol_hole_containing(insn->sec, insn->offset);3625 int size = find_symbol_hole_containing(insn->sec, insn->offset);
3626 unsigned long end = insn->offset + size;3626 unsigned long end = insn->offset + size;
3627 3627
@@ -3728,7 +3728,7 @@ static int validate_symbol(struct objtool_file *file, struct section *sec, · 100 unmodified lines
3728 state->uaccess = sym->uaccess_safe;3728 state->uaccess = sym->uaccess_safe;
3729 3729
3730 ret = validate_branch(file, insn->func, insn, *state);3730 ret = validate_branch(file, insn->func, insn, *state);
3731 if (ret && backtrace)3731 if (ret && opts.backtrace)
3732 BT_FUNC("<=== (sym)", insn);3732 BT_FUNC("<=== (sym)", insn);
3733 return ret;3733 return ret;
3734}3734}
@@ -3853,12 +3853,12 @@ int check(struct objtool_file *file) · 118 unmodified lines
3853{3853{
3854 int ret, warnings = 0;3854 int ret, warnings = 0;
3855 3855
3856 if (lto && !(vmlinux || module)) {3856 if (opts.lto && !(opts.vmlinux || opts.module)) {
3857 fprintf(stderr, "--lto requires: --vmlinux or --module\n");3857 fprintf(stderr, "--lto requires: --vmlinux or --module\n");
3858 return 1;3858 return 1;
3859 }3859 }
3860 3860
3861 if (ibt && !lto) {3861 if (opts.ibt && !opts.lto) {
3862 fprintf(stderr, "--ibt requires: --lto\n");3862 fprintf(stderr, "--ibt requires: --lto\n");
3863 return 1;3863 return 1;
3864 }3864 }
@@ -3883,7 +3883,7 @@ int check(struct objtool_file *file) · 18 unmodified lines
3883 if (list_empty(&file->insn_list))3883 if (list_empty(&file->insn_list))
3884 goto out;3884 goto out;
3885 3885
3886 if (vmlinux && !lto) {3886 if (opts.vmlinux && !opts.lto) {
3887 ret = validate_vmlinux_functions(file);3887 ret = validate_vmlinux_functions(file);
3888 if (ret < 0)3888 if (ret < 0)
3889 goto out;3889 goto out;
@@ -3892,7 +3892,7 @@ int check(struct objtool_file *file) · 2 unmodified lines
3892 goto out;3892 goto out;
3893 }3893 }
3894 3894
3895 if (retpoline) {3895 if (opts.retpoline) {
3896 ret = validate_retpoline(file);3896 ret = validate_retpoline(file);
3897 if (ret < 0)3897 if (ret < 0)
3898 return ret;3898 return ret;
@@ -3909,7 +3909,7 @@ int check(struct objtool_file *file) · 10 unmodified lines
3909 goto out;3909 goto out;
3910 warnings += ret;3910 warnings += ret;
3911 3911
3912 if (ibt) {3912 if (opts.ibt) {
3913 ret = validate_ibt(file);3913 ret = validate_ibt(file);
3914 if (ret < 0)3914 if (ret < 0)
3915 goto out;3915 goto out;
@@ -3928,28 +3928,28 @@ int check(struct objtool_file *file) · 12 unmodified lines
3928 goto out;3928 goto out;
3929 warnings += ret;3929 warnings += ret;
3930 3930
3931 if (retpoline) {3931 if (opts.retpoline) {
3932 ret = create_retpoline_sites_sections(file);3932 ret = create_retpoline_sites_sections(file);
3933 if (ret < 0)3933 if (ret < 0)
3934 goto out;3934 goto out;
3935 warnings += ret;3935 warnings += ret;
3936 }3936 }
3937 3937
3938 if (mcount) {3938 if (opts.mcount) {
3939 ret = create_mcount_loc_sections(file);3939 ret = create_mcount_loc_sections(file);
3940 if (ret < 0)3940 if (ret < 0)
3941 goto out;3941 goto out;
3942 warnings += ret;3942 warnings += ret;
3943 }3943 }
3944 3944
3945 if (ibt) {3945 if (opts.ibt) {
3946 ret = create_ibt_endbr_seal_sections(file);3946 ret = create_ibt_endbr_seal_sections(file);
3947 if (ret < 0)3947 if (ret < 0)
3948 goto out;3948 goto out;
3949 warnings += ret;3949 warnings += ret;
3950 }3950 }
3951 3951
3952 if (stats) {3952 if (opts.stats) {
3953 printf("nr_insns_visited: %ld\n", nr_insns_visited);3953 printf("nr_insns_visited: %ld\n", nr_insns_visited);
3954 printf("nr_cfi: %ld\n", nr_cfi);3954 printf("nr_cfi: %ld\n", nr_cfi);
3955 printf("nr_cfi_reused: %ld\n", nr_cfi_reused);3955 printf("nr_cfi_reused: %ld\n", nr_cfi_reused);
tools/objtool/elf.c+4−4
@@ -355,7 +355,7 @@ static int read_sections(struct elf *elf) · 354 unmodified lines
355 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));355 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));
356 }356 }
357 357
358 if (stats) {358 if (opts.stats) {
359 printf("nr_sections: %lu\n", (unsigned long)sections_nr);359 printf("nr_sections: %lu\n", (unsigned long)sections_nr);
360 printf("section_bits: %d\n", elf->section_bits);360 printf("section_bits: %d\n", elf->section_bits);
361 }361 }
@@ -475,7 +475,7 @@ static int read_symbols(struct elf *elf) · 113 unmodified lines
475 elf_add_symbol(elf, sym);475 elf_add_symbol(elf, sym);
476 }476 }
477 477
478 if (stats) {478 if (opts.stats) {
479 printf("nr_symbols: %lu\n", (unsigned long)symbols_nr);479 printf("nr_symbols: %lu\n", (unsigned long)symbols_nr);
480 printf("symbol_bits: %d\n", elf->symbol_bits);480 printf("symbol_bits: %d\n", elf->symbol_bits);
481 }481 }
@@ -843,7 +843,7 @@ static int read_relocs(struct elf *elf) · 361 unmodified lines
843 tot_reloc += nr_reloc;843 tot_reloc += nr_reloc;
844 }844 }
845 845
846 if (stats) {846 if (opts.stats) {
847 printf("max_reloc: %lu\n", max_reloc);847 printf("max_reloc: %lu\n", max_reloc);
848 printf("tot_reloc: %lu\n", tot_reloc);848 printf("tot_reloc: %lu\n", tot_reloc);
849 printf("reloc_bits: %d\n", elf->reloc_bits);849 printf("reloc_bits: %d\n", elf->reloc_bits);
@@ -1222,7 +1222,7 @@ int elf_write(struct elf *elf) · 372 unmodified lines
1222 struct section *sec;1222 struct section *sec;
1223 Elf_Scn *s;1223 Elf_Scn *s;
1224 1224
1225 if (dryrun)1225 if (opts.dryrun)
1226 return 0;1226 return 0;
1227 1227
1228 /* Update changed relocation sections and section headers: */1228 /* Update changed relocation sections and section headers: */
tools/objtool/include/objtool/builtin.h+23−3
@@ -8,9 +8,29 @@ · 7 unmodified lines
8#include <subcmd/parse-options.h>8#include <subcmd/parse-options.h>
9 9
10extern const struct option check_options[];10extern const struct option check_options[];
11extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,11
12 lto, vmlinux, mcount, noinstr, backup, sls, dryrun,12struct opts {
13 ibt;13 /* actions: */
14 bool ibt;
15 bool mcount;
16 bool noinstr;
17 bool retpoline;
18 bool sls;
19 bool uaccess;
20
21 /* options: */
22 bool backtrace;
23 bool backup;
24 bool dryrun;
25 bool lto;
26 bool module;
27 bool no_fp;
28 bool no_unreachable;
29 bool stats;
30 bool vmlinux;
31};
32
33extern struct opts opts;
14 34
15extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);35extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
16 36
tools/objtool/objtool.c+3−3
@@ -118,7 +118,7 @@ struct objtool_file *objtool_open_read(const char *_objname) · 117 unmodified lines
118 if (!file.elf)118 if (!file.elf)
119 return NULL;119 return NULL;
120 120
121 if (backup && !objtool_create_backup(objname)) {121 if (opts.backup && !objtool_create_backup(objname)) {
122 WARN("can't create backup file");122 WARN("can't create backup file");
123 return NULL;123 return NULL;
124 }124 }
@@ -129,7 +129,7 @@ struct objtool_file *objtool_open_read(const char *_objname) · 4 unmodified lines
129 INIT_LIST_HEAD(&file.static_call_list);129 INIT_LIST_HEAD(&file.static_call_list);
130 INIT_LIST_HEAD(&file.mcount_loc_list);130 INIT_LIST_HEAD(&file.mcount_loc_list);
131 INIT_LIST_HEAD(&file.endbr_list);131 INIT_LIST_HEAD(&file.endbr_list);
132 file.ignore_unreachables = no_unreachable;132 file.ignore_unreachables = opts.no_unreachable;
133 file.hints = false;133 file.hints = false;
134 134
135 return &file;135 return &file;
@@ -137,7 +137,7 @@ struct objtool_file *objtool_open_read(const char *_objname) · 1 unmodified line
137 137
138void objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func)138void objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func)
139{139{
140 if (!noinstr)140 if (!opts.noinstr)
141 return;141 return;
142 142
143 if (!f->pv_ops) {143 if (!f->pv_ops) {