Merge tag 'arm-dt-6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-microblaze.git] / tools / objtool / include / objtool / check.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
4  */
5
6 #ifndef _CHECK_H
7 #define _CHECK_H
8
9 #include <stdbool.h>
10 #include <objtool/cfi.h>
11 #include <objtool/arch.h>
12
13 struct insn_state {
14         struct cfi_state cfi;
15         unsigned int uaccess_stack;
16         bool uaccess;
17         bool df;
18         bool noinstr;
19         s8 instr;
20 };
21
22 struct alt_group {
23         /*
24          * Pointer from a replacement group to the original group.  NULL if it
25          * *is* the original group.
26          */
27         struct alt_group *orig_group;
28
29         /* First and last instructions in the group */
30         struct instruction *first_insn, *last_insn;
31
32         /*
33          * Byte-offset-addressed len-sized array of pointers to CFI structs.
34          * This is shared with the other alt_groups in the same alternative.
35          */
36         struct cfi_state **cfi;
37 };
38
39 struct instruction {
40         struct list_head list;
41         struct hlist_node hash;
42         struct list_head call_node;
43         struct section *sec;
44         unsigned long offset;
45         unsigned int len;
46         enum insn_type type;
47         unsigned long immediate;
48
49         u16 dead_end            : 1,
50            ignore               : 1,
51            ignore_alts          : 1,
52            hint                 : 1,
53            save                 : 1,
54            restore              : 1,
55            retpoline_safe       : 1,
56            noendbr              : 1,
57            entry                : 1;
58                 /* 7 bit hole */
59
60         s8 instr;
61         u8 visited;
62
63         struct alt_group *alt_group;
64         struct symbol *call_dest;
65         struct instruction *jump_dest;
66         struct instruction *first_jump_src;
67         struct reloc *jump_table;
68         struct reloc *reloc;
69         struct list_head alts;
70         struct symbol *func;
71         struct list_head stack_ops;
72         struct cfi_state *cfi;
73 };
74
75 #define VISITED_BRANCH          0x01
76 #define VISITED_BRANCH_UACCESS  0x02
77 #define VISITED_BRANCH_MASK     0x03
78 #define VISITED_ENTRY           0x04
79
80 static inline bool is_static_jump(struct instruction *insn)
81 {
82         return insn->type == INSN_JUMP_CONDITIONAL ||
83                insn->type == INSN_JUMP_UNCONDITIONAL;
84 }
85
86 static inline bool is_dynamic_jump(struct instruction *insn)
87 {
88         return insn->type == INSN_JUMP_DYNAMIC ||
89                insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
90 }
91
92 static inline bool is_jump(struct instruction *insn)
93 {
94         return is_static_jump(insn) || is_dynamic_jump(insn);
95 }
96
97 struct instruction *find_insn(struct objtool_file *file,
98                               struct section *sec, unsigned long offset);
99
100 #define for_each_insn(file, insn)                                       \
101         list_for_each_entry(insn, &file->insn_list, list)
102
103 #define sec_for_each_insn(file, sec, insn)                              \
104         for (insn = find_insn(file, sec, 0);                            \
105              insn && &insn->list != &file->insn_list &&                 \
106                         insn->sec == sec;                               \
107              insn = list_next_entry(insn, list))
108
109 #endif /* _CHECK_H */