.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com> |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or |
---|
5 | | - * modify it under the terms of the GNU General Public License |
---|
6 | | - * as published by the Free Software Foundation; either version 2 |
---|
7 | | - * of the License, or (at your option) any later version. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
---|
16 | 4 | */ |
---|
17 | 5 | |
---|
18 | 6 | #ifndef _CHECK_H |
---|
19 | 7 | #define _CHECK_H |
---|
20 | 8 | |
---|
21 | 9 | #include <stdbool.h> |
---|
22 | | -#include "elf.h" |
---|
23 | 10 | #include "cfi.h" |
---|
24 | 11 | #include "arch.h" |
---|
25 | | -#include "orc.h" |
---|
26 | | -#include <linux/hashtable.h> |
---|
27 | 12 | |
---|
28 | 13 | struct insn_state { |
---|
29 | | - struct cfi_reg cfa; |
---|
30 | | - struct cfi_reg regs[CFI_NUM_REGS]; |
---|
31 | | - int stack_size; |
---|
32 | | - unsigned char type; |
---|
33 | | - bool bp_scratch; |
---|
34 | | - bool drap, end; |
---|
35 | | - int drap_reg, drap_offset; |
---|
36 | | - struct cfi_reg vals[CFI_NUM_REGS]; |
---|
| 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 | 37 | }; |
---|
38 | 38 | |
---|
39 | 39 | struct instruction { |
---|
40 | 40 | struct list_head list; |
---|
41 | 41 | struct hlist_node hash; |
---|
| 42 | + struct list_head mcount_loc_node; |
---|
| 43 | + struct list_head call_node; |
---|
42 | 44 | struct section *sec; |
---|
43 | 45 | unsigned long offset; |
---|
44 | 46 | unsigned int len; |
---|
45 | | - unsigned char type; |
---|
| 47 | + enum insn_type type; |
---|
46 | 48 | unsigned long immediate; |
---|
47 | | - bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; |
---|
| 49 | + bool dead_end, ignore, ignore_alts; |
---|
| 50 | + bool hint; |
---|
| 51 | + bool save, restore; |
---|
48 | 52 | bool retpoline_safe; |
---|
| 53 | + bool entry; |
---|
| 54 | + s8 instr; |
---|
| 55 | + u8 visited; |
---|
| 56 | + struct alt_group *alt_group; |
---|
49 | 57 | struct symbol *call_dest; |
---|
50 | 58 | struct instruction *jump_dest; |
---|
51 | 59 | struct instruction *first_jump_src; |
---|
| 60 | + struct reloc *jump_table; |
---|
| 61 | + struct reloc *reloc; |
---|
52 | 62 | struct list_head alts; |
---|
53 | 63 | struct symbol *func; |
---|
54 | | - struct stack_op stack_op; |
---|
55 | | - struct insn_state state; |
---|
56 | | - struct orc_entry orc; |
---|
| 64 | + struct list_head stack_ops; |
---|
| 65 | + struct cfi_state *cfi; |
---|
57 | 66 | }; |
---|
58 | 67 | |
---|
59 | | -struct objtool_file { |
---|
60 | | - struct elf *elf; |
---|
61 | | - struct list_head insn_list; |
---|
62 | | - DECLARE_HASHTABLE(insn_hash, 16); |
---|
63 | | - struct section *whitelist; |
---|
64 | | - bool ignore_unreachables, c_file, hints, rodata; |
---|
65 | | -}; |
---|
| 68 | +#define VISITED_BRANCH 0x01 |
---|
| 69 | +#define VISITED_BRANCH_UACCESS 0x02 |
---|
| 70 | +#define VISITED_BRANCH_MASK 0x03 |
---|
| 71 | +#define VISITED_ENTRY 0x04 |
---|
66 | 72 | |
---|
67 | | -int check(const char *objname, bool orc); |
---|
| 73 | +static inline bool is_static_jump(struct instruction *insn) |
---|
| 74 | +{ |
---|
| 75 | + return insn->type == INSN_JUMP_CONDITIONAL || |
---|
| 76 | + insn->type == INSN_JUMP_UNCONDITIONAL; |
---|
| 77 | +} |
---|
| 78 | + |
---|
| 79 | +static inline bool is_dynamic_jump(struct instruction *insn) |
---|
| 80 | +{ |
---|
| 81 | + return insn->type == INSN_JUMP_DYNAMIC || |
---|
| 82 | + insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL; |
---|
| 83 | +} |
---|
| 84 | + |
---|
| 85 | +static inline bool is_jump(struct instruction *insn) |
---|
| 86 | +{ |
---|
| 87 | + return is_static_jump(insn) || is_dynamic_jump(insn); |
---|
| 88 | +} |
---|
68 | 89 | |
---|
69 | 90 | struct instruction *find_insn(struct objtool_file *file, |
---|
70 | 91 | struct section *sec, unsigned long offset); |
---|
.. | .. |
---|
77 | 98 | insn && &insn->list != &file->insn_list && \ |
---|
78 | 99 | insn->sec == sec; \ |
---|
79 | 100 | insn = list_next_entry(insn, list)) |
---|
80 | | - |
---|
81 | 101 | |
---|
82 | 102 | #endif /* _CHECK_H */ |
---|