Skip to content

Commit acc8c6a

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Consolidate option validation
The option validations are a bit scattered, consolidate them. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Brendan Jackman <[email protected]> Link: https://lore.kernel.org/r/8f886502fda1d15f39d7351b70d4ebe5903da627.1741975349.git.jpoimboe@kernel.org
1 parent 764d956 commit acc8c6a

File tree

1 file changed

+24
-44
lines changed

1 file changed

+24
-44
lines changed

tools/objtool/builtin-check.c

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])
131131

132132
static bool opts_valid(void)
133133
{
134+
if (opts.mnop && !opts.mcount) {
135+
ERROR("--mnop requires --mcount");
136+
return false;
137+
}
138+
139+
if (opts.noinstr && !opts.link) {
140+
ERROR("--noinstr requires --link");
141+
return false;
142+
}
143+
144+
if (opts.ibt && !opts.link) {
145+
ERROR("--ibt requires --link");
146+
return false;
147+
}
148+
149+
if (opts.unret && !opts.link) {
150+
ERROR("--unret requires --link");
151+
return false;
152+
}
153+
134154
if (opts.hack_jump_label ||
135155
opts.hack_noinstr ||
136156
opts.ibt ||
@@ -158,45 +178,6 @@ static bool opts_valid(void)
158178
return false;
159179
}
160180

161-
static bool mnop_opts_valid(void)
162-
{
163-
if (opts.mnop && !opts.mcount) {
164-
ERROR("--mnop requires --mcount");
165-
return false;
166-
}
167-
168-
return true;
169-
}
170-
171-
static bool link_opts_valid(struct objtool_file *file)
172-
{
173-
if (opts.link)
174-
return true;
175-
176-
if (has_multiple_files(file->elf)) {
177-
ERROR("Linked object detected, forcing --link");
178-
opts.link = true;
179-
return true;
180-
}
181-
182-
if (opts.noinstr) {
183-
ERROR("--noinstr requires --link");
184-
return false;
185-
}
186-
187-
if (opts.ibt) {
188-
ERROR("--ibt requires --link");
189-
return false;
190-
}
191-
192-
if (opts.unret) {
193-
ERROR("--unret requires --link");
194-
return false;
195-
}
196-
197-
return true;
198-
}
199-
200181
int objtool_run(int argc, const char **argv)
201182
{
202183
const char *objname;
@@ -216,11 +197,10 @@ int objtool_run(int argc, const char **argv)
216197
if (!file)
217198
return 1;
218199

219-
if (!mnop_opts_valid())
220-
return 1;
221-
222-
if (!link_opts_valid(file))
223-
return 1;
200+
if (!opts.link && has_multiple_files(file->elf)) {
201+
ERROR("Linked object detected, forcing --link");
202+
opts.link = true;
203+
}
224204

225205
ret = check(file);
226206
if (ret)

0 commit comments

Comments
 (0)