objtool: Move ORC logic out of check()

Now that the objtool_file can be obtained outside of the check function,
orc generation builtin no longer requires check to explicitly call its
orc related functions.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
Julien Thierry 2020-08-25 13:47:40 +01:00 committed by Josh Poimboeuf
parent 6545eb030e
commit d44becb9de
5 changed files with 32 additions and 21 deletions

View file

@ -42,6 +42,7 @@ int cmd_check(int argc, const char **argv)
{ {
const char *objname, *s; const char *objname, *s;
struct objtool_file *file; struct objtool_file *file;
int ret;
argc = parse_options(argc, argv, check_options, check_usage, 0); argc = parse_options(argc, argv, check_options, check_usage, 0);
@ -58,5 +59,12 @@ int cmd_check(int argc, const char **argv)
if (!file) if (!file)
return 1; return 1;
return check(file, false); ret = check(file);
if (ret)
return ret;
if (file->elf->changed)
return elf_write(file->elf);
return 0;
} }

View file

@ -32,6 +32,7 @@ int cmd_orc(int argc, const char **argv)
if (!strncmp(argv[0], "gen", 3)) { if (!strncmp(argv[0], "gen", 3)) {
struct objtool_file *file; struct objtool_file *file;
int ret;
argc = parse_options(argc, argv, check_options, orc_usage, 0); argc = parse_options(argc, argv, check_options, orc_usage, 0);
if (argc != 1) if (argc != 1)
@ -43,7 +44,25 @@ int cmd_orc(int argc, const char **argv)
if (!file) if (!file)
return 1; return 1;
return check(file, true); ret = check(file);
if (ret)
return ret;
if (list_empty(&file->insn_list))
return 0;
ret = create_orc(file);
if (ret)
return ret;
ret = create_orc_sections(file);
if (ret)
return ret;
if (!file->elf->changed)
return 0;
return elf_write(file->elf);
} }
if (!strcmp(argv[0], "dump")) { if (!strcmp(argv[0], "dump")) {

View file

@ -2908,7 +2908,7 @@ static int validate_reachable_instructions(struct objtool_file *file)
return 0; return 0;
} }
int check(struct objtool_file *file, bool orc) int check(struct objtool_file *file)
{ {
int ret, warnings = 0; int ret, warnings = 0;
@ -2960,22 +2960,6 @@ int check(struct objtool_file *file, bool orc)
goto out; goto out;
warnings += ret; warnings += ret;
if (orc) {
ret = create_orc(file);
if (ret < 0)
goto out;
ret = create_orc_sections(file);
if (ret < 0)
goto out;
}
if (file->elf->changed) {
ret = elf_write(file->elf);
if (ret < 0)
goto out;
}
out: out:
if (ret < 0) { if (ret < 0) {
/* /*

View file

@ -22,7 +22,7 @@ struct objtool_file {
struct objtool_file *objtool_open_read(const char *_objname); struct objtool_file *objtool_open_read(const char *_objname);
int check(struct objtool_file *file, bool orc); int check(struct objtool_file *file);
int orc_dump(const char *objname); int orc_dump(const char *objname);
int create_orc(struct objtool_file *file); int create_orc(struct objtool_file *file);
int create_orc_sections(struct objtool_file *file); int create_orc_sections(struct objtool_file *file);

View file

@ -17,7 +17,7 @@
return ENOSYS; \ return ENOSYS; \
}) })
int __weak check(struct objtool_file *file, bool orc) int __weak check(struct objtool_file *file)
{ {
UNSUPPORTED("check subcommand"); UNSUPPORTED("check subcommand");
} }