xref: /openbmc/linux/tools/objtool/builtin-check.c (revision ca41b97ed9124fd62323a162de5852f6e28f94b8)
1442f04c3SJosh Poimboeuf /*
2dcc914f4SJosh Poimboeuf  * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
3442f04c3SJosh Poimboeuf  *
4442f04c3SJosh Poimboeuf  * This program is free software; you can redistribute it and/or
5442f04c3SJosh Poimboeuf  * modify it under the terms of the GNU General Public License
6442f04c3SJosh Poimboeuf  * as published by the Free Software Foundation; either version 2
7442f04c3SJosh Poimboeuf  * of the License, or (at your option) any later version.
8442f04c3SJosh Poimboeuf  *
9442f04c3SJosh Poimboeuf  * This program is distributed in the hope that it will be useful,
10442f04c3SJosh Poimboeuf  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11442f04c3SJosh Poimboeuf  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12442f04c3SJosh Poimboeuf  * GNU General Public License for more details.
13442f04c3SJosh Poimboeuf  *
14442f04c3SJosh Poimboeuf  * You should have received a copy of the GNU General Public License
15442f04c3SJosh Poimboeuf  * along with this program; if not, see <http://www.gnu.org/licenses/>.
16442f04c3SJosh Poimboeuf  */
17442f04c3SJosh Poimboeuf 
18442f04c3SJosh Poimboeuf /*
19442f04c3SJosh Poimboeuf  * objtool check:
20442f04c3SJosh Poimboeuf  *
21442f04c3SJosh Poimboeuf  * This command analyzes every .o file and ensures the validity of its stack
22442f04c3SJosh Poimboeuf  * trace metadata.  It enforces a set of rules on asm code and C inline
23442f04c3SJosh Poimboeuf  * assembly code so that stack traces can be reliable.
24442f04c3SJosh Poimboeuf  *
25442f04c3SJosh Poimboeuf  * For more information, see tools/objtool/Documentation/stack-validation.txt.
26442f04c3SJosh Poimboeuf  */
27442f04c3SJosh Poimboeuf 
28442f04c3SJosh Poimboeuf #include <subcmd/parse-options.h>
29442f04c3SJosh Poimboeuf #include "builtin.h"
30dcc914f4SJosh Poimboeuf #include "check.h"
31442f04c3SJosh Poimboeuf 
32*ca41b97eSPeter Zijlstra bool no_fp, no_unreachable, retpoline, module;
33442f04c3SJosh Poimboeuf 
34dcc914f4SJosh Poimboeuf static const char * const check_usage[] = {
35442f04c3SJosh Poimboeuf 	"objtool check [<options>] file.o",
36442f04c3SJosh Poimboeuf 	NULL,
37442f04c3SJosh Poimboeuf };
38442f04c3SJosh Poimboeuf 
39dcc914f4SJosh Poimboeuf const struct option check_options[] = {
40867ac9d7SJosh Poimboeuf 	OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
41867ac9d7SJosh Poimboeuf 	OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
42b5bc2231SPeter Zijlstra 	OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
43*ca41b97eSPeter Zijlstra 	OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
44442f04c3SJosh Poimboeuf 	OPT_END(),
45442f04c3SJosh Poimboeuf };
46442f04c3SJosh Poimboeuf 
47dcc914f4SJosh Poimboeuf int cmd_check(int argc, const char **argv)
48dcc914f4SJosh Poimboeuf {
49dcc914f4SJosh Poimboeuf 	const char *objname;
50dcc914f4SJosh Poimboeuf 
51dcc914f4SJosh Poimboeuf 	argc = parse_options(argc, argv, check_options, check_usage, 0);
52442f04c3SJosh Poimboeuf 
53442f04c3SJosh Poimboeuf 	if (argc != 1)
54dcc914f4SJosh Poimboeuf 		usage_with_options(check_usage, check_options);
55442f04c3SJosh Poimboeuf 
56442f04c3SJosh Poimboeuf 	objname = argv[0];
57442f04c3SJosh Poimboeuf 
5843a4525fSPeter Zijlstra 	return check(objname, false);
59442f04c3SJosh Poimboeuf }
60