Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp910667ybb; Fri, 10 Apr 2020 12:39:04 -0700 (PDT) X-Google-Smtp-Source: APiQypK+1XhV73L6Pjjxnkm58baJjJ/RAShqROUMfoyecP89wYOjUJuFM3rqwztjjD/lMr7V2euV X-Received: by 2002:ac8:2921:: with SMTP id y30mr751115qty.161.1586547544143; Fri, 10 Apr 2020 12:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586547544; cv=none; d=google.com; s=arc-20160816; b=O6jA2Byxo0MN8FtsTVs21GdEVhBNPMpCPvupVBSwl92QXDTcQr5IUxcap47TGpjKBG yuNHu+XVx3UP/LP57VN1cTScR42lVRAxLHq/JEPOe0Tbj1sxV9yVlq8cRWtYi9gpqkak eNv59pnAjcq3lL66Pp8cDM4bi23eRoL1ddLG0q3NnmsqsEt6BjXt03J8PvW3baLn+8Xf mmTAajyWvaS7/oBt8Uta48wDlx3JKXg2+Xz5Eph5Q+Q5Na+pGPdk+CnniX3Mb2j4CD9I /xfbMVels/CagqmHQydgE6S34+YN5vmpQvYr8FpHSA/Fm0/balF1MQYhXcWYzp8dMYRx tOIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cOTzk6L52p40NTUplYJdLdV66dG2xIYrcSjN0J4ZStc=; b=azCN2pOFX4FoMUHdpFG59OLM+WCD6+nGrESTTTOP3x+qy8cHTkVCrO+Eatg6cxoQsH 7UEKRklHGy9JLXtYH71/9L/8ObS0fA1y9aMvBYdyYuhH2DdFVK026yReeiPsupWlno3z e7cLgZFpR5UkqOFSK5OxqNr8APbgpt3HrasoNUJvhSv5P1Xx3QGfIEWvfqeLF7Rh6Tzw VWAyNWMuvfVxp9Nc+DMSnhfwoU2yGk6SPhMM8X9mPquokA5zfRtoqYnModsHLh305GVO 0LITZ8WiIvAm7EGBqnNzkzFfyFUPgI5bGyjJJNg3hyd2kC61AqTmYz39IChnqclGXgoD GqRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si1579666qvb.11.2020.04.10.12.38.48; Fri, 10 Apr 2020 12:39:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgDJTgd (ORCPT + 99 others); Fri, 10 Apr 2020 15:36:33 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:55124 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbgDJTgd (ORCPT ); Fri, 10 Apr 2020 15:36:33 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Fri, 10 Apr 2020 12:36:28 -0700 Received: from sc9-mailhost3.vmware.com (unknown [10.166.69.226]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id A7E7940BB1; Fri, 10 Apr 2020 12:36:32 -0700 (PDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Julien Thierry , Ingo Molnar , Steven Rostedt , Miroslav Benes , Matt Helsley Subject: [RFC][PATCH 04/36] objtool: Report missing support for subcommands Date: Fri, 10 Apr 2020 12:35:27 -0700 Message-ID: <0e08a8c9e18e09906888357435b7acba8e0cbe2b.1586468801.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-001.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 3178c00072f5..e372cddd86e0 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -1,3 +1,4 @@ +objtool-y += arch/missing/ objtool-y += arch/$(SRCARCH)/ objtool-y += builtin-check.o objtool-y += builtin-orc.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 #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