dw2gencfi.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* dw2gencfi.h - Support for generating Dwarf2 CFI information.
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. Contributed by Michal Ludvig <mludvig@suse.cz>
  4. This file is part of GAS, the GNU Assembler.
  5. GAS is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GAS 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. You should have received a copy of the GNU General Public License
  14. along with GAS; see the file COPYING. If not, write to the Free
  15. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. #ifndef DW2GENCFI_H
  18. #define DW2GENCFI_H
  19. #include "dwarf2.h"
  20. struct symbol;
  21. extern const pseudo_typeS cfi_pseudo_table[];
  22. /* cfi_finish() is called at the end of file. It will complain if
  23. the last CFI wasn't properly closed by .cfi_endproc. */
  24. extern void cfi_finish (void);
  25. /* Entry points for backends to add unwind information. */
  26. extern void cfi_new_fde (struct symbol *);
  27. extern void cfi_end_fde (struct symbol *);
  28. extern void cfi_set_return_column (unsigned);
  29. extern void cfi_set_sections (void);
  30. extern void cfi_add_advance_loc (struct symbol *);
  31. extern void cfi_add_label (const char *);
  32. extern void cfi_add_CFA_offset (unsigned, offsetT);
  33. extern void cfi_add_CFA_val_offset (unsigned, offsetT);
  34. extern void cfi_add_CFA_def_cfa (unsigned, offsetT);
  35. extern void cfi_add_CFA_register (unsigned, unsigned);
  36. extern void cfi_add_CFA_def_cfa_register (unsigned);
  37. extern void cfi_add_CFA_def_cfa_offset (offsetT);
  38. extern void cfi_add_CFA_restore (unsigned);
  39. extern void cfi_add_CFA_undefined (unsigned);
  40. extern void cfi_add_CFA_same_value (unsigned);
  41. extern void cfi_add_CFA_remember_state (void);
  42. extern void cfi_add_CFA_restore_state (void);
  43. /* Structures for md_cfi_end. */
  44. #if defined (TE_PE) || defined (TE_PEP)
  45. #define SUPPORT_FRAME_LINKONCE 1
  46. #else
  47. #define SUPPORT_FRAME_LINKONCE 0
  48. #endif
  49. #ifdef tc_cfi_reloc_for_encoding
  50. #define SUPPORT_COMPACT_EH 1
  51. #else
  52. #define SUPPORT_COMPACT_EH 0
  53. #endif
  54. #define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH)
  55. struct cfi_insn_data
  56. {
  57. struct cfi_insn_data *next;
  58. #if MULTIPLE_FRAME_SECTIONS
  59. segT cur_seg;
  60. #endif
  61. int insn;
  62. union
  63. {
  64. struct
  65. {
  66. unsigned reg;
  67. offsetT offset;
  68. } ri;
  69. struct
  70. {
  71. unsigned reg1;
  72. unsigned reg2;
  73. } rr;
  74. unsigned r;
  75. offsetT i;
  76. struct
  77. {
  78. symbolS *lab1;
  79. symbolS *lab2;
  80. } ll;
  81. struct cfi_escape_data *esc;
  82. struct
  83. {
  84. unsigned reg, encoding;
  85. expressionS exp;
  86. } ea;
  87. const char *sym_name;
  88. } u;
  89. };
  90. /* An enumeration describing the Compact EH header format. The least
  91. significant bit is used to distinguish the entries.
  92. Inline Compact: Function offset [0]
  93. Four chars of unwind data.
  94. Out-of-line Compact: Function offset [1]
  95. Compact unwind data offset [0]
  96. Legacy: Function offset [1]
  97. Unwind data offset [1]
  98. The header type is initialized to EH_COMPACT_UNKNOWN until the
  99. format is discovered by encountering a .fde_data entry.
  100. Failure to find a .fde_data entry will cause an EH_COMPACT_LEGACY
  101. header to be generated. */
  102. enum {
  103. EH_COMPACT_UNKNOWN,
  104. EH_COMPACT_LEGACY,
  105. EH_COMPACT_INLINE,
  106. EH_COMPACT_OUTLINE,
  107. EH_COMPACT_OUTLINE_DONE,
  108. /* Outline if .cfi_inline_lsda used, otherwise legacy FDE. */
  109. EH_COMPACT_HAS_LSDA
  110. };
  111. /* Stack of old CFI data, for save/restore. */
  112. struct cfa_save_data
  113. {
  114. struct cfa_save_data *next;
  115. offsetT cfa_offset;
  116. };
  117. /* Current open FDE entry. */
  118. struct frch_cfi_data
  119. {
  120. struct fde_entry *cur_fde_data;
  121. symbolS *last_address;
  122. offsetT cur_cfa_offset;
  123. struct cfa_save_data *cfa_save_stack;
  124. };
  125. struct fde_entry
  126. {
  127. struct fde_entry *next;
  128. #if MULTIPLE_FRAME_SECTIONS
  129. segT cur_seg;
  130. #endif
  131. symbolS *start_address;
  132. symbolS *end_address;
  133. struct cfi_insn_data *data;
  134. struct cfi_insn_data **last;
  135. unsigned char per_encoding;
  136. unsigned char lsda_encoding;
  137. int personality_id;
  138. expressionS personality;
  139. expressionS lsda;
  140. unsigned int return_column;
  141. unsigned int signal_frame;
  142. #if MULTIPLE_FRAME_SECTIONS
  143. int handled;
  144. #endif
  145. int eh_header_type;
  146. /* Compact unwinding opcodes, not including the PR byte or LSDA. */
  147. int eh_data_size;
  148. bfd_byte *eh_data;
  149. /* For out of line tables and FDEs. */
  150. symbolS *eh_loc;
  151. int sections;
  152. #ifdef tc_fde_entry_extras
  153. tc_fde_entry_extras
  154. #endif
  155. };
  156. /* The list of all FDEs that have been collected. */
  157. extern struct fde_entry *all_fde_data;
  158. /* Fake CFI type; outside the byte range of any real CFI insn. */
  159. #define CFI_adjust_cfa_offset 0x100
  160. #define CFI_return_column 0x101
  161. #define CFI_rel_offset 0x102
  162. #define CFI_escape 0x103
  163. #define CFI_signal_frame 0x104
  164. #define CFI_val_encoded_addr 0x105
  165. #define CFI_label 0x106
  166. /* By default emit .eh_frame only, not .debug_frame. */
  167. #define CFI_EMIT_eh_frame (1 << 0)
  168. #define CFI_EMIT_debug_frame (1 << 1)
  169. #define CFI_EMIT_target (1 << 2)
  170. #define CFI_EMIT_eh_frame_compact (1 << 3)
  171. #endif /* DW2GENCFI_H */