.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 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 | #include <string.h> |
---|
28 | 16 | #include "builtin.h" |
---|
29 | | -#include "check.h" |
---|
30 | | - |
---|
| 17 | +#include "objtool.h" |
---|
31 | 18 | |
---|
32 | 19 | static const char *orc_usage[] = { |
---|
33 | 20 | "objtool orc generate [<options>] file.o", |
---|
.. | .. |
---|
44 | 31 | usage_with_options(orc_usage, check_options); |
---|
45 | 32 | |
---|
46 | 33 | if (!strncmp(argv[0], "gen", 3)) { |
---|
| 34 | + struct objtool_file *file; |
---|
| 35 | + int ret; |
---|
| 36 | + |
---|
47 | 37 | argc = parse_options(argc, argv, check_options, orc_usage, 0); |
---|
48 | 38 | if (argc != 1) |
---|
49 | 39 | usage_with_options(orc_usage, check_options); |
---|
50 | 40 | |
---|
51 | 41 | objname = argv[0]; |
---|
52 | 42 | |
---|
53 | | - return check(objname, true); |
---|
| 43 | + file = objtool_open_read(objname); |
---|
| 44 | + if (!file) |
---|
| 45 | + return 1; |
---|
| 46 | + |
---|
| 47 | + ret = check(file); |
---|
| 48 | + if (ret) |
---|
| 49 | + return ret; |
---|
| 50 | + |
---|
| 51 | + if (list_empty(&file->insn_list)) |
---|
| 52 | + return 0; |
---|
| 53 | + |
---|
| 54 | + ret = orc_create(file); |
---|
| 55 | + if (ret) |
---|
| 56 | + return ret; |
---|
| 57 | + |
---|
| 58 | + if (!file->elf->changed) |
---|
| 59 | + return 0; |
---|
| 60 | + |
---|
| 61 | + return elf_write(file->elf); |
---|
54 | 62 | } |
---|
55 | 63 | |
---|
56 | 64 | if (!strcmp(argv[0], "dump")) { |
---|