Skip to content

Commit b51277e

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Ditch subcommands
Objtool has a fairly singular focus. It runs on object files and does validations and transformations which can be combined in various ways. The subcommand model has never been a good fit, making it awkward to combine and remove options. Remove the "check" and "orc" subcommands in favor of a more traditional cmdline option model. This makes it much more flexible to use, and easier to port individual features to other arches. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/5c61ebf805e90aefc5fa62bc63468ffae53b9df6.1650300597.git.jpoimboe@redhat.com
1 parent 2daf7fa commit b51277e

File tree

10 files changed

+72
-211
lines changed

10 files changed

+72
-211
lines changed

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ ifdef CONFIG_STACK_VALIDATION
227227
objtool := $(objtree)/tools/objtool/objtool
228228

229229
objtool_args = \
230-
$(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
231230
$(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \
232231
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
232+
$(if $(CONFIG_UNWINDER_ORC), --orc) \
233233
$(if $(CONFIG_RETPOLINE), --retpoline) \
234234
$(if $(CONFIG_SLS), --sls) \
235235
$(if $(CONFIG_X86_SMAP), --uaccess) \

scripts/link-vmlinux.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ objtool_link()
113113

114114
# Don't perform vmlinux validation unless explicitly requested,
115115
# but run objtool on vmlinux.o now that we have an object file.
116-
if is_enabled CONFIG_UNWINDER_ORC; then
117-
objtoolcmd="orc generate"
118-
fi
119116

120117
if is_enabled CONFIG_X86_KERNEL_IBT; then
121118
objtoolopt="${objtoolopt} --ibt"
@@ -125,6 +122,10 @@ objtool_link()
125122
objtoolopt="${objtoolopt} --mcount"
126123
fi
127124

125+
if is_enabled CONFIG_UNWINDER_ORC; then
126+
objtoolopt="${objtoolopt} --orc"
127+
fi
128+
128129
objtoolopt="${objtoolopt} --lto"
129130
fi
130131

@@ -134,10 +135,6 @@ objtool_link()
134135

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

137-
if [ -z "${objtoolcmd}" ]; then
138-
objtoolcmd="check"
139-
fi
140-
141138
if is_enabled CONFIG_RETPOLINE; then
142139
objtoolopt="${objtoolopt} --retpoline"
143140
fi
@@ -161,7 +158,7 @@ objtool_link()
161158
objtoolopt="${objtoolopt} --vmlinux"
162159

163160
info OBJTOOL ${1}
164-
tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}
161+
tools/objtool/objtool ${objtoolopt} ${1}
165162
fi
166163
}
167164

tools/objtool/Build

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ objtool-y += arch/$(SRCARCH)/
22

33
objtool-y += weak.o
44

5-
objtool-$(SUBCMD_CHECK) += check.o
6-
objtool-$(SUBCMD_CHECK) += special.o
7-
objtool-$(SUBCMD_ORC) += check.o
8-
objtool-$(SUBCMD_ORC) += orc_gen.o
9-
objtool-$(SUBCMD_ORC) += orc_dump.o
10-
5+
objtool-y += check.o
6+
objtool-y += special.o
117
objtool-y += builtin-check.o
12-
objtool-y += builtin-orc.o
138
objtool-y += elf.o
149
objtool-y += objtool.o
1510

11+
objtool-$(BUILD_ORC) += orc_gen.o
12+
objtool-$(BUILD_ORC) += orc_dump.o
13+
1614
objtool-y += libstring.o
1715
objtool-y += libctype.o
1816
objtool-y += str_error_r.o

tools/objtool/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
3939

4040
AWK = awk
4141

42-
SUBCMD_CHECK := n
43-
SUBCMD_ORC := n
42+
BUILD_ORC := n
4443

4544
ifeq ($(SRCARCH),x86)
46-
SUBCMD_CHECK := y
47-
SUBCMD_ORC := y
45+
BUILD_ORC := y
4846
endif
4947

50-
export SUBCMD_CHECK SUBCMD_ORC
48+
export BUILD_ORC
5149
export srctree OUTPUT CFLAGS SRCARCH AWK
5250
include $(srctree)/tools/build/Makefile.include
5351

tools/objtool/builtin-check.c

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
* Copyright (C) 2015-2017 Josh Poimboeuf <[email protected]>
44
*/
55

6-
/*
7-
* objtool check:
8-
*
9-
* This command analyzes every .o file and ensures the validity of its stack
10-
* trace metadata. It enforces a set of rules on asm code and C inline
11-
* assembly code so that stack traces can be reliable.
12-
*
13-
* For more information, see tools/objtool/Documentation/stack-validation.txt.
14-
*/
15-
166
#include <subcmd/parse-options.h>
177
#include <string.h>
188
#include <stdlib.h>
@@ -22,7 +12,7 @@
2212
struct opts opts;
2313

2414
static const char * const check_usage[] = {
25-
"objtool check <actions> [<options>] file.o",
15+
"objtool <actions> [<options>] file.o",
2616
NULL,
2717
};
2818

@@ -31,14 +21,26 @@ static const char * const env_usage[] = {
3121
NULL,
3222
};
3323

24+
static int parse_dump(const struct option *opt, const char *str, int unset)
25+
{
26+
if (!str || !strcmp(str, "orc")) {
27+
opts.dump_orc = true;
28+
return 0;
29+
}
30+
31+
return -1;
32+
}
33+
3434
const struct option check_options[] = {
3535
OPT_GROUP("Actions:"),
3636
OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
3737
OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
3838
OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"),
39+
OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"),
3940
OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate retpoline usage"),
4041
OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mitigations"),
4142
OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SMAP"),
43+
OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
4244

4345
OPT_GROUP("Options:"),
4446
OPT_BOOLEAN(0, "backtrace", &opts.backtrace, "unwind on error"),
@@ -81,7 +83,31 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])
8183
return argc;
8284
}
8385

84-
int cmd_check(int argc, const char **argv)
86+
static bool opts_valid(void)
87+
{
88+
if (opts.ibt ||
89+
opts.mcount ||
90+
opts.noinstr ||
91+
opts.orc ||
92+
opts.retpoline ||
93+
opts.sls ||
94+
opts.uaccess) {
95+
if (opts.dump_orc) {
96+
fprintf(stderr, "--dump can't be combined with other options\n");
97+
return false;
98+
}
99+
100+
return true;
101+
}
102+
103+
if (opts.dump_orc)
104+
return true;
105+
106+
fprintf(stderr, "At least one command required\n");
107+
return false;
108+
}
109+
110+
int objtool_run(int argc, const char **argv)
85111
{
86112
const char *objname;
87113
struct objtool_file *file;
@@ -90,6 +116,12 @@ int cmd_check(int argc, const char **argv)
90116
argc = cmd_parse_options(argc, argv, check_usage);
91117
objname = argv[0];
92118

119+
if (!opts_valid())
120+
return 1;
121+
122+
if (opts.dump_orc)
123+
return orc_dump(objname);
124+
93125
file = objtool_open_read(objname);
94126
if (!file)
95127
return 1;

tools/objtool/builtin-orc.c

Lines changed: 0 additions & 73 deletions
This file was deleted.

tools/objtool/check.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,6 +3949,14 @@ int check(struct objtool_file *file)
39493949
warnings += ret;
39503950
}
39513951

3952+
if (opts.orc && !list_empty(&file->insn_list)) {
3953+
ret = orc_create(file);
3954+
if (ret < 0)
3955+
goto out;
3956+
warnings += ret;
3957+
}
3958+
3959+
39523960
if (opts.stats) {
39533961
printf("nr_insns_visited: %ld\n", nr_insns_visited);
39543962
printf("nr_cfi: %ld\n", nr_cfi);

tools/objtool/include/objtool/builtin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ extern const struct option check_options[];
1111

1212
struct opts {
1313
/* actions: */
14+
bool dump_orc;
1415
bool ibt;
1516
bool mcount;
1617
bool noinstr;
18+
bool orc;
1719
bool retpoline;
1820
bool sls;
1921
bool uaccess;
@@ -34,7 +36,6 @@ extern struct opts opts;
3436

3537
extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
3638

37-
extern int cmd_check(int argc, const char **argv);
38-
extern int cmd_orc(int argc, const char **argv);
39+
extern int objtool_run(int argc, const char **argv);
3940

4041
#endif /* _BUILTIN_H */

0 commit comments

Comments
 (0)