4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 * The 'check' subcmd analyzes every .o file and ensures the validity of its
22 * stack trace metadata. It enforces a set of rules on asm code and C inline
23 * assembly code so that stack traces can be reliable.
25 * For more information, see tools/objtool/Documentation/stack-validation.txt.
32 #include <subcmd/exec-cmd.h>
33 #include <subcmd/pager.h>
34 #include <linux/kernel.h>
40 int (*fn)(int, const char **);
44 static const char objtool_usage_string[] =
45 "objtool [OPTIONS] COMMAND [ARGS]";
47 static struct cmd_struct objtool_cmds[] = {
48 {"check", cmd_check, "Perform stack metadata validation on an object file" },
53 static void cmd_usage(void)
55 unsigned int i, longest = 0;
57 printf("\n usage: %s\n\n", objtool_usage_string);
59 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
60 if (longest < strlen(objtool_cmds[i].name))
61 longest = strlen(objtool_cmds[i].name);
65 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
66 printf(" %-*s ", longest, objtool_cmds[i].name);
67 puts(objtool_cmds[i].help);
75 static void handle_options(int *argc, const char ***argv)
78 const char *cmd = (*argv)[0];
83 if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) {
87 fprintf(stderr, "Unknown option: %s\n", cmd);
88 fprintf(stderr, "\n Usage: %s\n",
89 objtool_usage_string);
98 static void handle_internal_command(int argc, const char **argv)
100 const char *cmd = argv[0];
103 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
104 struct cmd_struct *p = objtool_cmds+i;
106 if (strcmp(p->name, cmd))
109 ret = p->fn(argc, argv);
117 int main(int argc, const char **argv)
119 static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED";
122 exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
127 handle_options(&argc, &argv);
132 handle_internal_command(argc, argv);