/* dw2gencfi.h - Support for generating Dwarf2 CFI information.
- Copyright 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003-2020 Free Software Foundation, Inc.
Contributed by Michal Ludvig <mludvig@suse.cz>
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
+ the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
#ifndef DW2GENCFI_H
#define DW2GENCFI_H
-#include "elf/dwarf2.h"
+#include "dwarf2.h"
-struct cfi_config {
- /* Target address length in bytes. (usually 4 or 8).
- Round it up for archs like S/390 with 31b addresses. */
- unsigned int addr_length;
+struct symbol;
- /* Alignment of .eh_frame blocks in bytes (usually 1, 4 or 8). */
- unsigned int eh_align;
-
- /* Code alignment (1 for x86/amd64 machines, 4 or 8 for
- RISC machines). Consult Dwarf2 standard for details. */
- int code_align;
-
- /* Data (stack) alignment (-4 on x86, -8 on amd64, something
- positive on archs where stack grows up). Consult Dwarf2
- standard for details. */
- int data_align;
-
- /* Return address column (0x8 on x86, 0x10 on amd64). Consult
- Dwarf2 standard for details. */
- int ra_column;
+extern const pseudo_typeS cfi_pseudo_table[];
- /* Relocation type for init_addr FDE record. (BFD_RELOC_64
- on amd64). */
- int reloc_type;
+/* cfi_finish() is called at the end of file. It will complain if
+ the last CFI wasn't properly closed by .cfi_endproc. */
+extern void cfi_finish (void);
+
+/* Entry points for backends to add unwind information. */
+extern void cfi_new_fde (struct symbol *);
+extern void cfi_end_fde (struct symbol *);
+extern void cfi_set_return_column (unsigned);
+extern void cfi_set_sections (void);
+extern void cfi_add_advance_loc (struct symbol *);
+extern void cfi_add_label (const char *);
+
+extern void cfi_add_CFA_offset (unsigned, offsetT);
+extern void cfi_add_CFA_val_offset (unsigned, offsetT);
+extern void cfi_add_CFA_def_cfa (unsigned, offsetT);
+extern void cfi_add_CFA_register (unsigned, unsigned);
+extern void cfi_add_CFA_def_cfa_register (unsigned);
+extern void cfi_add_CFA_def_cfa_offset (offsetT);
+extern void cfi_add_CFA_restore (unsigned);
+extern void cfi_add_CFA_undefined (unsigned);
+extern void cfi_add_CFA_same_value (unsigned);
+extern void cfi_add_CFA_remember_state (void);
+extern void cfi_add_CFA_restore_state (void);
+
+/* Structures for md_cfi_end. */
+
+#if defined (TE_PE) || defined (TE_PEP)
+#define SUPPORT_FRAME_LINKONCE 1
+#else
+#define SUPPORT_FRAME_LINKONCE 0
+#endif
+
+#ifdef tc_cfi_reloc_for_encoding
+#define SUPPORT_COMPACT_EH 1
+#else
+#define SUPPORT_COMPACT_EH 0
+#endif
+
+#define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH)
+
+struct cfi_insn_data
+{
+ struct cfi_insn_data *next;
+#if MULTIPLE_FRAME_SECTIONS
+ segT cur_seg;
+#endif
+ int insn;
+ union
+ {
+ struct
+ {
+ unsigned reg;
+ offsetT offset;
+ } ri;
+
+ struct
+ {
+ unsigned reg1;
+ unsigned reg2;
+ } rr;
+
+ unsigned r;
+ offsetT i;
+
+ struct
+ {
+ symbolS *lab1;
+ symbolS *lab2;
+ } ll;
+
+ struct cfi_escape_data *esc;
+
+ struct
+ {
+ unsigned reg, encoding;
+ expressionS exp;
+ } ea;
+
+ const char *sym_name;
+ } u;
};
-/* Codes of CFI instructions taken from Dwarf2 standard. */
-enum cfi_insn {
- CFA_nop = DW_CFA_nop,
- CFA_set_loc = DW_CFA_set_loc,
- CFA_advance_loc1 = DW_CFA_advance_loc1,
- CFA_advance_loc2 = DW_CFA_advance_loc2,
- CFA_advance_loc4 = DW_CFA_advance_loc4,
- CFA_offset_extended = DW_CFA_offset_extended,
- CFA_resotre_extended = DW_CFA_restore_extended,
- CFA_undefined = DW_CFA_undefined,
- CFA_same_value = DW_CFA_same_value,
- CFA_register = DW_CFA_register,
- CFA_remember_state = DW_CFA_remember_state,
- CFA_restore_state = DW_CFA_restore_state,
- CFA_def_cfa = DW_CFA_def_cfa,
- CFA_def_cfa_register = DW_CFA_def_cfa_register,
- CFA_def_cfa_offset = DW_CFA_def_cfa_offset,
- CFA_advance_loc = DW_CFA_advance_loc,
- CFA_offset = DW_CFA_offset,
- CFA_restore = DW_CFA_restore,
-
- /* These don't belong to the standard. */
- CFI_startproc = 0xff00,
- CFI_endproc = 0xff01,
- CFI_adjust_cfa_offset = 0xff10,
- CFI_verbose = 0xffff
+/* An enumeration describing the Compact EH header format. The least
+ significant bit is used to distinguish the entries.
+
+ Inline Compact: Function offset [0]
+ Four chars of unwind data.
+ Out-of-line Compact: Function offset [1]
+ Compact unwind data offset [0]
+ Legacy: Function offset [1]
+ Unwind data offset [1]
+
+ The header type is initialized to EH_COMPACT_UNKNOWN until the
+ format is discovered by encountering a .fde_data entry.
+ Failure to find a .fde_data entry will cause an EH_COMPACT_LEGACY
+ header to be generated. */
+
+enum {
+ EH_COMPACT_UNKNOWN,
+ EH_COMPACT_LEGACY,
+ EH_COMPACT_INLINE,
+ EH_COMPACT_OUTLINE,
+ EH_COMPACT_OUTLINE_DONE,
+ /* Outline if .cfi_inline_lsda used, otherwise legacy FDE. */
+ EH_COMPACT_HAS_LSDA
};
-extern const pseudo_typeS cfi_pseudo_table[];
-
-/* Insert .cfi_* directives to the list of pseudo-ops. */
-void cfi_pop_insert PARAMS ((void));
+/* Stack of old CFI data, for save/restore. */
+struct cfa_save_data
+{
+ struct cfa_save_data *next;
+ offsetT cfa_offset;
+};
-/* Set/change setup of the CFI machinery. This change won't
- affect already generated CIEs/FDEs. */
-void cfi_set_config PARAMS ((struct cfi_config *cfg));
+/* Current open FDE entry. */
+struct frch_cfi_data
+{
+ struct fde_entry *cur_fde_data;
+ symbolS *last_address;
+ offsetT cur_cfa_offset;
+ struct cfa_save_data *cfa_save_stack;
+};
-/* cfi_finish() is called at the end of file. It will complain if
- the last CFI wasn't properly closed by .cfi_endproc. */
-void cfi_finish PARAMS ((void));
+struct fde_entry
+{
+ struct fde_entry *next;
+#if MULTIPLE_FRAME_SECTIONS
+ segT cur_seg;
+#endif
+ symbolS *start_address;
+ symbolS *end_address;
+ struct cfi_insn_data *data;
+ struct cfi_insn_data **last;
+ unsigned char per_encoding;
+ unsigned char lsda_encoding;
+ int personality_id;
+ expressionS personality;
+ expressionS lsda;
+ unsigned int return_column;
+ unsigned int signal_frame;
+#if MULTIPLE_FRAME_SECTIONS
+ int handled;
+#endif
+ int eh_header_type;
+ /* Compact unwinding opcodes, not including the PR byte or LSDA. */
+ int eh_data_size;
+ bfd_byte *eh_data;
+ /* For out of line tables and FDEs. */
+ symbolS *eh_loc;
+ int sections;
+#ifdef tc_fde_entry_extras
+ tc_fde_entry_extras
+#endif
+};
-/* Add CFI instruction to the list of instructions
- of the current frame. cfi_add_insn() could be used
- in tc_cfi_frame_initial_instructions() to add instructions
- needed for every frame (ie. those that usually go to CIE). */
-void cfi_add_insn (enum cfi_insn insn, long param0, long param1);
+/* The list of all FDEs that have been collected. */
+extern struct fde_entry *all_fde_data;
+
+/* Fake CFI type; outside the byte range of any real CFI insn. */
+#define CFI_adjust_cfa_offset 0x100
+#define CFI_return_column 0x101
+#define CFI_rel_offset 0x102
+#define CFI_escape 0x103
+#define CFI_signal_frame 0x104
+#define CFI_val_encoded_addr 0x105
+#define CFI_label 0x106
+
+/* By default emit .eh_frame only, not .debug_frame. */
+#define CFI_EMIT_eh_frame (1 << 0)
+#define CFI_EMIT_debug_frame (1 << 1)
+#define CFI_EMIT_target (1 << 2)
+#define CFI_EMIT_eh_frame_compact (1 << 3)
#endif /* DW2GENCFI_H */