blob: f0ce8ffe71359a47515eeb929ef1edadee2f8507 [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>
10#include "elf.h"
Josh Poimboeufbaa41462017-06-28 10:11:07 -050011#include "cfi.h"
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050012#include "arch.h"
Josh Poimboeuf627fce12017-07-11 10:33:42 -050013#include "orc.h"
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050014#include <linux/hashtable.h>
15
Josh Poimboeufbaa41462017-06-28 10:11:07 -050016struct insn_state {
17 struct cfi_reg cfa;
18 struct cfi_reg regs[CFI_NUM_REGS];
19 int stack_size;
Josh Poimboeuf627fce12017-07-11 10:33:42 -050020 unsigned char type;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050021 bool bp_scratch;
Peter Zijlstra2f0f9e92019-02-25 11:10:55 +010022 bool drap, end, uaccess, df;
Peter Zijlstraea242132019-02-25 12:50:09 +010023 unsigned int uaccess_stack;
Josh Poimboeufbf4d1a82017-08-10 16:37:26 -050024 int drap_reg, drap_offset;
Josh Poimboeufdd88a0a2017-08-29 12:51:03 -050025 struct cfi_reg vals[CFI_NUM_REGS];
Josh Poimboeufbaa41462017-06-28 10:11:07 -050026};
27
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050028struct instruction {
29 struct list_head list;
30 struct hlist_node hash;
31 struct section *sec;
32 unsigned long offset;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050033 unsigned int len;
Josh Poimboeuf9fe7b762019-07-17 20:36:56 -050034 enum insn_type type;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050035 unsigned long immediate;
Peter Zijlstra882a0db2019-07-24 17:47:26 -050036 bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;
Peter Zijlstrab5bc2232018-01-16 10:24:06 +010037 bool retpoline_safe;
Peter Zijlstra882a0db2019-07-24 17:47:26 -050038 u8 visited;
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;
Jann Hornbd98c812019-07-17 20:36:54 -050042 struct rela *jump_table;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050043 struct list_head alts;
44 struct symbol *func;
Josh Poimboeufbaa41462017-06-28 10:11:07 -050045 struct stack_op stack_op;
46 struct insn_state state;
Josh Poimboeuf627fce12017-07-11 10:33:42 -050047 struct orc_entry orc;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050048};
49
50struct objtool_file {
51 struct elf *elf;
52 struct list_head insn_list;
Peter Zijlstra513b5ca2020-03-12 10:20:46 +010053 DECLARE_HASHTABLE(insn_hash, 20);
Allan Xavier4a60aa02018-09-07 08:12:01 -050054 bool ignore_unreachables, c_file, hints, rodata;
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050055};
56
Peter Zijlstra43a45252018-01-16 17:16:32 +010057int check(const char *objname, bool orc);
Josh Poimboeuf627fce12017-07-11 10:33:42 -050058
59struct instruction *find_insn(struct objtool_file *file,
60 struct section *sec, unsigned long offset);
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050061
Josh Poimboeufbaa41462017-06-28 10:11:07 -050062#define for_each_insn(file, insn) \
63 list_for_each_entry(insn, &file->insn_list, list)
64
Josh Poimboeuf627fce12017-07-11 10:33:42 -050065#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
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050072#endif /* _CHECK_H */