Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 1 | /* |
| 2 | * 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 | */ |
| 17 | |
| 18 | /* |
| 19 | * objtool orc: |
| 20 | * |
| 21 | * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip |
| 22 | * sections to it, which is used by the in-kernel ORC unwinder. |
| 23 | * |
| 24 | * This command is a superset of "objtool check". |
| 25 | */ |
| 26 | |
| 27 | #include <string.h> |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 28 | #include "builtin.h" |
| 29 | #include "check.h" |
| 30 | |
| 31 | |
| 32 | static const char *orc_usage[] = { |
| 33 | "objtool orc generate [<options>] file.o", |
| 34 | "objtool orc dump file.o", |
| 35 | NULL, |
| 36 | }; |
| 37 | |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 38 | int cmd_orc(int argc, const char **argv) |
| 39 | { |
| 40 | const char *objname; |
| 41 | |
| 42 | argc--; argv++; |
Simon Ser | d89e426 | 2017-12-30 14:43:31 -0600 | [diff] [blame] | 43 | if (argc <= 0) |
| 44 | usage_with_options(orc_usage, check_options); |
| 45 | |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 46 | if (!strncmp(argv[0], "gen", 3)) { |
| 47 | argc = parse_options(argc, argv, check_options, orc_usage, 0); |
| 48 | if (argc != 1) |
| 49 | usage_with_options(orc_usage, check_options); |
| 50 | |
| 51 | objname = argv[0]; |
| 52 | |
Peter Zijlstra | 43a4525 | 2018-01-16 17:16:32 +0100 | [diff] [blame] | 53 | return check(objname, true); |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | if (!strcmp(argv[0], "dump")) { |
| 57 | if (argc != 2) |
| 58 | usage_with_options(orc_usage, check_options); |
| 59 | |
| 60 | objname = argv[1]; |
| 61 | |
| 62 | return orc_dump(objname); |
| 63 | } |
| 64 | |
| 65 | usage_with_options(orc_usage, check_options); |
| 66 | |
| 67 | return 0; |
| 68 | } |