builtin-orc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
  4. */
  5. /*
  6. * objtool orc:
  7. *
  8. * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip
  9. * sections to it, which is used by the in-kernel ORC unwinder.
  10. *
  11. * This command is a superset of "objtool check".
  12. */
  13. #include <string.h>
  14. #include "builtin.h"
  15. #include "objtool.h"
  16. static const char *orc_usage[] = {
  17. "objtool orc generate [<options>] file.o",
  18. "objtool orc dump file.o",
  19. NULL,
  20. };
  21. int cmd_orc(int argc, const char **argv)
  22. {
  23. const char *objname;
  24. argc--; argv++;
  25. if (argc <= 0)
  26. usage_with_options(orc_usage, check_options);
  27. if (!strncmp(argv[0], "gen", 3)) {
  28. struct objtool_file *file;
  29. int ret;
  30. argc = parse_options(argc, argv, check_options, orc_usage, 0);
  31. if (argc != 1)
  32. usage_with_options(orc_usage, check_options);
  33. objname = argv[0];
  34. file = objtool_open_read(objname);
  35. if (!file)
  36. return 1;
  37. ret = check(file);
  38. if (ret)
  39. return ret;
  40. if (list_empty(&file->insn_list))
  41. return 0;
  42. ret = create_orc(file);
  43. if (ret)
  44. return ret;
  45. ret = create_orc_sections(file);
  46. if (ret)
  47. return ret;
  48. if (!file->elf->changed)
  49. return 0;
  50. return elf_write(file->elf);
  51. }
  52. if (!strcmp(argv[0], "dump")) {
  53. if (argc != 2)
  54. usage_with_options(orc_usage, check_options);
  55. objname = argv[1];
  56. return orc_dump(objname);
  57. }
  58. usage_with_options(orc_usage, check_options);
  59. return 0;
  60. }