Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / tools / objtool / builtin-orc.c
blob7b31121fa60b270a2ed41ce2436fc704b8431358
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
4 */
6 /*
7 * objtool orc:
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.
12 * This command is a superset of "objtool check".
15 #include <string.h>
16 #include "builtin.h"
17 #include "objtool.h"
19 static const char *orc_usage[] = {
20 "objtool orc generate [<options>] file.o",
21 "objtool orc dump file.o",
22 NULL,
25 int cmd_orc(int argc, const char **argv)
27 const char *objname;
29 argc--; argv++;
30 if (argc <= 0)
31 usage_with_options(orc_usage, check_options);
33 if (!strncmp(argv[0], "gen", 3)) {
34 struct objtool_file *file;
35 int ret;
37 argc = parse_options(argc, argv, check_options, orc_usage, 0);
38 if (argc != 1)
39 usage_with_options(orc_usage, check_options);
41 objname = argv[0];
43 file = objtool_open_read(objname);
44 if (!file)
45 return 1;
47 ret = check(file);
48 if (ret)
49 return ret;
51 if (list_empty(&file->insn_list))
52 return 0;
54 ret = create_orc(file);
55 if (ret)
56 return ret;
58 ret = create_orc_sections(file);
59 if (ret)
60 return ret;
62 if (!file->elf->changed)
63 return 0;
65 return elf_write(file->elf);
68 if (!strcmp(argv[0], "dump")) {
69 if (argc != 2)
70 usage_with_options(orc_usage, check_options);
72 objname = argv[1];
74 return orc_dump(objname);
77 usage_with_options(orc_usage, check_options);
79 return 0;