builtin-klp.c 1.1 KB

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