projects/linux·blob master · refs

54 lines · 1.2 KiB

1// SPDX-License-Identifier: GPL-2.0-or-later
2#include <subcmd/parse-options.h>
3#include <string.h>
4#include <stdlib.h>
5#include <objtool/builtin.h>
6#include <objtool/objtool.h>
7#include <objtool/klp.h>
8
9struct subcmd {
10 const char *name;
11 const char *description;
12 int (*fn)(int, const char **);
13};
14
15static struct subcmd subcmds[] = {
16 { "checksum", "Generate per-function checksums", cmd_klp_checksum, },
17 { "diff", "Generate binary diff of two object files", cmd_klp_diff, },
18 { "post-link", "Finalize klp symbols/relocs after module linking", cmd_klp_post_link, },
19};
20
21static void cmd_klp_usage(void)
22{
23 fprintf(stderr, "usage: objtool klp <subcommand> [<options>]\n\n");
24 fprintf(stderr, "Subcommands:\n");
25
26 for (int i = 0; i < ARRAY_SIZE(subcmds); i++) {
27 struct subcmd *cmd = &subcmds[i];
28
29 fprintf(stderr, " %s\t%s\n", cmd->name, cmd->description);
30 }
31
32 exit(1);
33}
34
35int cmd_klp(int argc, const char **argv)
36{
37 argc--;
38 argv++;
39
40 if (!argc)
41 cmd_klp_usage();
42
43 if (argc) {
44 for (int i = 0; i < ARRAY_SIZE(subcmds); i++) {
45 struct subcmd *cmd = &subcmds[i];
46
47 if (!strcmp(cmd->name, argv[0]))
48 return cmd->fn(argc, argv);
49 }
50 }
51
52 cmd_klp_usage();
53 return 0;
54}