Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com> |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _CHECK_H |
| 7 | #define _CHECK_H |
| 8 | |
| 9 | #include <stdbool.h> |
Josh Poimboeuf | baa4146 | 2017-06-28 10:11:07 -0500 | [diff] [blame] | 10 | #include "cfi.h" |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 11 | #include "arch.h" |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 12 | |
Josh Poimboeuf | baa4146 | 2017-06-28 10:11:07 -0500 | [diff] [blame] | 13 | struct insn_state { |
Peter Zijlstra | e7c0219 | 2020-03-25 14:04:45 +0100 | [diff] [blame] | 14 | struct cfi_state cfi; |
Peter Zijlstra | ea24213 | 2019-02-25 12:50:09 +0100 | [diff] [blame] | 15 | unsigned int uaccess_stack; |
Peter Zijlstra | e7c0219 | 2020-03-25 14:04:45 +0100 | [diff] [blame] | 16 | bool uaccess; |
| 17 | bool df; |
Peter Zijlstra | c4a3393 | 2020-03-10 18:57:41 +0100 | [diff] [blame] | 18 | bool noinstr; |
| 19 | s8 instr; |
Josh Poimboeuf | baa4146 | 2017-06-28 10:11:07 -0500 | [diff] [blame] | 20 | }; |
| 21 | |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 22 | struct instruction { |
| 23 | struct list_head list; |
| 24 | struct hlist_node hash; |
Josh Poimboeuf | 1e7e478 | 2020-08-18 15:57:45 +0200 | [diff] [blame] | 25 | struct list_head static_call_node; |
Peter Zijlstra | 7dcfcd4 | 2020-08-06 15:14:09 -0700 | [diff] [blame] | 26 | struct list_head mcount_loc_node; |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 27 | struct section *sec; |
| 28 | unsigned long offset; |
Josh Poimboeuf | baa4146 | 2017-06-28 10:11:07 -0500 | [diff] [blame] | 29 | unsigned int len; |
Josh Poimboeuf | 9fe7b76 | 2019-07-17 20:36:56 -0500 | [diff] [blame] | 30 | enum insn_type type; |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 31 | unsigned long immediate; |
Alexandre Chartre | 13fab06 | 2020-04-14 12:36:11 +0200 | [diff] [blame] | 32 | bool dead_end, ignore, ignore_alts; |
Peter Zijlstra | c536ed2 | 2020-04-01 16:54:26 +0200 | [diff] [blame] | 33 | bool hint; |
Peter Zijlstra | b5bc223 | 2018-01-16 10:24:06 +0100 | [diff] [blame] | 34 | bool retpoline_safe; |
Peter Zijlstra | c4a3393 | 2020-03-10 18:57:41 +0100 | [diff] [blame] | 35 | s8 instr; |
Peter Zijlstra | 882a0db | 2019-07-24 17:47:26 -0500 | [diff] [blame] | 36 | u8 visited; |
Peter Zijlstra | e25eea8 | 2020-04-01 16:38:19 +0200 | [diff] [blame] | 37 | u8 ret_offset; |
Alexandre Chartre | 13fab06 | 2020-04-14 12:36:11 +0200 | [diff] [blame] | 38 | int alt_group; |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 39 | struct symbol *call_dest; |
| 40 | struct instruction *jump_dest; |
Peter Zijlstra | 99ce796 | 2018-02-08 14:02:32 +0100 | [diff] [blame] | 41 | struct instruction *first_jump_src; |
Matt Helsley | f197422 | 2020-05-29 14:01:13 -0700 | [diff] [blame] | 42 | struct reloc *jump_table; |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 43 | struct list_head alts; |
| 44 | struct symbol *func; |
Julien Thierry | 65ea47d | 2020-03-27 15:28:47 +0000 | [diff] [blame] | 45 | struct list_head stack_ops; |
Peter Zijlstra | e7c0219 | 2020-03-25 14:04:45 +0100 | [diff] [blame] | 46 | struct cfi_state cfi; |
Julien Thierry | 66734e3 | 2020-08-25 13:47:42 +0100 | [diff] [blame] | 47 | #ifdef INSN_USE_ORC |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 48 | struct orc_entry orc; |
Julien Thierry | 66734e3 | 2020-08-25 13:47:42 +0100 | [diff] [blame] | 49 | #endif |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
Julien Thierry | 45245f5 | 2020-09-04 16:30:23 +0100 | [diff] [blame] | 52 | static inline bool is_static_jump(struct instruction *insn) |
| 53 | { |
| 54 | return insn->type == INSN_JUMP_CONDITIONAL || |
| 55 | insn->type == INSN_JUMP_UNCONDITIONAL; |
| 56 | } |
| 57 | |
Josh Poimboeuf | 7631376 | 2021-01-21 15:29:18 -0600 | [diff] [blame] | 58 | static inline bool is_dynamic_jump(struct instruction *insn) |
| 59 | { |
| 60 | return insn->type == INSN_JUMP_DYNAMIC || |
| 61 | insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL; |
| 62 | } |
| 63 | |
| 64 | static inline bool is_jump(struct instruction *insn) |
| 65 | { |
| 66 | return is_static_jump(insn) || is_dynamic_jump(insn); |
| 67 | } |
| 68 | |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 69 | struct instruction *find_insn(struct objtool_file *file, |
| 70 | struct section *sec, unsigned long offset); |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 71 | |
Josh Poimboeuf | baa4146 | 2017-06-28 10:11:07 -0500 | [diff] [blame] | 72 | #define for_each_insn(file, insn) \ |
| 73 | list_for_each_entry(insn, &file->insn_list, list) |
| 74 | |
Josh Poimboeuf | 627fce1 | 2017-07-11 10:33:42 -0500 | [diff] [blame] | 75 | #define sec_for_each_insn(file, sec, insn) \ |
| 76 | for (insn = find_insn(file, sec, 0); \ |
| 77 | insn && &insn->list != &file->insn_list && \ |
| 78 | insn->sec == sec; \ |
| 79 | insn = list_next_entry(insn, list)) |
| 80 | |
Josh Poimboeuf | dcc914f | 2017-06-28 10:11:05 -0500 | [diff] [blame] | 81 | #endif /* _CHECK_H */ |