Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 2 | /* |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 3 | * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com> |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 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 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 16 | #include <subcmd/parse-options.h> |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 17 | #include "builtin.h" |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 18 | #include "check.h" |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 19 | |
Peter Zijlstra | ea24213 | 2019-02-25 12:50:09 +0100 | [diff] [blame] | 20 | bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess; |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 21 | |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 22 | static const char * const check_usage[] = { |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 23 | "objtool check [<options>] file.o", |
| 24 | NULL, |
| 25 | }; |
| 26 | |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 27 | const struct option check_options[] = { |
Josh Poimboeuf | 867ac9d | 2017-07-24 18:34:14 -0500 | [diff] [blame] | 28 | OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"), |
| 29 | OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"), |
Peter Zijlstra | b5bc223 | 2018-01-16 10:24:06 +0100 | [diff] [blame] | 30 | OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"), |
Peter Zijlstra | ca41b97 | 2018-01-31 10:18:28 +0100 | [diff] [blame] | 31 | OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"), |
Peter Zijlstra | 7697eee | 2019-03-01 11:15:49 +0100 | [diff] [blame] | 32 | OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"), |
Peter Zijlstra | ea24213 | 2019-02-25 12:50:09 +0100 | [diff] [blame] | 33 | OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"), |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 34 | OPT_END(), |
| 35 | }; |
| 36 | |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 37 | int cmd_check(int argc, const char **argv) |
| 38 | { |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 39 | const char *objname; |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 40 | |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 41 | argc = parse_options(argc, argv, check_options, check_usage, 0); |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 42 | |
| 43 | if (argc != 1) |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 44 | usage_with_options(check_usage, check_options); |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 45 | |
| 46 | objname = argv[0]; |
| 47 | |
Peter Zijlstra | 43a4525 | 2018-01-16 17:16:32 +0100 | [diff] [blame] | 48 | return check(objname, false); |
Josh Poimboeuf | 442f04c | 2016-02-28 22:22:41 -0600 | [diff] [blame] | 49 | } |