1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
9 * This command analyzes every .o file and ensures the validity of its stack
10 * trace metadata. It enforces a set of rules on asm code and C inline
11 * assembly code so that stack traces can be reliable.
13 * For more information, see tools/objtool/Documentation/stack-validation.txt.
16 #include <subcmd/parse-options.h>
21 bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
22 validate_dup, vmlinux, sls, unret, rethunk;
24 static const char * const check_usage[] = {
25 "objtool check [<options>] file.o",
29 const struct option check_options[] = {
30 OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
31 OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
32 OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
33 OPT_BOOLEAN(0, "rethunk", &rethunk, "validate and annotate rethunk usage"),
34 OPT_BOOLEAN(0, "unret", &unret, "validate entry unret placement"),
35 OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
36 OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),
37 OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),
38 OPT_BOOLEAN('s', "stats", &stats, "print statistics"),
39 OPT_BOOLEAN('d', "duplicate", &validate_dup, "duplicate validation for vmlinux.o"),
40 OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
41 OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"),
45 int cmd_check(int argc, const char **argv)
47 const char *objname, *s;
48 struct objtool_file *file;
51 argc = parse_options(argc, argv, check_options, check_usage, 0);
54 usage_with_options(check_usage, check_options);
58 s = strstr(objname, "vmlinux.o");
62 file = objtool_open_read(objname);
70 if (file->elf->changed)
71 return elf_write(file->elf);