/* dw2gencfi.c - Support for generating Dwarf2 CFI information.
- Copyright 2003 Free Software Foundation, Inc.
+ Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by Michal Ludvig <mludvig@suse.cz>
This file is part of GAS, the GNU Assembler.
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. */
#include "as.h"
#include "dw2gencfi.h"
/* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field
of the CIE. Default to 1 if not otherwise specified. */
-#ifndef DWARF2_LINE_MIN_INSN_LENGTH
+#ifndef DWARF2_LINE_MIN_INSN_LENGTH
# define DWARF2_LINE_MIN_INSN_LENGTH 1
#endif
provide the following definitions. Otherwise provide them to
allow compilation to continue. */
#ifndef TARGET_USE_CFIPOP
-# ifndef DWARF2_DEFAULT_RETURN_COLUMN
+# ifndef DWARF2_DEFAULT_RETURN_COLUMN
# define DWARF2_DEFAULT_RETURN_COLUMN 0
# endif
-# ifndef DWARF2_CIE_DATA_ALIGNMENT
+# ifndef DWARF2_CIE_DATA_ALIGNMENT
# define DWARF2_CIE_DATA_ALIGNMENT 1
# endif
#endif
+#ifndef EH_FRAME_ALIGNMENT
+# define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
+#endif
+
#ifndef tc_cfi_frame_initial_instructions
# define tc_cfi_frame_initial_instructions() ((void)0)
#endif
cfa_save_stack = p->next;
free (p);
}
+ else
+ as_bad (_("CFI state restore without previous remember"));
}
\f
{ "cfi_same_value", dot_cfi, DW_CFA_same_value },
{ "cfi_remember_state", dot_cfi, DW_CFA_remember_state },
{ "cfi_restore_state", dot_cfi, DW_CFA_restore_state },
+ { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save },
{ "cfi_escape", dot_cfi_escape, 0 },
{ NULL, NULL, 0 }
};
}
#endif
- expression (&exp);
+ expression_and_evaluate (&exp);
switch (exp.X_op)
{
case O_register:
if (!cur_fde_data)
{
as_bad (_("CFI instruction used without previous .cfi_startproc"));
+ ignore_rest_of_line ();
return;
}
break;
case DW_CFA_restore:
- reg1 = cfi_parse_reg ();
- cfi_add_CFA_restore (reg1);
+ for (;;)
+ {
+ reg1 = cfi_parse_reg ();
+ cfi_add_CFA_restore (reg1);
+ SKIP_WHITESPACE ();
+ if (*input_line_pointer != ',')
+ break;
+ ++input_line_pointer;
+ }
break;
case DW_CFA_undefined:
- reg1 = cfi_parse_reg ();
- cfi_add_CFA_undefined (reg1);
+ for (;;)
+ {
+ reg1 = cfi_parse_reg ();
+ cfi_add_CFA_undefined (reg1);
+ SKIP_WHITESPACE ();
+ if (*input_line_pointer != ',')
+ break;
+ ++input_line_pointer;
+ }
break;
case DW_CFA_same_value:
cfi_add_CFA_restore_state ();
break;
+ case DW_CFA_GNU_window_save:
+ cfi_add_CFA_insn (DW_CFA_GNU_window_save);
+ break;
+
default:
abort ();
}
if (!cur_fde_data)
{
as_bad (_("CFI instruction used without previous .cfi_startproc"));
+ ignore_rest_of_line ();
return;
}
insn = alloc_cfi_insn_data ();
insn->insn = CFI_escape;
insn->u.esc = head;
+
+ --input_line_pointer;
+ demand_empty_rest_of_line ();
}
static void
if (cur_fde_data)
{
as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
+ ignore_rest_of_line ();
return;
}
}
demand_empty_rest_of_line ();
+ cur_cfa_offset = 0;
if (!simple)
tc_cfi_frame_initial_instructions ();
}
if (! cur_fde_data)
{
as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
+ ignore_rest_of_line ();
return;
}
cfi_end_fde (symbol_temp_new_now ());
+
+ demand_empty_rest_of_line ();
}
\f
{
out_one (DW_CFA_def_cfa_sf);
out_uleb128 (insn->u.ri.reg);
- out_uleb128 (offset);
+ out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
}
else
{
if (offset < 0)
{
out_one (DW_CFA_def_cfa_offset_sf);
- out_sleb128 (offset);
+ out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
}
else
{
out_one (insn->insn);
break;
+ case DW_CFA_GNU_window_save:
+ out_one (DW_CFA_GNU_window_save);
+ break;
+
case CFI_escape:
{
struct cfi_escape_data *e;
exp.X_op_symbol = after_size_address;
exp.X_add_number = 0;
- emit_expr (&exp, 4); /* Length */
+ emit_expr (&exp, 4); /* Length. */
symbol_set_value_now (after_size_address);
- out_four (0); /* CIE id */
- out_one (DW_CIE_VERSION); /* Version */
- out_one ('z'); /* Augmentation */
+ out_four (0); /* CIE id. */
+ out_one (DW_CIE_VERSION); /* Version. */
+ out_one ('z'); /* Augmentation. */
out_one ('R');
out_one (0);
- out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment */
- out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment */
- out_one (cie->return_column); /* Return column */
- out_uleb128 (1); /* Augmentation size */
+ out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment. */
+ out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment. */
+ if (DW_CIE_VERSION == 1) /* Return column. */
+ out_one (cie->return_column);
+ else
+ out_uleb128 (cie->return_column);
+ out_uleb128 (1); /* Augmentation size. */
+#if defined DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
out_one (DW_EH_PE_pcrel | DW_EH_PE_sdata4);
+#else
+ out_one (DW_EH_PE_sdata4);
+#endif
if (cie->first)
for (i = cie->first; i != cie->last; i = i->next)
output_cfi_insn (i);
- frag_align (2, 0, 0);
+ frag_align (2, DW_CFA_nop, 0);
symbol_set_value_now (end_address);
}
static void
output_fde (struct fde_entry *fde, struct cie_entry *cie,
- struct cfi_insn_data *first)
+ struct cfi_insn_data *first, int align)
{
symbolS *after_size_address, *end_address;
expressionS exp;
exp.X_add_symbol = end_address;
exp.X_op_symbol = after_size_address;
exp.X_add_number = 0;
- emit_expr (&exp, 4); /* Length */
+ emit_expr (&exp, 4); /* Length. */
symbol_set_value_now (after_size_address);
exp.X_add_symbol = after_size_address;
exp.X_op_symbol = cie->start_address;
- emit_expr (&exp, 4); /* CIE offset */
-
+ emit_expr (&exp, 4); /* CIE offset. */
+
+#ifdef DIFF_EXPR_OK
exp.X_add_symbol = fde->start_address;
exp.X_op_symbol = symbol_temp_new_now ();
- emit_expr (&exp, 4); /* Code offset */
+ emit_expr (&exp, 4); /* Code offset. */
+#else
+ exp.X_op = O_symbol;
+ exp.X_add_symbol = fde->start_address;
+ exp.X_op_symbol = NULL;
+#ifdef tc_cfi_emit_pcrel_expr
+ tc_cfi_emit_pcrel_expr (&exp, 4); /* Code offset. */
+#else
+ emit_expr (&exp, 4); /* Code offset. */
+#endif
+ exp.X_op = O_subtract;
+#endif
exp.X_add_symbol = fde->end_address;
- exp.X_op_symbol = fde->start_address; /* Code length */
+ exp.X_op_symbol = fde->start_address; /* Code length. */
emit_expr (&exp, 4);
- out_uleb128 (0); /* Augmentation size */
+ out_uleb128 (0); /* Augmentation size. */
for (; first; first = first->next)
output_cfi_insn (first);
- frag_align (2, 0, 0);
+ frag_align (align, DW_CFA_nop, 0);
symbol_set_value_now (end_address);
}
switch (i->insn)
{
case DW_CFA_advance_loc:
- /* We reached the first advance in the FDE, but did not
- reach the end of the CIE list. */
+ case DW_CFA_remember_state:
+ /* We reached the first advance/remember in the FDE,
+ but did not reach the end of the CIE list. */
goto fail;
case DW_CFA_offset:
}
/* Success if we reached the end of the CIE list, and we've either
- run out of FDE entries or we've encountered an advance. */
- if (i == cie->last && (!j || j->insn == DW_CFA_advance_loc))
+ run out of FDE entries or we've encountered an advance,
+ remember, or escape. */
+ if (i == cie->last
+ && (!j
+ || j->insn == DW_CFA_advance_loc
+ || j->insn == DW_CFA_remember_state
+ || j->insn == CFI_escape))
{
*pfirst = j;
return cie;
cie->first = fde->data;
for (i = cie->first; i ; i = i->next)
- if (i->insn == DW_CFA_advance_loc)
+ if (i->insn == DW_CFA_advance_loc
+ || i->insn == DW_CFA_remember_state
+ || i->insn == CFI_escape)
break;
cie->last = i;
/* Open .eh_frame section. */
cfi_seg = subseg_new (".eh_frame", 0);
-#ifdef BFD_ASSEMBLER
bfd_set_section_flags (stdoutput, cfi_seg,
SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY);
-#endif
subseg_set (cfi_seg, 0);
- record_alignment (cfi_seg, 2);
+ record_alignment (cfi_seg, EH_FRAME_ALIGNMENT);
/* Make sure check_eh_frame doesn't do anything with our output. */
save_flag_traditional_format = flag_traditional_format;
struct cie_entry *cie;
cie = select_cie_for_fde (fde, &first);
- output_fde (fde, cie, first);
+ output_fde (fde, cie, first, fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
}
flag_traditional_format = save_flag_traditional_format;