objtool: Support repeated uses of the same C jump table
[platform/kernel/linux-starfive.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_reg cfa;
18         struct cfi_reg regs[CFI_NUM_REGS];
19         int stack_size;
20         unsigned char type;
21         bool bp_scratch;
22         bool drap, end, uaccess, df;
23         unsigned int uaccess_stack;
24         int drap_reg, drap_offset;
25         struct cfi_reg vals[CFI_NUM_REGS];
26 };
27
28 struct instruction {
29         struct list_head list;
30         struct hlist_node hash;
31         struct section *sec;
32         unsigned long offset;
33         unsigned int len;
34         unsigned char type;
35         unsigned long immediate;
36         bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
37         bool retpoline_safe;
38         struct symbol *call_dest;
39         struct instruction *jump_dest;
40         struct instruction *first_jump_src;
41         struct rela *jump_table;
42         struct list_head alts;
43         struct symbol *func;
44         struct stack_op stack_op;
45         struct insn_state state;
46         struct orc_entry orc;
47 };
48
49 struct objtool_file {
50         struct elf *elf;
51         struct list_head insn_list;
52         DECLARE_HASHTABLE(insn_hash, 16);
53         bool ignore_unreachables, c_file, hints, rodata;
54 };
55
56 int check(const char *objname, bool orc);
57
58 struct instruction *find_insn(struct objtool_file *file,
59                               struct section *sec, unsigned long offset);
60
61 #define for_each_insn(file, insn)                                       \
62         list_for_each_entry(insn, &file->insn_list, list)
63
64 #define sec_for_each_insn(file, sec, insn)                              \
65         for (insn = find_insn(file, sec, 0);                            \
66              insn && &insn->list != &file->insn_list &&                 \
67                         insn->sec == sec;                               \
68              insn = list_next_entry(insn, list))
69
70
71 #endif /* _CHECK_H */