linux/tools/objtool/check.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
   3 *
   4 * This program is free software; you can redistribute it and/or
   5 * modify it under the terms of the GNU General Public License
   6 * as published by the Free Software Foundation; either version 2
   7 * of the License, or (at your option) any later version.
   8 *
   9 * This program is distributed in the hope that it will be useful,
  10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12 * GNU General Public License for more details.
  13 *
  14 * You should have received a copy of the GNU General Public License
  15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16 */
  17
  18#ifndef _CHECK_H
  19#define _CHECK_H
  20
  21#include <stdbool.h>
  22#include "elf.h"
  23#include "cfi.h"
  24#include "arch.h"
  25#include "orc.h"
  26#include <linux/hashtable.h>
  27
  28struct insn_state {
  29        struct cfi_reg cfa;
  30        struct cfi_reg regs[CFI_NUM_REGS];
  31        int stack_size;
  32        unsigned char type;
  33        bool bp_scratch;
  34        bool drap, end, uaccess;
  35        unsigned int uaccess_stack;
  36        int drap_reg, drap_offset;
  37        struct cfi_reg vals[CFI_NUM_REGS];
  38};
  39
  40struct instruction {
  41        struct list_head list;
  42        struct hlist_node hash;
  43        struct section *sec;
  44        unsigned long offset;
  45        unsigned int len;
  46        unsigned char type;
  47        unsigned long immediate;
  48        bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
  49        bool retpoline_safe;
  50        struct symbol *call_dest;
  51        struct instruction *jump_dest;
  52        struct instruction *first_jump_src;
  53        struct rela *jump_table;
  54        struct list_head alts;
  55        struct symbol *func;
  56        struct stack_op stack_op;
  57        struct insn_state state;
  58        struct orc_entry orc;
  59};
  60
  61struct objtool_file {
  62        struct elf *elf;
  63        struct list_head insn_list;
  64        DECLARE_HASHTABLE(insn_hash, 16);
  65        struct section *whitelist;
  66        bool ignore_unreachables, c_file, hints, rodata;
  67};
  68
  69int check(const char *objname, bool orc);
  70
  71struct instruction *find_insn(struct objtool_file *file,
  72                              struct section *sec, unsigned long offset);
  73
  74#define for_each_insn(file, insn)                                       \
  75        list_for_each_entry(insn, &file->insn_list, list)
  76
  77#define sec_for_each_insn(file, sec, insn)                              \
  78        for (insn = find_insn(file, sec, 0);                            \
  79             insn && &insn->list != &file->insn_list &&                 \
  80                        insn->sec == sec;                               \
  81             insn = list_next_entry(insn, list))
  82
  83
  84#endif /* _CHECK_H */
  85