[tip: objtool/core] objtool: Consolidate option validation
From: tip-bot2 for Josh Poimboeuf
Date: Mon Mar 17 2025 - 06:47:18 EST
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: acc8c6a798a011a5fe37b455b0286a85a4164b47
Gitweb: https://git.kernel.org/tip/acc8c6a798a011a5fe37b455b0286a85a4164b47
Author: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
AuthorDate: Fri, 14 Mar 2025 12:29:05 -07:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Mon, 17 Mar 2025 11:36:01 +01:00
objtool: Consolidate option validation
The option validations are a bit scattered, consolidate them.
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
Link: https://lore.kernel.org/r/8f886502fda1d15f39d7351b70d4ebe5903da627.1741975349.git.jpoimboe@xxxxxxxxxx
---
tools/objtool/builtin-check.c | 68 ++++++++++++----------------------
1 file changed, 24 insertions(+), 44 deletions(-)
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index c7275cf..36d81a4 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -131,6 +131,26 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])
static bool opts_valid(void)
{
+ if (opts.mnop && !opts.mcount) {
+ ERROR("--mnop requires --mcount");
+ return false;
+ }
+
+ if (opts.noinstr && !opts.link) {
+ ERROR("--noinstr requires --link");
+ return false;
+ }
+
+ if (opts.ibt && !opts.link) {
+ ERROR("--ibt requires --link");
+ return false;
+ }
+
+ if (opts.unret && !opts.link) {
+ ERROR("--unret requires --link");
+ return false;
+ }
+
if (opts.hack_jump_label ||
opts.hack_noinstr ||
opts.ibt ||
@@ -158,45 +178,6 @@ static bool opts_valid(void)
return false;
}
-static bool mnop_opts_valid(void)
-{
- if (opts.mnop && !opts.mcount) {
- ERROR("--mnop requires --mcount");
- return false;
- }
-
- return true;
-}
-
-static bool link_opts_valid(struct objtool_file *file)
-{
- if (opts.link)
- return true;
-
- if (has_multiple_files(file->elf)) {
- ERROR("Linked object detected, forcing --link");
- opts.link = true;
- return true;
- }
-
- if (opts.noinstr) {
- ERROR("--noinstr requires --link");
- return false;
- }
-
- if (opts.ibt) {
- ERROR("--ibt requires --link");
- return false;
- }
-
- if (opts.unret) {
- ERROR("--unret requires --link");
- return false;
- }
-
- return true;
-}
-
int objtool_run(int argc, const char **argv)
{
const char *objname;
@@ -216,11 +197,10 @@ int objtool_run(int argc, const char **argv)
if (!file)
return 1;
- if (!mnop_opts_valid())
- return 1;
-
- if (!link_opts_valid(file))
- return 1;
+ if (!opts.link && has_multiple_files(file->elf)) {
+ ERROR("Linked object detected, forcing --link");
+ opts.link = true;
+ }
ret = check(file);
if (ret)