blob: 3a9a3daf6e3df78cf1d16fef4c63e63172b7139e [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;
Peter Zijlstra7dcfcd42020-08-06 15:14:09 -070026 struct list_head mcount_loc_node;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050027 struct section *sec;
28 unsigned long offset;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050029 unsigned int len;
Josh Poimboeuf9fe7b762019-07-17 20:36:56 -050030 enum insn_type type;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050031 unsigned long immediate;
Alexandre Chartre13fab062020-04-14 12:36:11 +020032 bool dead_end, ignore, ignore_alts;
Peter Zijlstrac536ed22020-04-01 16:54:26 +020033 bool hint;
Peter Zijlstrab5bc2232018-01-16 10:24:06 +010034 bool retpoline_safe;
Peter Zijlstrac4a33932020-03-10 18:57:41 +010035 s8 instr;
Peter Zijlstra882a0db2019-07-24 17:47:26 -050036 u8 visited;
Peter Zijlstrae25eea82020-04-01 16:38:19 +020037 u8 ret_offset;
Alexandre Chartre13fab062020-04-14 12:36:11 +020038 int alt_group;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050039 struct symbol *call_dest;
40 struct instruction *jump_dest;
Peter Zijlstra99ce7962018-02-08 14:02:32 +010041 struct instruction *first_jump_src;
Matt Helsleyf1974222020-05-29 14:01:13 -070042 struct reloc *jump_table;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050043 struct list_head alts;
44 struct symbol *func;
Julien Thierry65ea47d2020-03-27 15:28:47 +000045 struct list_head stack_ops;
Peter Zijlstrae7c02192020-03-25 14:04:45 +010046 struct cfi_state cfi;
Julien Thierry66734e32020-08-25 13:47:42 +010047#ifdef INSN_USE_ORC
Josh Poimboeuf627fce12017-07-11 10:33:42 -050048 struct orc_entry orc;
Julien Thierry66734e32020-08-25 13:47:42 +010049#endif
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050050};
51
Julien Thierry45245f52020-09-04 16:30:23 +010052static 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 Poimboeuf76313762021-01-21 15:29:18 -060058static 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
64static inline bool is_jump(struct instruction *insn)
65{
66 return is_static_jump(insn) || is_dynamic_jump(insn);
67}
68
Josh Poimboeuf627fce12017-07-11 10:33:42 -050069struct instruction *find_insn(struct objtool_file *file,
70 struct section *sec, unsigned long offset);
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050071
Josh Poimboeufbaa41462017-06-28 10:11:07 -050072#define for_each_insn(file, insn) \
73 list_for_each_entry(insn, &file->insn_list, list)
74
Josh Poimboeuf627fce12017-07-11 10:33:42 -050075#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 Poimboeufdcc914f2017-06-28 10:11:05 -050081#endif /* _CHECK_H */