Skip to content

Commit 9fe7b76

Browse files
jpoimboeKAGA-KOKO
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Nick Desaulniers <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/0740e96af0d40e54cfd6a07bf09db0fbd10793cd.1563413318.git.jpoimboe@redhat.com
1 parent e65050b commit 9fe7b76

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

tools/objtool/arch.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
#include "elf.h"
1212
#include "cfi.h"
1313

14-
#define INSN_JUMP_CONDITIONAL 1
15-
#define INSN_JUMP_UNCONDITIONAL 2
16-
#define INSN_JUMP_DYNAMIC 3
17-
#define INSN_CALL 4
18-
#define INSN_CALL_DYNAMIC 5
19-
#define INSN_RETURN 6
20-
#define INSN_CONTEXT_SWITCH 7
21-
#define INSN_STACK 8
22-
#define INSN_BUG 9
23-
#define INSN_NOP 10
24-
#define INSN_STAC 11
25-
#define INSN_CLAC 12
26-
#define INSN_STD 13
27-
#define INSN_CLD 14
28-
#define INSN_OTHER 15
29-
#define INSN_LAST INSN_OTHER
14+
enum insn_type {
15+
INSN_JUMP_CONDITIONAL,
16+
INSN_JUMP_UNCONDITIONAL,
17+
INSN_JUMP_DYNAMIC,
18+
INSN_CALL,
19+
INSN_CALL_DYNAMIC,
20+
INSN_RETURN,
21+
INSN_CONTEXT_SWITCH,
22+
INSN_STACK,
23+
INSN_BUG,
24+
INSN_NOP,
25+
INSN_STAC,
26+
INSN_CLAC,
27+
INSN_STD,
28+
INSN_CLD,
29+
INSN_OTHER,
30+
};
3031

3132
enum op_dest_type {
3233
OP_DEST_REG,
@@ -68,7 +69,7 @@ void arch_initial_func_cfi_state(struct cfi_state *state);
6869

6970
int arch_decode_instruction(struct elf *elf, struct section *sec,
7071
unsigned long offset, unsigned int maxlen,
71-
unsigned int *len, unsigned char *type,
72+
unsigned int *len, enum insn_type *type,
7273
unsigned long *immediate, struct stack_op *op);
7374

7475
bool arch_callee_saved_reg(unsigned char reg);

tools/objtool/arch/x86/decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool arch_callee_saved_reg(unsigned char reg)
6868

6969
int arch_decode_instruction(struct elf *elf, struct section *sec,
7070
unsigned long offset, unsigned int maxlen,
71-
unsigned int *len, unsigned char *type,
71+
unsigned int *len, enum insn_type *type,
7272
unsigned long *immediate, struct stack_op *op)
7373
{
7474
struct insn insn;

tools/objtool/check.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,6 @@ static int decode_instructions(struct objtool_file *file)
267267
if (ret)
268268
goto err;
269269

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-
277270
hash_add(file->insn_hash, &insn->hash, insn->offset);
278271
list_add_tail(&insn->list, &file->insn_list);
279272
}

tools/objtool/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct instruction {
3131
struct section *sec;
3232
unsigned long offset;
3333
unsigned int len;
34-
unsigned char type;
34+
enum insn_type type;
3535
unsigned long immediate;
3636
bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
3737
bool retpoline_safe;

0 commit comments

Comments
 (0)