From 6642ac91a19496a38043f038d1e32dc8b90cbd7f Mon Sep 17 00:00:00 2001 From: Vanessa Hack <vanessa.hack@fau.de> Date: Tue, 20 Apr 2021 17:16:09 +0200 Subject: [PATCH] objtool: get architecture as first step of check() --- tools/objtool/arch.h | 2 ++ tools/objtool/arch/x86/decode.c | 18 +++++++++++++++--- tools/objtool/check.c | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h index 540331850a86..00c14786d262 100644 --- a/tools/objtool/arch.h +++ b/tools/objtool/arch.h @@ -72,6 +72,8 @@ struct stack_op { struct instruction; +void get_arch(const struct elf *elf); + void arch_initial_func_cfi_state(struct cfi_init_state *state); int arch_decode_instruction(const struct elf *elf, const struct section *sec, diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 3853a413abcf..6599b0f31552 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -32,19 +32,31 @@ int arch_offset; int x8664bit; static int is_x86_64(const struct elf *elf) +{ + switch (elf->ehdr.e_machine) { + case EM_X86_64: + return 1; + case EM_386: + return 0; + default: + WARN("unexpected ELF machine type %d", elf->ehdr.e_machine); + return -1; + } +} + +void get_arch(const struct elf *elf) { switch (elf->ehdr.e_machine) { case EM_X86_64: arch_offset = 8; x8664bit = 1; - return 1; + break; case EM_386: arch_offset = 4; x8664bit = 0; - return 0; + break; default: WARN("unexpected ELF machine type %d", elf->ehdr.e_machine); - return -1; } } diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f7bc480083af..4e1ab4d377c0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2920,6 +2920,8 @@ int check(struct objtool_file *file) { int ret, warnings = 0; + get_arch(file->elf); + arch_initial_func_cfi_state(&initial_func_cfi); ret = decode_sections(file); -- GitLab