/* dw2gencfi.c - Support for generating Dwarf2 CFI information.
- Copyright 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Free Software Foundation, Inc.
Contributed by Michal Ludvig <mludvig@suse.cz>
This file is part of GAS, the GNU Assembler.
#ifdef TARGET_USE_CFIPOP
+/* By default, use difference expressions if DIFF_EXPR_OK is defined. */
+#ifndef CFI_DIFF_EXPR_OK
+# ifdef DIFF_EXPR_OK
+# define CFI_DIFF_EXPR_OK 1
+# else
+# define CFI_DIFF_EXPR_OK 0
+# endif
+#endif
+
/* 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
# define DWARF2_LINE_MIN_INSN_LENGTH 1
#endif
+/* By default, use 32-bit relocations from .eh_frame into .text. */
+#ifndef DWARF2_FDE_RELOC_SIZE
+# define DWARF2_FDE_RELOC_SIZE 4
+#endif
+
+/* By default, use a read-only .eh_frame section. */
+#ifndef DWARF2_EH_FRAME_READ_ONLY
+# define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY
+#endif
+
#ifndef EH_FRAME_ALIGNMENT
# define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
#endif
# define tc_cfi_frame_initial_instructions() ((void)0)
#endif
+#ifndef DWARF2_ADDR_SIZE
+# define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
+#endif
+
struct cfi_insn_data
{
struct cfi_escape_data *next;
expressionS exp;
} *esc;
+
+ struct {
+ unsigned reg, encoding;
+ expressionS exp;
+ } ea;
} u;
};
static void dot_cfi_endproc (int);
static void dot_cfi_personality (int);
static void dot_cfi_lsda (int);
+static void dot_cfi_val_encoded_addr (int);
/* Fake CFI type; outside the byte range of any real CFI insn. */
#define CFI_adjust_cfa_offset 0x100
#define CFI_rel_offset 0x102
#define CFI_escape 0x103
#define CFI_signal_frame 0x104
+#define CFI_val_encoded_addr 0x105
const pseudo_typeS cfi_pseudo_table[] =
{
{ "cfi_signal_frame", dot_cfi, CFI_signal_frame },
{ "cfi_personality", dot_cfi_personality, 0 },
{ "cfi_lsda", dot_cfi_lsda, 0 },
+ { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr, 0 },
{ NULL, NULL, 0 }
};
}
fde = frchain_now->frch_cfi_data->cur_fde_data;
- encoding = get_absolute_expression ();
+ encoding = cfi_parse_const ();
if (encoding == DW_EH_PE_omit)
{
demand_empty_rest_of_line ();
if ((encoding & 0xff) != encoding
|| ((encoding & 0x70) != 0
-#if defined DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
+#if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
&& (encoding & 0x70) != DW_EH_PE_pcrel
#endif
)
}
fde = frchain_now->frch_cfi_data->cur_fde_data;
- encoding = get_absolute_expression ();
+ encoding = cfi_parse_const ();
if (encoding == DW_EH_PE_omit)
{
demand_empty_rest_of_line ();
if ((encoding & 0xff) != encoding
|| ((encoding & 0x70) != 0
-#if defined DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
+#if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
&& (encoding & 0x70) != DW_EH_PE_pcrel
#endif
)
demand_empty_rest_of_line ();
}
+static void
+dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED)
+{
+ struct cfi_insn_data *insn_ptr;
+ offsetT encoding;
+
+ if (frchain_now->frch_cfi_data == NULL)
+ {
+ as_bad (_("CFI instruction used without previous .cfi_startproc"));
+ ignore_rest_of_line ();
+ return;
+ }
+
+ /* If the last address was not at the current PC, advance to current. */
+ if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
+ || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
+ != frag_now_fix ())
+ cfi_add_advance_loc (symbol_temp_new_now ());
+
+ insn_ptr = alloc_cfi_insn_data ();
+ insn_ptr->insn = CFI_val_encoded_addr;
+
+ insn_ptr->u.ea.reg = cfi_parse_reg ();
+
+ cfi_parse_separator ();
+ encoding = cfi_parse_const ();
+ if ((encoding & 0xff) != encoding
+ || ((encoding & 0x70) != 0
+#if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
+ && (encoding & 0x70) != DW_EH_PE_pcrel
+#endif
+ )
+ /* leb128 can be handled, but does something actually need it? */
+ || (encoding & 7) == DW_EH_PE_uleb128
+ || (encoding & 7) > DW_EH_PE_udata8)
+ {
+ as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
+ encoding = DW_EH_PE_omit;
+ }
+
+ cfi_parse_separator ();
+ expression_and_evaluate (&insn_ptr->u.ea.exp);
+ switch (insn_ptr->u.ea.exp.X_op)
+ {
+ case O_symbol:
+ break;
+ case O_constant:
+ if ((encoding & 0x70) != DW_EH_PE_pcrel)
+ break;
+ default:
+ encoding = DW_EH_PE_omit;
+ break;
+ }
+
+ insn_ptr->u.ea.encoding = encoding;
+ if (encoding == DW_EH_PE_omit)
+ {
+ as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
+ ignore_rest_of_line ();
+ return;
+ }
+
+ demand_empty_rest_of_line ();
+}
+
static void
dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
{
if (scaled <= 0x3F)
out_one (DW_CFA_advance_loc + scaled);
- else if (delta <= 0xFF)
+ else if (scaled <= 0xFF)
{
out_one (DW_CFA_advance_loc1);
- out_one (delta);
+ out_one (scaled);
}
- else if (delta <= 0xFFFF)
+ else if (scaled <= 0xFFFF)
{
out_one (DW_CFA_advance_loc2);
- out_two (delta);
+ out_two (scaled);
}
else
{
out_one (DW_CFA_advance_loc4);
- out_four (delta);
+ out_four (scaled);
}
}
else
is already allocated to the frag. This comes from the way
that it scans the .eh_frame section looking first for the
.byte DW_CFA_advance_loc4. */
- frag_more (1);
+ *frag_more (1) = DW_CFA_advance_loc4;
frag_var (rs_cfa, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH << 3,
make_expr_symbol (&exp), frag_now_fix () - 1,
break;
}
+ case CFI_val_encoded_addr:
+ {
+ unsigned encoding = insn->u.ea.encoding;
+ offsetT encoding_size;
+
+ if (encoding == DW_EH_PE_omit)
+ break;
+ out_one (DW_CFA_val_expression);
+ out_uleb128 (insn->u.ea.reg);
+
+ switch (encoding & 0x7)
+ {
+ case DW_EH_PE_absptr:
+ encoding_size = DWARF2_ADDR_SIZE (stdoutput);
+ break;
+ case DW_EH_PE_udata2:
+ encoding_size = 2;
+ break;
+ case DW_EH_PE_udata4:
+ encoding_size = 4;
+ break;
+ case DW_EH_PE_udata8:
+ encoding_size = 8;
+ break;
+ default:
+ abort ();
+ }
+
+ /* If the user has requested absolute encoding,
+ then use the smaller DW_OP_addr encoding. */
+ if (insn->u.ea.encoding == DW_EH_PE_absptr)
+ {
+ out_uleb128 (1 + encoding_size);
+ out_one (DW_OP_addr);
+ }
+ else
+ {
+ out_uleb128 (1 + 1 + encoding_size);
+ out_one (DW_OP_GNU_encoded_addr);
+ out_one (encoding);
+
+ if ((encoding & 0x70) == DW_EH_PE_pcrel)
+ {
+#if CFI_DIFF_EXPR_OK
+ insn->u.ea.exp.X_op = O_subtract;
+ insn->u.ea.exp.X_op_symbol = symbol_temp_new_now ();
+#elif defined (tc_cfi_emit_pcrel_expr)
+ tc_cfi_emit_pcrel_expr (&insn->u.ea.exp, encoding_size);
+ break;
+#else
+ abort ();
+#endif
+ }
+ }
+ emit_expr (&insn->u.ea.exp, encoding_size);
+ }
+ break;
+
default:
abort ();
}
expressionS exp;
struct cfi_insn_data *i;
offsetT augmentation_size;
+ int enc;
cie->start_address = symbol_temp_new_now ();
after_size_address = symbol_temp_make ();
exp = cie->personality;
if ((cie->per_encoding & 0x70) == DW_EH_PE_pcrel)
{
-#ifdef DIFF_EXPR_OK
+#if CFI_DIFF_EXPR_OK
exp.X_op = O_subtract;
exp.X_op_symbol = symbol_temp_new_now ();
emit_expr (&exp, size);
}
if (cie->lsda_encoding != DW_EH_PE_omit)
out_one (cie->lsda_encoding);
-#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);
+
+ switch (DWARF2_FDE_RELOC_SIZE)
+ {
+ case 2:
+ enc = DW_EH_PE_sdata2;
+ break;
+ case 4:
+ enc = DW_EH_PE_sdata4;
+ break;
+ case 8:
+ enc = DW_EH_PE_sdata8;
+ break;
+ default:
+ abort ();
+ }
+#if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
+ enc |= DW_EH_PE_pcrel;
#endif
+ out_one (enc);
if (cie->first)
for (i = cie->first; i != cie->last; i = i->next)
exp.X_op_symbol = cie->start_address;
emit_expr (&exp, 4); /* CIE offset. */
-#ifdef DIFF_EXPR_OK
+#if CFI_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, DWARF2_FDE_RELOC_SIZE); /* 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. */
+ tc_cfi_emit_pcrel_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
#else
- emit_expr (&exp, 4); /* Code offset. */
+ emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* 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. */
- emit_expr (&exp, 4);
+ emit_expr (&exp, DWARF2_FDE_RELOC_SIZE);
augmentation_size = encoding_size (fde->lsda_encoding);
out_uleb128 (augmentation_size); /* Augmentation size. */
exp = fde->lsda;
if ((fde->lsda_encoding & 0x70) == DW_EH_PE_pcrel)
{
-#ifdef DIFF_EXPR_OK
+#if CFI_DIFF_EXPR_OK
exp.X_op = O_subtract;
exp.X_op_symbol = symbol_temp_new_now ();
emit_expr (&exp, augmentation_size);
break;
case CFI_escape:
+ case CFI_val_encoded_addr:
/* Don't bother matching these for now. */
goto fail;
&& (!j
|| j->insn == DW_CFA_advance_loc
|| j->insn == DW_CFA_remember_state
- || j->insn == CFI_escape))
+ || j->insn == CFI_escape
+ || j->insn == CFI_val_encoded_addr))
{
*pfirst = j;
return cie;
for (i = cie->first; i ; i = i->next)
if (i->insn == DW_CFA_advance_loc
|| i->insn == DW_CFA_remember_state
- || i->insn == CFI_escape)
+ || i->insn == CFI_escape
+ || i->insn == CFI_val_encoded_addr)
break;
cie->last = i;
/* Open .eh_frame section. */
cfi_seg = subseg_new (".eh_frame", 0);
bfd_set_section_flags (stdoutput, cfi_seg,
- SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY);
+ SEC_ALLOC | SEC_LOAD | SEC_DATA
+ | DWARF2_EH_FRAME_READ_ONLY);
subseg_set (cfi_seg, 0);
record_alignment (cfi_seg, EH_FRAME_ALIGNMENT);
+#ifdef md_fix_up_eh_frame
+ md_fix_up_eh_frame (cfi_seg);
+#endif
+
/* Make sure check_eh_frame doesn't do anything with our output. */
save_flag_traditional_format = flag_traditional_format;
flag_traditional_format = 1;