All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Helsley <mhelsley@vmware.com>
To: <linux-kernel@vger.kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Julien Thierry <jthierry@redhat.com>,
	Miroslav Benes <mbenes@suse.cz>,
	Steven Rostedt <rostedt@goodmis.org>,
	Matt Helsley <mhelsley@vmware.com>
Subject: [RFC][PATCH 5/5] objtool: Report missing support for subcommands
Date: Mon, 11 May 2020 10:35:13 -0700	[thread overview]
Message-ID: <38a0c7a1ec8d98238379a322866c0432befc259b.1588888003.git.mhelsley@vmware.com> (raw)
In-Reply-To: <cover.1588888003.git.mhelsley@vmware.com>

The check and orc-related subcommands for objtool are x86-specific.
To make this clear to anyone using the tool return a non-zero exit
code and indicate in the help and usage output which commands are
(and are not) available.

Signed-off-by: Matt Helsley <mhelsley@vmware.com>
---
 tools/objtool/Build                   |  1 +
 tools/objtool/arch/missing/check.c    |  4 +++-
 tools/objtool/arch/missing/orc_dump.c |  4 +++-
 tools/objtool/builtin-check.c         |  5 ++++
 tools/objtool/builtin-orc.c           |  7 ++++++
 tools/objtool/builtin.h               |  2 ++
 tools/objtool/check.h                 |  1 +
 tools/objtool/objtool.c               | 34 +++++++++++++++++++++++----
 tools/objtool/orc.h                   |  1 +
 9 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/tools/objtool/Build b/tools/objtool/Build
index fb6e6faf6f10..8e5ad5c238ba 100644
--- a/tools/objtool/Build
+++ b/tools/objtool/Build
@@ -1,3 +1,4 @@
+objtool-y += arch/missing/
 objtool-y += arch/$(SRCARCH)/
 
 objtool-$(SUBCMD_CHECK) += check.o
diff --git a/tools/objtool/arch/missing/check.c b/tools/objtool/arch/missing/check.c
index 5eac14c8c6a5..7f9deb0451bb 100644
--- a/tools/objtool/arch/missing/check.c
+++ b/tools/objtool/arch/missing/check.c
@@ -8,7 +8,9 @@
 
 const char *objname;
 
-int __attribute__ ((weak)) check(const char *_objname, bool orc)
+int missing_check(const char *_objname, bool orc)
 {
 	return 127;
 }
+
+int __attribute__ ((weak, alias("missing_check"))) check(const char *_objname, bool orc);
diff --git a/tools/objtool/arch/missing/orc_dump.c b/tools/objtool/arch/missing/orc_dump.c
index f7ebb3a2ce9e..45367ddd08a4 100644
--- a/tools/objtool/arch/missing/orc_dump.c
+++ b/tools/objtool/arch/missing/orc_dump.c
@@ -5,7 +5,9 @@
 
 #include "../../orc.h"
 
-int __attribute__ ((weak)) orc_dump(const char *_objname)
+int missing_orc_dump(const char *_objname)
 {
 	return 127;
 }
+
+int __attribute__ ((weak, alias("missing_orc_dump"))) orc_dump(const char *_objname);
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 10fbe75ab43d..7e7ad576ebc0 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -35,6 +35,11 @@ const struct option check_options[] = {
 	OPT_END(),
 };
 
+bool is_cmd_check_available(void)
+{
+	return check != missing_check;
+}
+
 int cmd_check(int argc, const char **argv)
 {
 	const char *objname;
diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c
index e6e54ae4ab75..043b93f68e83 100644
--- a/tools/objtool/builtin-orc.c
+++ b/tools/objtool/builtin-orc.c
@@ -23,6 +23,13 @@ static const char *orc_usage[] = {
 	NULL,
 };
 
+bool is_cmd_orc_available(void)
+{
+	if (check == missing_check)
+		return false;
+	return orc_dump != missing_orc_dump;
+}
+
 int cmd_orc(int argc, const char **argv)
 {
 	const char *objname;
diff --git a/tools/objtool/builtin.h b/tools/objtool/builtin.h
index 0b907902ee79..478558d38007 100644
--- a/tools/objtool/builtin.h
+++ b/tools/objtool/builtin.h
@@ -10,7 +10,9 @@
 extern const struct option check_options[];
 extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats;
 
+extern bool is_cmd_check_available(void);
 extern int cmd_check(int argc, const char **argv);
+extern bool is_cmd_orc_available(void);
 extern int cmd_orc(int argc, const char **argv);
 
 #endif /* _BUILTIN_H */
diff --git a/tools/objtool/check.h b/tools/objtool/check.h
index 4d34bfc84dc7..c54fb9f5c8e6 100644
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -9,6 +9,7 @@
 #include <stdbool.h>
 #include "objtool.h"
 
+int missing_check(const char *objname, bool orc);
 int check(const char *objname, bool orc);
 
 struct instruction *find_insn(struct objtool_file *file,
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index 593ec85915a9..e901c40c76ef 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -27,21 +27,22 @@ struct cmd_struct {
 	const char *name;
 	int (*fn)(int, const char **);
 	const char *help;
+	bool (*is_available)(void);
 };
 
 static const char objtool_usage_string[] =
 	"objtool COMMAND [ARGS]";
 
 static struct cmd_struct objtool_cmds[] = {
-	{"check",	cmd_check,	"Perform stack metadata validation on an object file" },
-	{"orc",		cmd_orc,	"Generate in-place ORC unwind tables for an object file" },
+	{"check",	cmd_check,	"Perform stack metadata validation on an object file", is_cmd_check_available },
+	{"orc",		cmd_orc,	"Generate in-place ORC unwind tables for an object file", is_cmd_orc_available },
 };
 
 bool help;
 
 static void cmd_usage(void)
 {
-	unsigned int i, longest = 0;
+	unsigned int i, longest = 0, num_unavail = 0;
 
 	printf("\n usage: %s\n\n", objtool_usage_string);
 
@@ -52,8 +53,26 @@ static void cmd_usage(void)
 
 	puts(" Commands:");
 	for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
-		printf("   %-*s   ", longest, objtool_cmds[i].name);
-		puts(objtool_cmds[i].help);
+		struct cmd_struct *p = objtool_cmds+i;
+
+		if (!p->is_available()) {
+			num_unavail++;
+			continue;
+		}
+		printf("   %-*s   ", longest, p->name);
+		puts(p->help);
+	}
+
+	if (num_unavail > 0) {
+		puts("\n Unavailable commands on this architecture:");
+		for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
+			struct cmd_struct *p = objtool_cmds+i;
+
+			if (p->is_available())
+				continue;
+			printf("   %-*s   ", longest, p->name);
+			puts(p->help);
+		}
 	}
 
 	printf("\n");
@@ -96,6 +115,11 @@ static void handle_internal_command(int argc, const char **argv)
 		if (strcmp(p->name, cmd))
 			continue;
 
+		if (!p->is_available()) {
+			fprintf(stderr, "command %s is not available on this architecture\n", cmd);
+			exit(127);
+		}
+
 		ret = p->fn(argc, argv);
 
 		exit(ret);
diff --git a/tools/objtool/orc.h b/tools/objtool/orc.h
index c67f451d7610..9174356ba0fa 100644
--- a/tools/objtool/orc.h
+++ b/tools/objtool/orc.h
@@ -11,6 +11,7 @@ struct objtool_file;
 int create_orc(struct objtool_file *file);
 int create_orc_sections(struct objtool_file *file);
 
+int missing_orc_dump(const char *objname);
 int orc_dump(const char *objname);
 
 #endif /* _ORC_H */
-- 
2.20.1


  parent reply	other threads:[~2020-05-11 17:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11 17:35 [RFC][PATCH 0/5] Enable objtool multiarch build Matt Helsley
2020-05-11 17:35 ` [RFC][PATCH 1/5] objtool: Exit successfully when requesting help Matt Helsley
2020-05-15 19:52   ` Josh Poimboeuf
2020-05-18 18:33     ` Matt Helsley
2020-05-11 17:35 ` [RFC][PATCH 2/5] objtool: Move struct objtool_file into arch-independent header Matt Helsley
2020-05-12 17:04   ` Julien Thierry
2020-05-12 18:07     ` Matt Helsley
2020-05-11 17:35 ` [RFC][PATCH 3/5] objtool: Add support for relocations without addends Matt Helsley
2020-05-12 17:04   ` Julien Thierry
2020-05-13 16:26     ` Matt Helsley
2020-05-13 16:55       ` Julien Thierry
2020-05-14 21:09         ` Matt Helsley
2020-05-15 20:33   ` Josh Poimboeuf
2020-05-18 19:14     ` Matt Helsley
2020-05-11 17:35 ` [RFC][PATCH 4/5] objtool: Enable compilation of objtool for all architectures Matt Helsley
2020-05-12 17:04   ` Julien Thierry
2020-05-13 15:59     ` Matt Helsley
2020-05-13 16:55       ` Julien Thierry
2020-05-15 20:51         ` Josh Poimboeuf
2020-05-18 18:26           ` Matt Helsley
2020-05-15 20:56   ` Josh Poimboeuf
2020-05-18 19:20     ` Matt Helsley
2020-05-18 19:50     ` Matt Helsley
2020-05-18 22:27       ` Josh Poimboeuf
2020-05-19 17:48         ` Matt Helsley
2020-05-11 17:35 ` Matt Helsley [this message]
2020-05-12  2:11   ` [RFC][PATCH 5/5] objtool: Report missing support for subcommands kbuild test robot
2020-05-15 21:04   ` Josh Poimboeuf
2020-05-18 18:29     ` Matt Helsley
2020-05-12 17:04 ` [RFC][PATCH 0/5] Enable objtool multiarch build Julien Thierry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38a0c7a1ec8d98238379a322866c0432befc259b.1588888003.git.mhelsley@vmware.com \
    --to=mhelsley@vmware.com \
    --cc=jpoimboe@redhat.com \
    --cc=jthierry@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.