objtool: Implement noinstr validation
[linux-2.6-microblaze.git] / tools / 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 "elf.h"
11 #include "cfi.h"
12 #include "arch.h"
13 #include "orc.h"
14 #include <linux/hashtable.h>
15
16 struct insn_state {
17         struct cfi_state cfi;
18         unsigned int uaccess_stack;
19         bool uaccess;
20         bool df;
21         bool noinstr;
22         s8 instr;
23 };
24
25 struct instruction {
26         struct list_head list;
27         struct hlist_node hash;
28         struct section *sec;
29         unsigned long offset;
30         unsigned int len;
31         enum insn_type type;
32         unsigned long immediate;
33         bool alt_group, dead_end, ignore, ignore_alts;
34         bool hint;
35         bool retpoline_safe;
36         s8 instr;
37         u8 visited;
38         u8 ret_offset;
39         struct symbol *call_dest;
40         struct instruction *jump_dest;
41         struct instruction *first_jump_src;
42         struct rela *jump_table;
43         struct list_head alts;
44         struct symbol *func;
45         struct list_head stack_ops;
46         struct cfi_state cfi;
47         struct orc_entry orc;
48 };
49
50 struct objtool_file {
51         struct elf *elf;
52         struct list_head insn_list;
53         DECLARE_HASHTABLE(insn_hash, 20);
54         bool ignore_unreachables, c_file, hints, rodata;
55 };
56
57 int check(const char *objname, bool orc);
58
59 struct instruction *find_insn(struct objtool_file *file,
60                               struct section *sec, unsigned long offset);
61
62 #define for_each_insn(file, insn)                                       \
63         list_for_each_entry(insn, &file->insn_list, list)
64
65 #define sec_for_each_insn(file, sec, insn)                              \
66         for (insn = find_insn(file, sec, 0);                            \
67              insn && &insn->list != &file->insn_list &&                 \
68                         insn->sec == sec;                               \
69              insn = list_next_entry(insn, list))
70
71
72 #endif /* _CHECK_H */