blob: 2804848e628e3718d37e27ca0f19001ba80764f8 [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Josh Poimboeufdcc914f2017-06-28 10:11:05 -05002/*
3 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
Josh Poimboeufdcc914f2017-06-28 10:11:05 -05004 */
5
6#ifndef _CHECK_H
7#define _CHECK_H
8
9#include <stdbool.h>
Josh Poimboeufbaa41462017-06-28 10:11:07 -050010#include "cfi.h"
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050011#include "arch.h"
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050012
Josh Poimboeufbaa41462017-06-28 10:11:07 -050013struct insn_state {
Peter Zijlstrae7c02192020-03-25 14:04:45 +010014 struct cfi_state cfi;
Peter Zijlstraea242132019-02-25 12:50:09 +010015 unsigned int uaccess_stack;
Peter Zijlstrae7c02192020-03-25 14:04:45 +010016 bool uaccess;
17 bool df;
Peter Zijlstrac4a33932020-03-10 18:57:41 +010018 bool noinstr;
19 s8 instr;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050020};
21
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050022struct instruction {
23 struct list_head list;
24 struct hlist_node hash;
Josh Poimboeuf1e7e4782020-08-18 15:57:45 +020025 struct list_head static_call_node;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050026 struct section *sec;
27 unsigned long offset;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050028 unsigned int len;
Josh Poimboeuf9fe7b762019-07-17 20:36:56 -050029 enum insn_type type;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050030 unsigned long immediate;
Alexandre Chartre13fab062020-04-14 12:36:11 +020031 bool dead_end, ignore, ignore_alts;
Peter Zijlstrac536ed22020-04-01 16:54:26 +020032 bool hint;
Peter Zijlstrab5bc2232018-01-16 10:24:06 +010033 bool retpoline_safe;
Peter Zijlstrac4a33932020-03-10 18:57:41 +010034 s8 instr;
Peter Zijlstra882a0db2019-07-24 17:47:26 -050035 u8 visited;
Peter Zijlstrae25eea82020-04-01 16:38:19 +020036 u8 ret_offset;
Alexandre Chartre13fab062020-04-14 12:36:11 +020037 int alt_group;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050038 struct symbol *call_dest;
39 struct instruction *jump_dest;
Peter Zijlstra99ce7962018-02-08 14:02:32 +010040 struct instruction *first_jump_src;
Matt Helsleyf1974222020-05-29 14:01:13 -070041 struct reloc *jump_table;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050042 struct list_head alts;
43 struct symbol *func;
Julien Thierry65ea47d2020-03-27 15:28:47 +000044 struct list_head stack_ops;
Peter Zijlstrae7c02192020-03-25 14:04:45 +010045 struct cfi_state cfi;
Julien Thierry66734e32020-08-25 13:47:42 +010046#ifdef INSN_USE_ORC
Josh Poimboeuf627fce12017-07-11 10:33:42 -050047 struct orc_entry orc;
Julien Thierry66734e32020-08-25 13:47:42 +010048#endif
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050049};
50
Julien Thierry45245f52020-09-04 16:30:23 +010051static inline bool is_static_jump(struct instruction *insn)
52{
53 return insn->type == INSN_JUMP_CONDITIONAL ||
54 insn->type == INSN_JUMP_UNCONDITIONAL;
55}
56
Josh Poimboeuf76313762021-01-21 15:29:18 -060057static inline bool is_dynamic_jump(struct instruction *insn)
58{
59 return insn->type == INSN_JUMP_DYNAMIC ||
60 insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
61}
62
63static inline bool is_jump(struct instruction *insn)
64{
65 return is_static_jump(insn) || is_dynamic_jump(insn);
66}
67
Josh Poimboeuf627fce12017-07-11 10:33:42 -050068struct instruction *find_insn(struct objtool_file *file,
69 struct section *sec, unsigned long offset);
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050070
Josh Poimboeufbaa41462017-06-28 10:11:07 -050071#define for_each_insn(file, insn) \
72 list_for_each_entry(insn, &file->insn_list, list)
73
Josh Poimboeuf627fce12017-07-11 10:33:42 -050074#define sec_for_each_insn(file, sec, insn) \
75 for (insn = find_insn(file, sec, 0); \
76 insn && &insn->list != &file->insn_list && \
77 insn->sec == sec; \
78 insn = list_next_entry(insn, list))
79
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050080#endif /* _CHECK_H */