| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License |
|---|
| 6 | | - * as published by the Free Software Foundation; either version 2 |
|---|
| 7 | | - * of the License, or (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License |
|---|
| 15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 4 | */ |
|---|
| 17 | 5 | |
|---|
| 18 | 6 | /* |
|---|
| .. | .. |
|---|
| 26 | 14 | */ |
|---|
| 27 | 15 | |
|---|
| 28 | 16 | #include <subcmd/parse-options.h> |
|---|
| 17 | +#include <string.h> |
|---|
| 29 | 18 | #include "builtin.h" |
|---|
| 30 | | -#include "check.h" |
|---|
| 19 | +#include "objtool.h" |
|---|
| 31 | 20 | |
|---|
| 32 | | -bool no_fp, no_unreachable, retpoline, module; |
|---|
| 21 | +bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, |
|---|
| 22 | + validate_dup, vmlinux, mcount, noinstr, sls, unret, rethunk; |
|---|
| 33 | 23 | |
|---|
| 34 | 24 | static const char * const check_usage[] = { |
|---|
| 35 | 25 | "objtool check [<options>] file.o", |
|---|
| .. | .. |
|---|
| 40 | 30 | OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"), |
|---|
| 41 | 31 | OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"), |
|---|
| 42 | 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"), |
|---|
| 43 | 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('n', "noinstr", &noinstr, "noinstr validation for vmlinux.o"), |
|---|
| 41 | + OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"), |
|---|
| 42 | + OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"), |
|---|
| 43 | + OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"), |
|---|
| 44 | 44 | OPT_END(), |
|---|
| 45 | 45 | }; |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | int cmd_check(int argc, const char **argv) |
|---|
| 48 | 48 | { |
|---|
| 49 | 49 | const char *objname; |
|---|
| 50 | + struct objtool_file *file; |
|---|
| 51 | + int ret; |
|---|
| 50 | 52 | |
|---|
| 51 | 53 | argc = parse_options(argc, argv, check_options, check_usage, 0); |
|---|
| 52 | 54 | |
|---|
| .. | .. |
|---|
| 55 | 57 | |
|---|
| 56 | 58 | objname = argv[0]; |
|---|
| 57 | 59 | |
|---|
| 58 | | - return check(objname, false); |
|---|
| 60 | + file = objtool_open_read(objname); |
|---|
| 61 | + if (!file) |
|---|
| 62 | + return 1; |
|---|
| 63 | + |
|---|
| 64 | + ret = check(file); |
|---|
| 65 | + if (ret) |
|---|
| 66 | + return ret; |
|---|
| 67 | + |
|---|
| 68 | + if (file->elf->changed) |
|---|
| 69 | + return elf_write(file->elf); |
|---|
| 70 | + |
|---|
| 71 | + return 0; |
|---|
| 59 | 72 | } |
|---|