builtin-check.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
  4. */
  5. /*
  6. * objtool check:
  7. *
  8. * This command analyzes every .o file and ensures the validity of its stack
  9. * trace metadata. It enforces a set of rules on asm code and C inline
  10. * assembly code so that stack traces can be reliable.
  11. *
  12. * For more information, see tools/objtool/Documentation/stack-validation.txt.
  13. */
  14. #include <subcmd/parse-options.h>
  15. #include <string.h>
  16. #include "builtin.h"
  17. #include "objtool.h"
  18. bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux, mcount, noinstr;
  19. static const char * const check_usage[] = {
  20. "objtool check [<options>] file.o",
  21. NULL,
  22. };
  23. const struct option check_options[] = {
  24. OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
  25. OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
  26. OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
  27. OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
  28. OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),
  29. OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),
  30. OPT_BOOLEAN('s', "stats", &stats, "print statistics"),
  31. OPT_BOOLEAN('d', "duplicate", &validate_dup, "duplicate validation for vmlinux.o"),
  32. OPT_BOOLEAN('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"),
  33. OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
  34. OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"),
  35. OPT_END(),
  36. };
  37. int cmd_check(int argc, const char **argv)
  38. {
  39. const char *objname;
  40. struct objtool_file *file;
  41. int ret;
  42. argc = parse_options(argc, argv, check_options, check_usage, 0);
  43. if (argc != 1)
  44. usage_with_options(check_usage, check_options);
  45. objname = argv[0];
  46. file = objtool_open_read(objname);
  47. if (!file)
  48. return 1;
  49. ret = check(file);
  50. if (ret)
  51. return ret;
  52. if (file->elf->changed)
  53. return elf_write(file->elf);
  54. return 0;
  55. }