check.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef _CHECK_H
  18. #define _CHECK_H
  19. #include <stdbool.h>
  20. #include "elf.h"
  21. #include "cfi.h"
  22. #include "arch.h"
  23. #include "orc.h"
  24. #include <linux/hashtable.h>
  25. struct insn_state {
  26. struct cfi_reg cfa;
  27. struct cfi_reg regs[CFI_NUM_REGS];
  28. int stack_size;
  29. unsigned char type;
  30. bool bp_scratch;
  31. bool drap;
  32. int drap_reg, drap_offset;
  33. struct cfi_reg vals[CFI_NUM_REGS];
  34. };
  35. struct instruction {
  36. struct list_head list;
  37. struct hlist_node hash;
  38. struct section *sec;
  39. unsigned long offset;
  40. unsigned int len;
  41. unsigned char type;
  42. unsigned long immediate;
  43. bool alt_group, visited, dead_end, ignore, hint, save, restore;
  44. struct symbol *call_dest;
  45. struct instruction *jump_dest;
  46. struct list_head alts;
  47. struct symbol *func;
  48. struct stack_op stack_op;
  49. struct insn_state state;
  50. struct orc_entry orc;
  51. };
  52. struct objtool_file {
  53. struct elf *elf;
  54. struct list_head insn_list;
  55. DECLARE_HASHTABLE(insn_hash, 16);
  56. struct section *rodata, *whitelist;
  57. bool ignore_unreachables, c_file, hints;
  58. };
  59. int check(const char *objname, bool no_fp, bool no_unreachable, bool orc);
  60. struct instruction *find_insn(struct objtool_file *file,
  61. struct section *sec, unsigned long offset);
  62. #define for_each_insn(file, insn) \
  63. list_for_each_entry(insn, &file->insn_list, list)
  64. #define sec_for_each_insn(file, sec, insn) \
  65. for (insn = find_insn(file, sec, 0); \
  66. insn && &insn->list != &file->insn_list && \
  67. insn->sec == sec; \
  68. insn = list_next_entry(insn, list))
  69. #endif /* _CHECK_H */