blob: 6d875ca6fce007358e6caf8069fb476ea04ed259 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
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
16struct 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;
David Brazdil0f672f62019-12-10 10:32:29 +000022 bool drap, end, uaccess, df;
23 unsigned int uaccess_stack;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000024 int drap_reg, drap_offset;
25 struct cfi_reg vals[CFI_NUM_REGS];
26};
27
28struct instruction {
29 struct list_head list;
30 struct hlist_node hash;
31 struct section *sec;
32 unsigned long offset;
33 unsigned int len;
David Brazdil0f672f62019-12-10 10:32:29 +000034 enum insn_type type;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035 unsigned long immediate;
David Brazdil0f672f62019-12-10 10:32:29 +000036 bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000037 bool retpoline_safe;
David Brazdil0f672f62019-12-10 10:32:29 +000038 u8 visited;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039 struct symbol *call_dest;
40 struct instruction *jump_dest;
41 struct instruction *first_jump_src;
David Brazdil0f672f62019-12-10 10:32:29 +000042 struct rela *jump_table;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000043 struct list_head alts;
44 struct symbol *func;
45 struct stack_op stack_op;
46 struct insn_state state;
47 struct orc_entry orc;
48};
49
50struct objtool_file {
51 struct elf *elf;
52 struct list_head insn_list;
53 DECLARE_HASHTABLE(insn_hash, 16);
David Brazdil0f672f62019-12-10 10:32:29 +000054 bool ignore_unreachables, c_file, hints, rodata;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000055};
56
57int check(const char *objname, bool orc);
58
59struct instruction *find_insn(struct objtool_file *file,
60 struct section *sec, unsigned long offset);
61
62#define for_each_insn(file, insn) \
63 list_for_each_entry(insn, &file->insn_list, list)
64
65#define sec_for_each_insn(file, sec, insn) \
66 for (insn = find_insn(file, sec, 0); \
67 insn && &insn->list != &file->insn_list && \
68 insn->sec == sec; \
69 insn = list_next_entry(insn, list))
70
71
72#endif /* _CHECK_H */