diff options
author | Josh Poimboeuf <jpoimboe@redhat.com> | 2019-07-17 21:36:56 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2019-07-18 15:01:10 -0400 |
commit | 9fe7b7642fe2c5158904d06fe31b740ca0695a01 (patch) | |
tree | 6488c994de6e16016bc5ded0beaf5ace832d0837 | |
parent | e65050b94d8c518fdbee572ea4ca6d352e1fda37 (diff) |
objtool: Convert insn type to enum
This makes it easier to add new instruction types. Also it's hopefully
more robust since the compiler should warn about out-of-range enums.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/0740e96af0d40e54cfd6a07bf09db0fbd10793cd.1563413318.git.jpoimboe@redhat.com
-rw-r--r-- | tools/objtool/arch.h | 35 | ||||
-rw-r--r-- | tools/objtool/arch/x86/decode.c | 2 | ||||
-rw-r--r-- | tools/objtool/check.c | 7 | ||||
-rw-r--r-- | tools/objtool/check.h | 2 |
4 files changed, 20 insertions, 26 deletions
diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h index 580e344db3dd..50448c0c4bca 100644 --- a/tools/objtool/arch.h +++ b/tools/objtool/arch.h | |||
@@ -11,22 +11,23 @@ | |||
11 | #include "elf.h" | 11 | #include "elf.h" |
12 | #include "cfi.h" | 12 | #include "cfi.h" |
13 | 13 | ||
14 | #define INSN_JUMP_CONDITIONAL 1 | 14 | enum insn_type { |
15 | #define INSN_JUMP_UNCONDITIONAL 2 | 15 | INSN_JUMP_CONDITIONAL, |
16 | #define INSN_JUMP_DYNAMIC 3 | 16 | INSN_JUMP_UNCONDITIONAL, |
17 | #define INSN_CALL 4 | 17 | INSN_JUMP_DYNAMIC, |
18 | #define INSN_CALL_DYNAMIC 5 | 18 | INSN_CALL, |
19 | #define INSN_RETURN 6 | 19 | INSN_CALL_DYNAMIC, |
20 | #define INSN_CONTEXT_SWITCH 7 | 20 | INSN_RETURN, |
21 | #define INSN_STACK 8 | 21 | INSN_CONTEXT_SWITCH, |
22 | #define INSN_BUG 9 | 22 | INSN_STACK, |
23 | #define INSN_NOP 10 | 23 | INSN_BUG, |
24 | #define INSN_STAC 11 | 24 | INSN_NOP, |
25 | #define INSN_CLAC 12 | 25 | INSN_STAC, |
26 | #define INSN_STD 13 | 26 | INSN_CLAC, |
27 | #define INSN_CLD 14 | 27 | INSN_STD, |
28 | #define INSN_OTHER 15 | 28 | INSN_CLD, |
29 | #define INSN_LAST INSN_OTHER | 29 | INSN_OTHER, |
30 | }; | ||
30 | 31 | ||
31 | enum op_dest_type { | 32 | enum op_dest_type { |
32 | OP_DEST_REG, | 33 | OP_DEST_REG, |
@@ -68,7 +69,7 @@ void arch_initial_func_cfi_state(struct cfi_state *state); | |||
68 | 69 | ||
69 | int arch_decode_instruction(struct elf *elf, struct section *sec, | 70 | int arch_decode_instruction(struct elf *elf, struct section *sec, |
70 | unsigned long offset, unsigned int maxlen, | 71 | unsigned long offset, unsigned int maxlen, |
71 | unsigned int *len, unsigned char *type, | 72 | unsigned int *len, enum insn_type *type, |
72 | unsigned long *immediate, struct stack_op *op); | 73 | unsigned long *immediate, struct stack_op *op); |
73 | 74 | ||
74 | bool arch_callee_saved_reg(unsigned char reg); | 75 | bool arch_callee_saved_reg(unsigned char reg); |
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 584568f27a83..0567c47a91b1 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c | |||
@@ -68,7 +68,7 @@ bool arch_callee_saved_reg(unsigned char reg) | |||
68 | 68 | ||
69 | int arch_decode_instruction(struct elf *elf, struct section *sec, | 69 | int arch_decode_instruction(struct elf *elf, struct section *sec, |
70 | unsigned long offset, unsigned int maxlen, | 70 | unsigned long offset, unsigned int maxlen, |
71 | unsigned int *len, unsigned char *type, | 71 | unsigned int *len, enum insn_type *type, |
72 | unsigned long *immediate, struct stack_op *op) | 72 | unsigned long *immediate, struct stack_op *op) |
73 | { | 73 | { |
74 | struct insn insn; | 74 | struct insn insn; |
diff --git a/tools/objtool/check.c b/tools/objtool/check.c index a966b22a32ef..04572a049cfc 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c | |||
@@ -267,13 +267,6 @@ static int decode_instructions(struct objtool_file *file) | |||
267 | if (ret) | 267 | if (ret) |
268 | goto err; | 268 | goto err; |
269 | 269 | ||
270 | if (!insn->type || insn->type > INSN_LAST) { | ||
271 | WARN_FUNC("invalid instruction type %d", | ||
272 | insn->sec, insn->offset, insn->type); | ||
273 | ret = -1; | ||
274 | goto err; | ||
275 | } | ||
276 | |||
277 | hash_add(file->insn_hash, &insn->hash, insn->offset); | 270 | hash_add(file->insn_hash, &insn->hash, insn->offset); |
278 | list_add_tail(&insn->list, &file->insn_list); | 271 | list_add_tail(&insn->list, &file->insn_list); |
279 | } | 272 | } |
diff --git a/tools/objtool/check.h b/tools/objtool/check.h index afa6a79e0715..b881fafcf55d 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h | |||
@@ -31,7 +31,7 @@ struct instruction { | |||
31 | struct section *sec; | 31 | struct section *sec; |
32 | unsigned long offset; | 32 | unsigned long offset; |
33 | unsigned int len; | 33 | unsigned int len; |
34 | unsigned char type; | 34 | enum insn_type type; |
35 | unsigned long immediate; | 35 | unsigned long immediate; |
36 | bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; | 36 | bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; |
37 | bool retpoline_safe; | 37 | bool retpoline_safe; |