.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2015 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 | /* |
---|
.. | .. |
---|
34 | 22 | #include <linux/kernel.h> |
---|
35 | 23 | |
---|
36 | 24 | #include "builtin.h" |
---|
| 25 | +#include "objtool.h" |
---|
| 26 | +#include "warn.h" |
---|
37 | 27 | |
---|
38 | 28 | struct cmd_struct { |
---|
39 | 29 | const char *name; |
---|
.. | .. |
---|
50 | 40 | }; |
---|
51 | 41 | |
---|
52 | 42 | bool help; |
---|
| 43 | + |
---|
| 44 | +const char *objname; |
---|
| 45 | +static struct objtool_file file; |
---|
| 46 | + |
---|
| 47 | +struct objtool_file *objtool_open_read(const char *_objname) |
---|
| 48 | +{ |
---|
| 49 | + if (objname) { |
---|
| 50 | + if (strcmp(objname, _objname)) { |
---|
| 51 | + WARN("won't handle more than one file at a time"); |
---|
| 52 | + return NULL; |
---|
| 53 | + } |
---|
| 54 | + return &file; |
---|
| 55 | + } |
---|
| 56 | + objname = _objname; |
---|
| 57 | + |
---|
| 58 | + file.elf = elf_open_read(objname, O_RDWR); |
---|
| 59 | + if (!file.elf) |
---|
| 60 | + return NULL; |
---|
| 61 | + |
---|
| 62 | + INIT_LIST_HEAD(&file.insn_list); |
---|
| 63 | + hash_init(file.insn_hash); |
---|
| 64 | + INIT_LIST_HEAD(&file.retpoline_call_list); |
---|
| 65 | + INIT_LIST_HEAD(&file.return_thunk_list); |
---|
| 66 | + INIT_LIST_HEAD(&file.static_call_list); |
---|
| 67 | + INIT_LIST_HEAD(&file.mcount_loc_list); |
---|
| 68 | + file.c_file = !vmlinux && find_section_by_name(file.elf, ".comment"); |
---|
| 69 | + file.ignore_unreachables = no_unreachable; |
---|
| 70 | + file.hints = false; |
---|
| 71 | + |
---|
| 72 | + return &file; |
---|
| 73 | +} |
---|
53 | 74 | |
---|
54 | 75 | static void cmd_usage(void) |
---|
55 | 76 | { |
---|
.. | .. |
---|
70 | 91 | |
---|
71 | 92 | printf("\n"); |
---|
72 | 93 | |
---|
73 | | - exit(129); |
---|
| 94 | + if (!help) |
---|
| 95 | + exit(129); |
---|
| 96 | + exit(0); |
---|
74 | 97 | } |
---|
75 | 98 | |
---|
76 | 99 | static void handle_options(int *argc, const char ***argv) |
---|