blob: 3979f275a77570baf4459c11782ee7c0e2a454ab [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Josh Poimboeuf627fce12017-07-11 10:33:42 -05002/*
3 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
Josh Poimboeuf627fce12017-07-11 10:33:42 -05004 */
5
6/*
7 * objtool orc:
8 *
9 * This command analyzes a .o file and adds .orc_unwind and .orc_unwind_ip
10 * sections to it, which is used by the in-kernel ORC unwinder.
11 *
12 * This command is a superset of "objtool check".
13 */
14
15#include <string.h>
Josh Poimboeuf627fce12017-07-11 10:33:42 -050016#include "builtin.h"
Matt Helsley0decf1f2020-05-19 13:55:33 -070017#include "objtool.h"
Josh Poimboeuf627fce12017-07-11 10:33:42 -050018
19static const char *orc_usage[] = {
20 "objtool orc generate [<options>] file.o",
21 "objtool orc dump file.o",
22 NULL,
23};
24
Josh Poimboeuf627fce12017-07-11 10:33:42 -050025int cmd_orc(int argc, const char **argv)
26{
27 const char *objname;
28
29 argc--; argv++;
Simon Serd89e4262017-12-30 14:43:31 -060030 if (argc <= 0)
31 usage_with_options(orc_usage, check_options);
32
Josh Poimboeuf627fce12017-07-11 10:33:42 -050033 if (!strncmp(argv[0], "gen", 3)) {
Julien Thierry6545eb02020-08-25 13:47:39 +010034 struct objtool_file *file;
35
Josh Poimboeuf627fce12017-07-11 10:33:42 -050036 argc = parse_options(argc, argv, check_options, orc_usage, 0);
37 if (argc != 1)
38 usage_with_options(orc_usage, check_options);
39
40 objname = argv[0];
41
Julien Thierry6545eb02020-08-25 13:47:39 +010042 file = objtool_open_read(objname);
43 if (!file)
44 return 1;
45
46 return check(file, true);
Josh Poimboeuf627fce12017-07-11 10:33:42 -050047 }
48
49 if (!strcmp(argv[0], "dump")) {
50 if (argc != 2)
51 usage_with_options(orc_usage, check_options);
52
53 objname = argv[1];
54
55 return orc_dump(objname);
56 }
57
58 usage_with_options(orc_usage, check_options);
59
60 return 0;
61}