• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
4  */
5 
6 /*
7  * objtool check:
8  *
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.
12  *
13  * For more information, see tools/objtool/Documentation/stack-validation.txt.
14  */
15 
16 #include <subcmd/parse-options.h>
17 #include <string.h>
18 #include "builtin.h"
19 #include "objtool.h"
20 
21 bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
22      validate_dup, vmlinux, sls, unret, rethunk;
23 
24 static const char * const check_usage[] = {
25 	"objtool check [<options>] file.o",
26 	NULL,
27 };
28 
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"),
42 	OPT_END(),
43 };
44 
cmd_check(int argc,const char ** argv)45 int cmd_check(int argc, const char **argv)
46 {
47 	const char *objname, *s;
48 	struct objtool_file *file;
49 	int ret;
50 
51 	argc = parse_options(argc, argv, check_options, check_usage, 0);
52 
53 	if (argc != 1)
54 		usage_with_options(check_usage, check_options);
55 
56 	objname = argv[0];
57 
58 	s = strstr(objname, "vmlinux.o");
59 	if (s && !s[9])
60 		vmlinux = true;
61 
62 	file = objtool_open_read(objname);
63 	if (!file)
64 		return 1;
65 
66 	ret = check(file);
67 	if (ret)
68 		return ret;
69 
70 	if (file->elf->changed)
71 		return elf_write(file->elf);
72 
73 	return 0;
74 }
75