Commit 2daf7fab authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Peter Zijlstra
Browse files

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

Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarMiroslav Benes <mbenes@suse.cz>
Link: https://lkml.kernel.org/r/9dcaa752f83aca24b1b21f0b0eeb28a0c181c0b0.1650300597.git.jpoimboe@redhat.com
parent aa3d60e0
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -228,14 +228,14 @@ objtool := $(objtree)/tools/objtool/objtool

objtool_args =								\
	$(if $(CONFIG_UNWINDER_ORC),orc generate,check)			\
	$(if $(part-of-module), --module)				\
	$(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt)			\
	$(if $(CONFIG_FRAME_POINTER),, --no-fp)				\
	$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)			\
	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)		\
	$(if $(CONFIG_RETPOLINE), --retpoline)				\
	$(if $(CONFIG_SLS), --sls)					\
	$(if $(CONFIG_X86_SMAP), --uaccess)				\
	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)		\
	$(if $(CONFIG_SLS), --sls)
	$(if $(part-of-module), --module)				\
	$(if $(CONFIG_FRAME_POINTER),, --no-fp)				\
	$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)

cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
+19 −11
Original line number Diff line number Diff line
@@ -117,8 +117,6 @@ objtool_link()
			objtoolcmd="orc generate"
		fi

		objtoolopt="${objtoolopt} --lto"

		if is_enabled CONFIG_X86_KERNEL_IBT; then
			objtoolopt="${objtoolopt} --ibt"
		fi
@@ -126,6 +124,8 @@ objtool_link()
		if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
			objtoolopt="${objtoolopt} --mcount"
		fi

		objtoolopt="${objtoolopt} --lto"
	fi

	if is_enabled CONFIG_VMLINUX_VALIDATION; then
@@ -133,25 +133,33 @@ objtool_link()
	fi

	if [ -n "${objtoolopt}" ]; then

		if [ -z "${objtoolcmd}" ]; then
			objtoolcmd="check"
		fi
		objtoolopt="${objtoolopt} --vmlinux"
		if ! is_enabled CONFIG_FRAME_POINTER; then
			objtoolopt="${objtoolopt} --no-fp"
		fi
		if is_enabled CONFIG_GCOV_KERNEL; then
			objtoolopt="${objtoolopt} --no-unreachable"
		fi

		if is_enabled CONFIG_RETPOLINE; then
			objtoolopt="${objtoolopt} --retpoline"
		fi

		if is_enabled CONFIG_SLS; then
			objtoolopt="${objtoolopt} --sls"
		fi

		if is_enabled CONFIG_X86_SMAP; then
			objtoolopt="${objtoolopt} --uaccess"
		fi
		if is_enabled CONFIG_SLS; then
			objtoolopt="${objtoolopt} --sls"

		if ! is_enabled CONFIG_FRAME_POINTER; then
			objtoolopt="${objtoolopt} --no-fp"
		fi

		if is_enabled CONFIG_GCOV_KERNEL; then
			objtoolopt="${objtoolopt} --no-unreachable"
		fi

		objtoolopt="${objtoolopt} --vmlinux"

		info OBJTOOL ${1}
		tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}
	fi
+1 −1
Original line number Diff line number Diff line
@@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
		break;

	case 0xc7: /* mov imm, r/m */
		if (!noinstr)
		if (!opts.noinstr)
			break;

		if (insn.length == 3+4+4 && !strncmp(sec->name, ".init.text", 10)) {
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt)
		 * find paths that see the STAC but take the NOP instead of
		 * CLAC and the other way around.
		 */
		if (uaccess)
		if (opts.uaccess)
			alt->skip_orig = true;
		else
			alt->skip_alt = true;
+21 −19
Original line number Diff line number Diff line
@@ -19,12 +19,10 @@
#include <objtool/builtin.h>
#include <objtool/objtool.h>

bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
     lto, vmlinux, mcount, noinstr, backup, sls, dryrun,
     ibt;
struct opts opts;

static const char * const check_usage[] = {
	"objtool check [<options>] file.o",
	"objtool check <actions> [<options>] file.o",
	NULL,
};

@@ -34,21 +32,25 @@ static const char * const env_usage[] = {
};

const struct option check_options[] = {
	OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
	OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
	OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
	OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
	OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),
	OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),
	OPT_BOOLEAN('s', "stats", &stats, "print statistics"),
	OPT_BOOLEAN(0, "lto", &lto, "whole-archive like runs"),
	OPT_BOOLEAN('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"),
	OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
	OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"),
	OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modification"),
	OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"),
	OPT_BOOLEAN(0, "dry-run", &dryrun, "don't write the modifications"),
	OPT_BOOLEAN(0, "ibt", &ibt, "validate ENDBR placement"),
	OPT_GROUP("Actions:"),
	OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
	OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
	OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"),
	OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate retpoline usage"),
	OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mitigations"),
	OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SMAP"),

	OPT_GROUP("Options:"),
	OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"),
	OPT_BOOLEAN(0, "backup", &opts.backup, "create .orig files before modification"),
	OPT_BOOLEAN(0, "dry-run", &opts.dryrun, "don't write modifications"),
	OPT_BOOLEAN(0, "lto", &opts.lto, "whole-archive like runs"),
	OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
	OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"),
	OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
	OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
	OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"),

	OPT_END(),
};

Loading