builtin-orc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
  3. *
  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.
  8. *
  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.
  13. *
  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/>.
  16. */
  17. /*
  18. * objtool orc:
  19. *
  20. * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip
  21. * sections to it, which is used by the in-kernel ORC unwinder.
  22. *
  23. * This command is a superset of "objtool check".
  24. */
  25. #include <string.h>
  26. #include "builtin.h"
  27. #include "check.h"
  28. static const char *orc_usage[] = {
  29. "objtool orc generate [<options>] file.o",
  30. "objtool orc dump file.o",
  31. NULL,
  32. };
  33. int cmd_orc(int argc, const char **argv)
  34. {
  35. const char *objname;
  36. argc--; argv++;
  37. if (argc <= 0)
  38. usage_with_options(orc_usage, check_options);
  39. if (!strncmp(argv[0], "gen", 3)) {
  40. argc = parse_options(argc, argv, check_options, orc_usage, 0);
  41. if (argc != 1)
  42. usage_with_options(orc_usage, check_options);
  43. objname = argv[0];
  44. return check(objname, true);
  45. }
  46. if (!strcmp(argv[0], "dump")) {
  47. if (argc != 2)
  48. usage_with_options(orc_usage, check_options);
  49. objname = argv[1];
  50. return orc_dump(objname);
  51. }
  52. usage_with_options(orc_usage, check_options);
  53. return 0;
  54. }