check.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
  4. */
  5. #ifndef _CHECK_H
  6. #define _CHECK_H
  7. #include <stdbool.h>
  8. #include "elf.h"
  9. #include "cfi.h"
  10. #include "arch.h"
  11. #include "orc.h"
  12. #include <linux/hashtable.h>
  13. struct insn_state {
  14. struct cfi_reg cfa;
  15. struct cfi_reg regs[CFI_NUM_REGS];
  16. int stack_size;
  17. unsigned char type;
  18. bool bp_scratch;
  19. bool drap, end, uaccess, df;
  20. unsigned int uaccess_stack;
  21. int drap_reg, drap_offset;
  22. struct cfi_reg vals[CFI_NUM_REGS];
  23. };
  24. struct instruction {
  25. struct list_head list;
  26. struct hlist_node hash;
  27. struct section *sec;
  28. unsigned long offset;
  29. unsigned int len;
  30. enum insn_type type;
  31. unsigned long immediate;
  32. bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;
  33. bool retpoline_safe;
  34. u8 visited;
  35. struct symbol *call_dest;
  36. struct instruction *jump_dest;
  37. struct instruction *first_jump_src;
  38. struct rela *jump_table;
  39. struct list_head alts;
  40. struct symbol *func;
  41. struct stack_op stack_op;
  42. struct insn_state state;
  43. struct orc_entry orc;
  44. };
  45. struct objtool_file {
  46. struct elf *elf;
  47. struct list_head insn_list;
  48. DECLARE_HASHTABLE(insn_hash, 16);
  49. bool ignore_unreachables, c_file, hints, rodata;
  50. };
  51. int check(const char *objname, bool orc);
  52. struct instruction *find_insn(struct objtool_file *file,
  53. struct section *sec, unsigned long offset);
  54. #define for_each_insn(file, insn) \
  55. list_for_each_entry(insn, &file->insn_list, list)
  56. #define sec_for_each_insn(file, sec, insn) \
  57. for (insn = find_insn(file, sec, 0); \
  58. insn && &insn->list != &file->insn_list && \
  59. insn->sec == sec; \
  60. insn = list_next_entry(insn, list))
  61. #endif /* _CHECK_H */