1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
9 * The 'check' subcmd analyzes every .o file and ensures the validity of its
10 * stack trace metadata. It enforces a set of rules on asm code and C inline
11 * assembly code so that stack traces can be reliable.
13 * For more information, see tools/objtool/Documentation/stack-validation.txt.
20 #include <subcmd/exec-cmd.h>
21 #include <subcmd/pager.h>
22 #include <linux/kernel.h>
28 int (*fn
)(int, const char **);
32 static const char objtool_usage_string
[] =
33 "objtool COMMAND [ARGS]";
35 static struct cmd_struct objtool_cmds
[] = {
36 {"check", cmd_check
, "Perform stack metadata validation on an object file" },
37 {"orc", cmd_orc
, "Generate in-place ORC unwind tables for an object file" },
42 static void cmd_usage(void)
44 unsigned int i
, longest
= 0;
46 printf("\n usage: %s\n\n", objtool_usage_string
);
48 for (i
= 0; i
< ARRAY_SIZE(objtool_cmds
); i
++) {
49 if (longest
< strlen(objtool_cmds
[i
].name
))
50 longest
= strlen(objtool_cmds
[i
].name
);
54 for (i
= 0; i
< ARRAY_SIZE(objtool_cmds
); i
++) {
55 printf(" %-*s ", longest
, objtool_cmds
[i
].name
);
56 puts(objtool_cmds
[i
].help
);
64 static void handle_options(int *argc
, const char ***argv
)
67 const char *cmd
= (*argv
)[0];
72 if (!strcmp(cmd
, "--help") || !strcmp(cmd
, "-h")) {
76 fprintf(stderr
, "Unknown option: %s\n", cmd
);
85 static void handle_internal_command(int argc
, const char **argv
)
87 const char *cmd
= argv
[0];
90 for (i
= 0; i
< ARRAY_SIZE(objtool_cmds
); i
++) {
91 struct cmd_struct
*p
= objtool_cmds
+i
;
93 if (strcmp(p
->name
, cmd
))
96 ret
= p
->fn(argc
, argv
);
104 int main(int argc
, const char **argv
)
106 static const char *UNUSED
= "OBJTOOL_NOT_IMPLEMENTED";
109 exec_cmd_init("objtool", UNUSED
, UNUSED
, UNUSED
);
114 handle_options(&argc
, &argv
);
119 handle_internal_command(argc
, argv
);