objtool: Move object file loading out of check()
Structure objtool_file can be used by different subcommands. In fact it already is, by check and orc. Provide a function that allows to initialize objtool_file, that builtin can call, without relying on check to do the correct setup for them and explicitly hand the objtool_file to them. Reviewed-by: Miroslav Benes <mbenes@suse.cz> Signed-off-by: Julien Thierry <jthierry@redhat.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:

committed by
Josh Poimboeuf

parent
7c9903c9bf
commit
6545eb030e
@@ -28,7 +28,6 @@ struct alternative {
|
||||
bool skip_orig;
|
||||
};
|
||||
|
||||
const char *objname;
|
||||
struct cfi_init_state initial_func_cfi;
|
||||
|
||||
struct instruction *find_insn(struct objtool_file *file,
|
||||
@@ -2909,37 +2908,22 @@ static int validate_reachable_instructions(struct objtool_file *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct objtool_file file;
|
||||
|
||||
int check(const char *_objname, bool orc)
|
||||
int check(struct objtool_file *file, bool orc)
|
||||
{
|
||||
int ret, warnings = 0;
|
||||
|
||||
objname = _objname;
|
||||
|
||||
file.elf = elf_open_read(objname, O_RDWR);
|
||||
if (!file.elf)
|
||||
return 1;
|
||||
|
||||
INIT_LIST_HEAD(&file.insn_list);
|
||||
hash_init(file.insn_hash);
|
||||
INIT_LIST_HEAD(&file.static_call_list);
|
||||
file.c_file = !vmlinux && find_section_by_name(file.elf, ".comment");
|
||||
file.ignore_unreachables = no_unreachable;
|
||||
file.hints = false;
|
||||
|
||||
arch_initial_func_cfi_state(&initial_func_cfi);
|
||||
|
||||
ret = decode_sections(&file);
|
||||
ret = decode_sections(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
warnings += ret;
|
||||
|
||||
if (list_empty(&file.insn_list))
|
||||
if (list_empty(&file->insn_list))
|
||||
goto out;
|
||||
|
||||
if (vmlinux && !validate_dup) {
|
||||
ret = validate_vmlinux_functions(&file);
|
||||
ret = validate_vmlinux_functions(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
@@ -2948,46 +2932,46 @@ int check(const char *_objname, bool orc)
|
||||
}
|
||||
|
||||
if (retpoline) {
|
||||
ret = validate_retpoline(&file);
|
||||
ret = validate_retpoline(file);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
warnings += ret;
|
||||
}
|
||||
|
||||
ret = validate_functions(&file);
|
||||
ret = validate_functions(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
warnings += ret;
|
||||
|
||||
ret = validate_unwind_hints(&file, NULL);
|
||||
ret = validate_unwind_hints(file, NULL);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
warnings += ret;
|
||||
|
||||
if (!warnings) {
|
||||
ret = validate_reachable_instructions(&file);
|
||||
ret = validate_reachable_instructions(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
warnings += ret;
|
||||
}
|
||||
|
||||
ret = create_static_call_sections(&file);
|
||||
ret = create_static_call_sections(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
warnings += ret;
|
||||
|
||||
if (orc) {
|
||||
ret = create_orc(&file);
|
||||
ret = create_orc(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
ret = create_orc_sections(&file);
|
||||
ret = create_orc_sections(file);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (file.elf->changed) {
|
||||
ret = elf_write(file.elf);
|
||||
if (file->elf->changed) {
|
||||
ret = elf_write(file->elf);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user