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