1 /* dw2gencfi.c - Support for generating Dwarf2 CFI information.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Michal Ludvig <mludvig@suse.cz>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "dw2gencfi.h"
25 #include "dwarf2dbg.h"
27 #ifdef TARGET_USE_CFIPOP
29 /* By default, use difference expressions if DIFF_EXPR_OK is defined. */
30 #ifndef CFI_DIFF_EXPR_OK
32 # define CFI_DIFF_EXPR_OK 1
34 # define CFI_DIFF_EXPR_OK 0
38 #ifndef CFI_DIFF_LSDA_OK
39 #define CFI_DIFF_LSDA_OK CFI_DIFF_EXPR_OK
42 #if CFI_DIFF_EXPR_OK == 1 && CFI_DIFF_LSDA_OK == 0
43 # error "CFI_DIFF_EXPR_OK should imply CFI_DIFF_LSDA_OK"
46 /* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field
47 of the CIE. Default to 1 if not otherwise specified. */
48 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
49 #define DWARF2_LINE_MIN_INSN_LENGTH 1
52 /* By default, use 32-bit relocations from .eh_frame into .text. */
53 #ifndef DWARF2_FDE_RELOC_SIZE
54 #define DWARF2_FDE_RELOC_SIZE 4
57 /* By default, use a read-only .eh_frame section. */
58 #ifndef DWARF2_EH_FRAME_READ_ONLY
59 #define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY
62 #ifndef EH_FRAME_ALIGNMENT
63 #define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
66 #ifndef tc_cfi_frame_initial_instructions
67 #define tc_cfi_frame_initial_instructions() ((void)0)
70 #ifndef tc_cfi_startproc
71 # define tc_cfi_startproc() ((void)0)
74 #ifndef tc_cfi_endproc
75 # define tc_cfi_endproc(fde) ((void) (fde))
78 #define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh)
81 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
84 #ifndef DWARF2_ADDR_SIZE
85 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
88 #if MULTIPLE_FRAME_SECTIONS
89 #define CUR_SEG(structp) structp->cur_seg
90 #define SET_CUR_SEG(structp, seg) structp->cur_seg = seg
91 #define HANDLED(structp) structp->handled
92 #define SET_HANDLED(structp, val) structp->handled = val
94 #define CUR_SEG(structp) NULL
95 #define SET_CUR_SEG(structp, seg) (void) (0 && seg)
96 #define HANDLED(structp) 0
97 #define SET_HANDLED(structp, val) (void) (0 && val)
100 #ifndef tc_cfi_reloc_for_encoding
101 #define tc_cfi_reloc_for_encoding(e) BFD_RELOC_NONE
104 /* Private segment collection list. */
105 struct dwcfi_seg_list
112 #ifdef SUPPORT_COMPACT_EH
113 static bfd_boolean compact_eh
;
118 static struct hash_control
*dwcfi_hash
;
120 /* Emit a single byte into the current segment. */
125 FRAG_APPEND_1_CHAR (byte
);
128 /* Emit a two-byte word into the current segment. */
133 md_number_to_chars (frag_more (2), data
, 2);
136 /* Emit a four byte word into the current segment. */
141 md_number_to_chars (frag_more (4), data
, 4);
144 /* Emit an unsigned "little-endian base 128" number. */
147 out_uleb128 (addressT value
)
149 output_leb128 (frag_more (sizeof_leb128 (value
, 0)), value
, 0);
152 /* Emit an unsigned "little-endian base 128" number. */
155 out_sleb128 (offsetT value
)
157 output_leb128 (frag_more (sizeof_leb128 (value
, 1)), value
, 1);
161 encoding_size (unsigned char encoding
)
163 if (encoding
== DW_EH_PE_omit
)
165 switch (encoding
& 0x7)
168 return bfd_get_arch_size (stdoutput
) == 64 ? 8 : 4;
169 case DW_EH_PE_udata2
:
171 case DW_EH_PE_udata4
:
173 case DW_EH_PE_udata8
:
180 /* Emit expression EXP in ENCODING. If EMIT_ENCODING is true, first
181 emit a byte containing ENCODING. */
184 emit_expr_encoded (expressionS
*exp
, int encoding
, bfd_boolean emit_encoding
)
186 offsetT size
= encoding_size (encoding
);
187 bfd_reloc_code_real_type code
;
189 if (encoding
== DW_EH_PE_omit
)
195 code
= tc_cfi_reloc_for_encoding (encoding
);
196 if (code
!= BFD_RELOC_NONE
)
198 reloc_howto_type
*howto
= bfd_reloc_type_lookup (stdoutput
, code
);
199 char *p
= frag_more (size
);
200 md_number_to_chars (p
, 0, size
);
201 fix_new (frag_now
, p
- frag_now
->fr_literal
, size
, exp
->X_add_symbol
,
202 exp
->X_add_number
, howto
->pc_relative
, code
);
204 else if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
207 expressionS tmp
= *exp
;
208 tmp
.X_op
= O_subtract
;
209 tmp
.X_op_symbol
= symbol_temp_new_now ();
210 emit_expr (&tmp
, size
);
211 #elif defined (tc_cfi_emit_pcrel_expr)
212 tc_cfi_emit_pcrel_expr (exp
, size
);
218 emit_expr (exp
, size
);
221 /* Build based on segment the derived .debug_...
222 segment name containing origin segment's postfix name part. */
225 get_debugseg_name (segT seg
, const char *base_name
)
236 name
= bfd_get_section_name (stdoutput
, seg
);
238 dollar
= strchr (name
, '$');
239 dot
= strchr (name
+ 1, '.');
243 if (!strcmp (base_name
, ".eh_frame_entry")
244 && strcmp (name
, ".text") != 0)
245 return concat (base_name
, ".", name
, NULL
);
253 else if (dot
< dollar
)
259 return concat (base_name
, name
, NULL
);
262 /* Allocate a dwcfi_seg_list structure. */
264 static struct dwcfi_seg_list
*
265 alloc_debugseg_item (segT seg
, int subseg
, char *name
)
267 struct dwcfi_seg_list
*r
;
269 r
= (struct dwcfi_seg_list
*)
270 xmalloc (sizeof (struct dwcfi_seg_list
) + strlen (name
));
278 is_now_linkonce_segment (void)
283 if ((bfd_get_section_flags (stdoutput
, now_seg
)
284 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
285 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
286 | SEC_LINK_DUPLICATES_SAME_CONTENTS
)) != 0)
291 /* Generate debug... segment with same linkonce properties
295 make_debug_seg (segT cseg
, char *name
, int sflags
)
297 segT save_seg
= now_seg
;
298 int save_subseg
= now_subseg
;
302 r
= subseg_new (name
, 0);
304 /* Check if code segment is marked as linked once. */
308 flags
= bfd_get_section_flags (stdoutput
, cseg
)
309 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
310 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
311 | SEC_LINK_DUPLICATES_SAME_CONTENTS
);
313 /* Add standard section flags. */
316 /* Apply possibly linked once flags to new generated segment, too. */
317 if (!bfd_set_section_flags (stdoutput
, r
, flags
))
318 as_bad (_("bfd_set_section_flags: %s"),
319 bfd_errmsg (bfd_get_error ()));
321 /* Restore to previous segment. */
322 if (save_seg
!= NULL
)
323 subseg_set (save_seg
, save_subseg
);
328 dwcfi_hash_insert (const char *name
, struct dwcfi_seg_list
*item
)
330 const char *error_string
;
332 if ((error_string
= hash_jam (dwcfi_hash
, name
, (char *) item
)))
333 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
337 static struct dwcfi_seg_list
*
338 dwcfi_hash_find (char *name
)
340 return (struct dwcfi_seg_list
*) hash_find (dwcfi_hash
, name
);
343 static struct dwcfi_seg_list
*
344 dwcfi_hash_find_or_make (segT cseg
, const char *base_name
, int flags
)
346 struct dwcfi_seg_list
*item
;
349 /* Initialize dwcfi_hash once. */
351 dwcfi_hash
= hash_new ();
353 name
= get_debugseg_name (cseg
, base_name
);
355 item
= dwcfi_hash_find (name
);
358 item
= alloc_debugseg_item (make_debug_seg (cseg
, name
, flags
), 0, name
);
360 dwcfi_hash_insert (item
->seg_name
, item
);
368 /* ??? Share this with dwarf2cfg.c. */
369 #ifndef TC_DWARF2_EMIT_OFFSET
370 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
372 /* Create an offset to .dwarf2_*. */
375 generic_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
380 exp
.X_add_symbol
= symbol
;
381 exp
.X_add_number
= 0;
382 emit_expr (&exp
, size
);
386 struct cfi_escape_data
388 struct cfi_escape_data
*next
;
394 struct cie_entry
*next
;
395 #if MULTIPLE_FRAME_SECTIONS
398 symbolS
*start_address
;
399 unsigned int return_column
;
400 unsigned int signal_frame
;
401 unsigned char fde_encoding
;
402 unsigned char per_encoding
;
403 unsigned char lsda_encoding
;
404 expressionS personality
;
405 struct cfi_insn_data
*first
, *last
;
408 /* List of FDE entries. */
410 struct fde_entry
*all_fde_data
;
411 static struct fde_entry
**last_fde_data
= &all_fde_data
;
413 /* List of CIEs so that they could be reused. */
414 static struct cie_entry
*cie_root
;
416 /* Stack of old CFI data, for save/restore. */
419 struct cfa_save_data
*next
;
423 /* Current open FDE entry. */
426 struct fde_entry
*cur_fde_data
;
427 symbolS
*last_address
;
428 offsetT cur_cfa_offset
;
429 struct cfa_save_data
*cfa_save_stack
;
432 /* Construct a new FDE structure and add it to the end of the fde list. */
434 static struct fde_entry
*
435 alloc_fde_entry (void)
437 struct fde_entry
*fde
= (struct fde_entry
*)
438 xcalloc (1, sizeof (struct fde_entry
));
440 frchain_now
->frch_cfi_data
= (struct frch_cfi_data
*)
441 xcalloc (1, sizeof (struct frch_cfi_data
));
442 frchain_now
->frch_cfi_data
->cur_fde_data
= fde
;
443 *last_fde_data
= fde
;
444 last_fde_data
= &fde
->next
;
445 SET_CUR_SEG (fde
, is_now_linkonce_segment ());
446 SET_HANDLED (fde
, 0);
447 fde
->last
= &fde
->data
;
448 fde
->return_column
= DWARF2_DEFAULT_RETURN_COLUMN
;
449 fde
->per_encoding
= DW_EH_PE_omit
;
450 fde
->lsda_encoding
= DW_EH_PE_omit
;
451 fde
->eh_header_type
= EH_COMPACT_UNKNOWN
;
456 /* The following functions are available for a backend to construct its
457 own unwind information, usually from legacy unwind directives. */
459 /* Construct a new INSN structure and add it to the end of the insn list
460 for the currently active FDE. */
462 static bfd_boolean cfi_sections_set
= FALSE
;
463 static int cfi_sections
= CFI_EMIT_eh_frame
;
464 int all_cfi_sections
= 0;
465 static struct fde_entry
*last_fde
;
467 static struct cfi_insn_data
*
468 alloc_cfi_insn_data (void)
470 struct cfi_insn_data
*insn
= (struct cfi_insn_data
*)
471 xcalloc (1, sizeof (struct cfi_insn_data
));
472 struct fde_entry
*cur_fde_data
= frchain_now
->frch_cfi_data
->cur_fde_data
;
474 *cur_fde_data
->last
= insn
;
475 cur_fde_data
->last
= &insn
->next
;
476 SET_CUR_SEG (insn
, is_now_linkonce_segment ());
480 /* Construct a new FDE structure that begins at LABEL. */
483 cfi_new_fde (symbolS
*label
)
485 struct fde_entry
*fde
= alloc_fde_entry ();
486 fde
->start_address
= label
;
487 frchain_now
->frch_cfi_data
->last_address
= label
;
490 /* End the currently open FDE. */
493 cfi_end_fde (symbolS
*label
)
495 frchain_now
->frch_cfi_data
->cur_fde_data
->end_address
= label
;
496 free (frchain_now
->frch_cfi_data
);
497 frchain_now
->frch_cfi_data
= NULL
;
500 /* Set the return column for the current FDE. */
503 cfi_set_return_column (unsigned regno
)
505 frchain_now
->frch_cfi_data
->cur_fde_data
->return_column
= regno
;
509 cfi_set_sections (void)
511 frchain_now
->frch_cfi_data
->cur_fde_data
->sections
= all_cfi_sections
;
514 /* Universal functions to store new instructions. */
517 cfi_add_CFA_insn (int insn
)
519 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
521 insn_ptr
->insn
= insn
;
525 cfi_add_CFA_insn_reg (int insn
, unsigned regno
)
527 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
529 insn_ptr
->insn
= insn
;
530 insn_ptr
->u
.r
= regno
;
534 cfi_add_CFA_insn_offset (int insn
, offsetT offset
)
536 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
538 insn_ptr
->insn
= insn
;
539 insn_ptr
->u
.i
= offset
;
543 cfi_add_CFA_insn_reg_reg (int insn
, unsigned reg1
, unsigned reg2
)
545 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
547 insn_ptr
->insn
= insn
;
548 insn_ptr
->u
.rr
.reg1
= reg1
;
549 insn_ptr
->u
.rr
.reg2
= reg2
;
553 cfi_add_CFA_insn_reg_offset (int insn
, unsigned regno
, offsetT offset
)
555 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
557 insn_ptr
->insn
= insn
;
558 insn_ptr
->u
.ri
.reg
= regno
;
559 insn_ptr
->u
.ri
.offset
= offset
;
562 /* Add a CFI insn to advance the PC from the last address to LABEL. */
565 cfi_add_advance_loc (symbolS
*label
)
567 struct cfi_insn_data
*insn
= alloc_cfi_insn_data ();
569 insn
->insn
= DW_CFA_advance_loc
;
570 insn
->u
.ll
.lab1
= frchain_now
->frch_cfi_data
->last_address
;
571 insn
->u
.ll
.lab2
= label
;
573 frchain_now
->frch_cfi_data
->last_address
= label
;
576 /* Add a CFI insn to label the current position in the CFI segment. */
579 cfi_add_label (const char *name
)
581 unsigned int len
= strlen (name
) + 1;
582 struct cfi_insn_data
*insn
= alloc_cfi_insn_data ();
584 insn
->insn
= CFI_label
;
585 obstack_grow (¬es
, name
, len
);
586 insn
->u
.sym_name
= (char *) obstack_finish (¬es
);
589 /* Add a DW_CFA_offset record to the CFI data. */
592 cfi_add_CFA_offset (unsigned regno
, offsetT offset
)
594 unsigned int abs_data_align
;
596 gas_assert (DWARF2_CIE_DATA_ALIGNMENT
!= 0);
597 cfi_add_CFA_insn_reg_offset (DW_CFA_offset
, regno
, offset
);
599 abs_data_align
= (DWARF2_CIE_DATA_ALIGNMENT
< 0
600 ? -DWARF2_CIE_DATA_ALIGNMENT
: DWARF2_CIE_DATA_ALIGNMENT
);
601 if (offset
% abs_data_align
)
602 as_bad (_("register save offset not a multiple of %u"), abs_data_align
);
605 /* Add a DW_CFA_def_cfa record to the CFI data. */
608 cfi_add_CFA_def_cfa (unsigned regno
, offsetT offset
)
610 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa
, regno
, offset
);
611 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
614 /* Add a DW_CFA_register record to the CFI data. */
617 cfi_add_CFA_register (unsigned reg1
, unsigned reg2
)
619 cfi_add_CFA_insn_reg_reg (DW_CFA_register
, reg1
, reg2
);
622 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
625 cfi_add_CFA_def_cfa_register (unsigned regno
)
627 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register
, regno
);
630 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
633 cfi_add_CFA_def_cfa_offset (offsetT offset
)
635 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset
, offset
);
636 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
640 cfi_add_CFA_restore (unsigned regno
)
642 cfi_add_CFA_insn_reg (DW_CFA_restore
, regno
);
646 cfi_add_CFA_undefined (unsigned regno
)
648 cfi_add_CFA_insn_reg (DW_CFA_undefined
, regno
);
652 cfi_add_CFA_same_value (unsigned regno
)
654 cfi_add_CFA_insn_reg (DW_CFA_same_value
, regno
);
658 cfi_add_CFA_remember_state (void)
660 struct cfa_save_data
*p
;
662 cfi_add_CFA_insn (DW_CFA_remember_state
);
664 p
= (struct cfa_save_data
*) xmalloc (sizeof (*p
));
665 p
->cfa_offset
= frchain_now
->frch_cfi_data
->cur_cfa_offset
;
666 p
->next
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
667 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
;
671 cfi_add_CFA_restore_state (void)
673 struct cfa_save_data
*p
;
675 cfi_add_CFA_insn (DW_CFA_restore_state
);
677 p
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
680 frchain_now
->frch_cfi_data
->cur_cfa_offset
= p
->cfa_offset
;
681 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
->next
;
685 as_bad (_("CFI state restore without previous remember"));
689 /* Parse CFI assembler directives. */
691 static void dot_cfi (int);
692 static void dot_cfi_escape (int);
693 static void dot_cfi_sections (int);
694 static void dot_cfi_startproc (int);
695 static void dot_cfi_endproc (int);
696 static void dot_cfi_fde_data (int);
697 static void dot_cfi_personality (int);
698 static void dot_cfi_personality_id (int);
699 static void dot_cfi_lsda (int);
700 static void dot_cfi_val_encoded_addr (int);
701 static void dot_cfi_inline_lsda (int);
702 static void dot_cfi_label (int);
704 const pseudo_typeS cfi_pseudo_table
[] =
706 { "cfi_sections", dot_cfi_sections
, 0 },
707 { "cfi_startproc", dot_cfi_startproc
, 0 },
708 { "cfi_endproc", dot_cfi_endproc
, 0 },
709 { "cfi_fde_data", dot_cfi_fde_data
, 0 },
710 { "cfi_def_cfa", dot_cfi
, DW_CFA_def_cfa
},
711 { "cfi_def_cfa_register", dot_cfi
, DW_CFA_def_cfa_register
},
712 { "cfi_def_cfa_offset", dot_cfi
, DW_CFA_def_cfa_offset
},
713 { "cfi_adjust_cfa_offset", dot_cfi
, CFI_adjust_cfa_offset
},
714 { "cfi_offset", dot_cfi
, DW_CFA_offset
},
715 { "cfi_rel_offset", dot_cfi
, CFI_rel_offset
},
716 { "cfi_register", dot_cfi
, DW_CFA_register
},
717 { "cfi_return_column", dot_cfi
, CFI_return_column
},
718 { "cfi_restore", dot_cfi
, DW_CFA_restore
},
719 { "cfi_undefined", dot_cfi
, DW_CFA_undefined
},
720 { "cfi_same_value", dot_cfi
, DW_CFA_same_value
},
721 { "cfi_remember_state", dot_cfi
, DW_CFA_remember_state
},
722 { "cfi_restore_state", dot_cfi
, DW_CFA_restore_state
},
723 { "cfi_window_save", dot_cfi
, DW_CFA_GNU_window_save
},
724 { "cfi_escape", dot_cfi_escape
, 0 },
725 { "cfi_signal_frame", dot_cfi
, CFI_signal_frame
},
726 { "cfi_personality", dot_cfi_personality
, 0 },
727 { "cfi_personality_id", dot_cfi_personality_id
, 0 },
728 { "cfi_lsda", dot_cfi_lsda
, 0 },
729 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr
, 0 },
730 { "cfi_inline_lsda", dot_cfi_inline_lsda
, 0 },
731 { "cfi_label", dot_cfi_label
, 0 },
736 cfi_parse_separator (void)
739 if (*input_line_pointer
== ',')
740 input_line_pointer
++;
742 as_bad (_("missing separator"));
745 #ifndef tc_parse_to_dw2regnum
747 tc_parse_to_dw2regnum (expressionS
*exp
)
749 # ifdef tc_regname_to_dw2regnum
751 if (is_name_beginner (*input_line_pointer
)
752 || (*input_line_pointer
== '%'
753 && is_name_beginner (*++input_line_pointer
)))
757 c
= get_symbol_name (& name
);
759 exp
->X_op
= O_constant
;
760 exp
->X_add_number
= tc_regname_to_dw2regnum (name
);
762 restore_line_pointer (c
);
766 expression_and_evaluate (exp
);
776 tc_parse_to_dw2regnum (&exp
);
781 regno
= exp
.X_add_number
;
791 as_bad (_("bad register expression"));
799 cfi_parse_const (void)
801 return get_absolute_expression ();
810 if (frchain_now
->frch_cfi_data
== NULL
)
812 as_bad (_("CFI instruction used without previous .cfi_startproc"));
813 ignore_rest_of_line ();
817 /* If the last address was not at the current PC, advance to current. */
818 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
819 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
821 cfi_add_advance_loc (symbol_temp_new_now ());
826 reg1
= cfi_parse_reg ();
827 cfi_parse_separator ();
828 offset
= cfi_parse_const ();
829 cfi_add_CFA_offset (reg1
, offset
);
833 reg1
= cfi_parse_reg ();
834 cfi_parse_separator ();
835 offset
= cfi_parse_const ();
836 cfi_add_CFA_offset (reg1
,
837 offset
- frchain_now
->frch_cfi_data
->cur_cfa_offset
);
841 reg1
= cfi_parse_reg ();
842 cfi_parse_separator ();
843 offset
= cfi_parse_const ();
844 cfi_add_CFA_def_cfa (reg1
, offset
);
847 case DW_CFA_register
:
848 reg1
= cfi_parse_reg ();
849 cfi_parse_separator ();
850 reg2
= cfi_parse_reg ();
851 cfi_add_CFA_register (reg1
, reg2
);
854 case DW_CFA_def_cfa_register
:
855 reg1
= cfi_parse_reg ();
856 cfi_add_CFA_def_cfa_register (reg1
);
859 case DW_CFA_def_cfa_offset
:
860 offset
= cfi_parse_const ();
861 cfi_add_CFA_def_cfa_offset (offset
);
864 case CFI_adjust_cfa_offset
:
865 offset
= cfi_parse_const ();
866 cfi_add_CFA_def_cfa_offset (frchain_now
->frch_cfi_data
->cur_cfa_offset
873 reg1
= cfi_parse_reg ();
874 cfi_add_CFA_restore (reg1
);
876 if (*input_line_pointer
!= ',')
878 ++input_line_pointer
;
882 case DW_CFA_undefined
:
885 reg1
= cfi_parse_reg ();
886 cfi_add_CFA_undefined (reg1
);
888 if (*input_line_pointer
!= ',')
890 ++input_line_pointer
;
894 case DW_CFA_same_value
:
895 reg1
= cfi_parse_reg ();
896 cfi_add_CFA_same_value (reg1
);
899 case CFI_return_column
:
900 reg1
= cfi_parse_reg ();
901 cfi_set_return_column (reg1
);
904 case DW_CFA_remember_state
:
905 cfi_add_CFA_remember_state ();
908 case DW_CFA_restore_state
:
909 cfi_add_CFA_restore_state ();
912 case DW_CFA_GNU_window_save
:
913 cfi_add_CFA_insn (DW_CFA_GNU_window_save
);
916 case CFI_signal_frame
:
917 frchain_now
->frch_cfi_data
->cur_fde_data
->signal_frame
= 1;
924 demand_empty_rest_of_line ();
928 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED
)
930 struct cfi_escape_data
*head
, **tail
, *e
;
931 struct cfi_insn_data
*insn
;
933 if (frchain_now
->frch_cfi_data
== NULL
)
935 as_bad (_("CFI instruction used without previous .cfi_startproc"));
936 ignore_rest_of_line ();
940 /* If the last address was not at the current PC, advance to current. */
941 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
942 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
944 cfi_add_advance_loc (symbol_temp_new_now ());
949 e
= (struct cfi_escape_data
*) xmalloc (sizeof (*e
));
950 do_parse_cons_expression (&e
->exp
, 1);
954 while (*input_line_pointer
++ == ',');
957 insn
= alloc_cfi_insn_data ();
958 insn
->insn
= CFI_escape
;
961 --input_line_pointer
;
962 demand_empty_rest_of_line ();
966 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED
)
968 struct fde_entry
*fde
;
971 if (frchain_now
->frch_cfi_data
== NULL
)
973 as_bad (_("CFI instruction used without previous .cfi_startproc"));
974 ignore_rest_of_line ();
978 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
979 encoding
= cfi_parse_const ();
980 if (encoding
== DW_EH_PE_omit
)
982 demand_empty_rest_of_line ();
983 fde
->per_encoding
= encoding
;
987 if ((encoding
& 0xff) != encoding
988 || ((((encoding
& 0x70) != 0
989 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
990 && (encoding
& 0x70) != DW_EH_PE_pcrel
993 /* leb128 can be handled, but does something actually need it? */
994 || (encoding
& 7) == DW_EH_PE_uleb128
995 || (encoding
& 7) > DW_EH_PE_udata8
)
996 && tc_cfi_reloc_for_encoding (encoding
) == BFD_RELOC_NONE
))
998 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
999 ignore_rest_of_line ();
1003 if (*input_line_pointer
++ != ',')
1005 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
1006 ignore_rest_of_line ();
1010 expression_and_evaluate (&fde
->personality
);
1011 switch (fde
->personality
.X_op
)
1016 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1017 encoding
= DW_EH_PE_omit
;
1020 encoding
= DW_EH_PE_omit
;
1024 fde
->per_encoding
= encoding
;
1026 if (encoding
== DW_EH_PE_omit
)
1028 as_bad (_("wrong second argument to .cfi_personality"));
1029 ignore_rest_of_line ();
1033 demand_empty_rest_of_line ();
1037 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED
)
1039 struct fde_entry
*fde
;
1042 if (frchain_now
->frch_cfi_data
== NULL
)
1044 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1045 ignore_rest_of_line ();
1049 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1050 encoding
= cfi_parse_const ();
1051 if (encoding
== DW_EH_PE_omit
)
1053 demand_empty_rest_of_line ();
1054 fde
->lsda_encoding
= encoding
;
1058 if ((encoding
& 0xff) != encoding
1059 || ((((encoding
& 0x70) != 0
1060 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
1061 && (encoding
& 0x70) != DW_EH_PE_pcrel
1064 /* leb128 can be handled, but does something actually need it? */
1065 || (encoding
& 7) == DW_EH_PE_uleb128
1066 || (encoding
& 7) > DW_EH_PE_udata8
)
1067 && tc_cfi_reloc_for_encoding (encoding
) == BFD_RELOC_NONE
))
1069 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1070 ignore_rest_of_line ();
1074 if (*input_line_pointer
++ != ',')
1076 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
1077 ignore_rest_of_line ();
1081 fde
->lsda_encoding
= encoding
;
1083 expression_and_evaluate (&fde
->lsda
);
1084 switch (fde
->lsda
.X_op
)
1089 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1090 encoding
= DW_EH_PE_omit
;
1093 encoding
= DW_EH_PE_omit
;
1097 fde
->lsda_encoding
= encoding
;
1099 if (encoding
== DW_EH_PE_omit
)
1101 as_bad (_("wrong second argument to .cfi_lsda"));
1102 ignore_rest_of_line ();
1106 demand_empty_rest_of_line ();
1110 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED
)
1112 struct cfi_insn_data
*insn_ptr
;
1115 if (frchain_now
->frch_cfi_data
== NULL
)
1117 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1118 ignore_rest_of_line ();
1122 /* If the last address was not at the current PC, advance to current. */
1123 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
1124 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
1126 cfi_add_advance_loc (symbol_temp_new_now ());
1128 insn_ptr
= alloc_cfi_insn_data ();
1129 insn_ptr
->insn
= CFI_val_encoded_addr
;
1131 insn_ptr
->u
.ea
.reg
= cfi_parse_reg ();
1133 cfi_parse_separator ();
1134 encoding
= cfi_parse_const ();
1135 if ((encoding
& 0xff) != encoding
1136 || ((encoding
& 0x70) != 0
1137 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1138 && (encoding
& 0x70) != DW_EH_PE_pcrel
1141 /* leb128 can be handled, but does something actually need it? */
1142 || (encoding
& 7) == DW_EH_PE_uleb128
1143 || (encoding
& 7) > DW_EH_PE_udata8
)
1145 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1146 encoding
= DW_EH_PE_omit
;
1149 cfi_parse_separator ();
1150 expression_and_evaluate (&insn_ptr
->u
.ea
.exp
);
1151 switch (insn_ptr
->u
.ea
.exp
.X_op
)
1156 if ((encoding
& 0x70) != DW_EH_PE_pcrel
)
1159 encoding
= DW_EH_PE_omit
;
1163 insn_ptr
->u
.ea
.encoding
= encoding
;
1164 if (encoding
== DW_EH_PE_omit
)
1166 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1167 ignore_rest_of_line ();
1171 demand_empty_rest_of_line ();
1175 dot_cfi_label (int ignored ATTRIBUTE_UNUSED
)
1177 char *name
= read_symbol_name ();
1182 /* If the last address was not at the current PC, advance to current. */
1183 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
1184 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
1186 cfi_add_advance_loc (symbol_temp_new_now ());
1188 cfi_add_label (name
);
1190 demand_empty_rest_of_line ();
1194 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED
)
1199 if (is_name_beginner (*input_line_pointer
) || *input_line_pointer
== '"')
1205 saved_ilp
= input_line_pointer
;
1206 c
= get_symbol_name (& name
);
1208 if (strncmp (name
, ".eh_frame", sizeof ".eh_frame") == 0
1210 sections
|= CFI_EMIT_eh_frame
;
1211 else if (strncmp (name
, ".debug_frame", sizeof ".debug_frame") == 0)
1212 sections
|= CFI_EMIT_debug_frame
;
1213 #if SUPPORT_COMPACT_EH
1214 else if (strncmp (name
, ".eh_frame_entry", sizeof ".eh_frame_entry") == 0)
1217 sections
|= CFI_EMIT_eh_frame_compact
;
1220 #ifdef tc_cfi_section_name
1221 else if (strcmp (name
, tc_cfi_section_name
) == 0)
1222 sections
|= CFI_EMIT_target
;
1226 *input_line_pointer
= c
;
1227 input_line_pointer
= saved_ilp
;
1231 *input_line_pointer
= c
;
1232 SKIP_WHITESPACE_AFTER_NAME ();
1233 if (*input_line_pointer
== ',')
1235 name
= input_line_pointer
++;
1237 if (!is_name_beginner (*input_line_pointer
) && *input_line_pointer
!= '"')
1239 input_line_pointer
= name
;
1243 else if (is_name_beginner (*input_line_pointer
) || *input_line_pointer
== '"')
1247 demand_empty_rest_of_line ();
1248 if (cfi_sections_set
&& cfi_sections
!= sections
)
1249 as_bad (_("inconsistent uses of .cfi_sections"));
1250 cfi_sections_set
= TRUE
;
1251 cfi_sections
= sections
;
1255 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED
)
1259 if (frchain_now
->frch_cfi_data
!= NULL
)
1261 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1262 ignore_rest_of_line ();
1266 cfi_new_fde (symbol_temp_new_now ());
1269 if (is_name_beginner (*input_line_pointer
) || *input_line_pointer
== '"')
1271 char * saved_ilp
= input_line_pointer
;
1274 c
= get_symbol_name (& name
);
1276 if (strcmp (name
, "simple") == 0)
1279 restore_line_pointer (c
);
1282 input_line_pointer
= saved_ilp
;
1284 demand_empty_rest_of_line ();
1286 all_cfi_sections
|= cfi_sections
;
1287 cfi_set_sections ();
1288 frchain_now
->frch_cfi_data
->cur_cfa_offset
= 0;
1290 tc_cfi_frame_initial_instructions ();
1292 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1293 tc_cfi_startproc ();
1297 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED
)
1299 if (frchain_now
->frch_cfi_data
== NULL
)
1301 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1302 ignore_rest_of_line ();
1306 last_fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1308 cfi_end_fde (symbol_temp_new_now ());
1310 demand_empty_rest_of_line ();
1312 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1313 tc_cfi_endproc (last_fde
);
1317 get_cfi_seg (segT cseg
, const char *base
, flagword flags
, int align
)
1319 /* Exclude .debug_frame sections for Compact EH. */
1320 if (SUPPORT_FRAME_LINKONCE
|| ((flags
& SEC_DEBUGGING
) == 0 && compact_eh
))
1322 struct dwcfi_seg_list
*l
;
1324 l
= dwcfi_hash_find_or_make (cseg
, base
, flags
);
1327 subseg_set (cseg
, l
->subseg
);
1331 cseg
= subseg_new (base
, 0);
1332 bfd_set_section_flags (stdoutput
, cseg
, flags
);
1334 record_alignment (cseg
, align
);
1338 #if SUPPORT_COMPACT_EH
1340 dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED
)
1342 struct fde_entry
*fde
;
1344 if (frchain_now
->frch_cfi_data
== NULL
)
1346 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1347 ignore_rest_of_line ();
1351 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1352 fde
->personality_id
= cfi_parse_const ();
1353 demand_empty_rest_of_line ();
1355 if (fde
->personality_id
== 0 || fde
->personality_id
> 3)
1357 as_bad (_("wrong argument to .cfi_personality_id"));
1363 dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED
)
1365 if (frchain_now
->frch_cfi_data
== NULL
)
1367 as_bad (_(".cfi_fde_data without corresponding .cfi_startproc"));
1368 ignore_rest_of_line ();
1372 last_fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1374 if ((cfi_sections
& CFI_EMIT_target
) != 0
1375 || (cfi_sections
& CFI_EMIT_eh_frame_compact
) != 0)
1377 struct cfi_escape_data
*head
, **tail
, *e
;
1381 if (!is_it_end_of_statement ())
1386 e
= (struct cfi_escape_data
*) xmalloc (sizeof (*e
));
1387 do_parse_cons_expression (&e
->exp
, 1);
1392 while (*input_line_pointer
++ == ',');
1393 --input_line_pointer
;
1397 if (last_fde
->lsda_encoding
!= DW_EH_PE_omit
)
1398 last_fde
->eh_header_type
= EH_COMPACT_HAS_LSDA
;
1399 else if (num_ops
<= 3 && last_fde
->per_encoding
== DW_EH_PE_omit
)
1400 last_fde
->eh_header_type
= EH_COMPACT_INLINE
;
1402 last_fde
->eh_header_type
= EH_COMPACT_OUTLINE
;
1404 if (last_fde
->eh_header_type
== EH_COMPACT_INLINE
)
1407 last_fde
->eh_data_size
= num_ops
;
1408 last_fde
->eh_data
= (bfd_byte
*) xmalloc (num_ops
);
1414 last_fde
->eh_data
[num_ops
++] = e
->exp
.X_add_number
;
1417 if (last_fde
->eh_header_type
== EH_COMPACT_INLINE
)
1419 last_fde
->eh_data
[num_ops
++] = tc_compact_eh_opcode_stop
;
1422 demand_empty_rest_of_line ();
1425 /* Function to emit the compact unwinding opcodes stored in the
1426 fde's eh_data field. The end of the opcode data will be
1427 padded to the value in align. */
1430 output_compact_unwind_data (struct fde_entry
*fde
, int align
)
1432 int data_size
= fde
->eh_data_size
+ 2;
1437 fde
->eh_loc
= symbol_temp_new_now ();
1440 if (fde
->personality_id
!= 0)
1441 *p
= fde
->personality_id
;
1442 else if (fde
->per_encoding
!= DW_EH_PE_omit
)
1445 emit_expr_encoded (&fde
->personality
, fde
->per_encoding
, FALSE
);
1446 data_size
+= encoding_size (fde
->per_encoding
);
1451 amask
= (1 << align
) - 1;
1452 align_padding
= ((data_size
+ amask
) & ~amask
) - data_size
;
1454 p
= frag_more (fde
->eh_data_size
+ 1 + align_padding
);
1455 memcpy (p
, fde
->eh_data
, fde
->eh_data_size
);
1456 p
+= fde
->eh_data_size
;
1458 while (align_padding
-- > 0)
1459 *(p
++) = tc_compact_eh_opcode_pad
;
1461 *(p
++) = tc_compact_eh_opcode_stop
;
1462 fde
->eh_header_type
= EH_COMPACT_OUTLINE_DONE
;
1465 /* Handle the .cfi_inline_lsda directive. */
1467 dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED
)
1471 long max_alignment
= 28;
1475 as_bad (_("unexpected .cfi_inline_lsda"));
1476 ignore_rest_of_line ();
1480 if ((last_fde
->sections
& CFI_EMIT_eh_frame_compact
) == 0)
1482 as_bad (_(".cfi_inline_lsda not valid for this frame"));
1483 ignore_rest_of_line ();
1487 if (last_fde
->eh_header_type
!= EH_COMPACT_UNKNOWN
1488 && last_fde
->eh_header_type
!= EH_COMPACT_HAS_LSDA
)
1490 as_bad (_(".cfi_inline_lsda seen for frame without .cfi_lsda"));
1491 ignore_rest_of_line ();
1495 #ifdef md_flush_pending_output
1496 md_flush_pending_output ();
1499 align
= get_absolute_expression ();
1500 if (align
> max_alignment
)
1502 align
= max_alignment
;
1503 as_bad (_("Alignment too large: %d. assumed."), align
);
1507 as_warn (_("Alignment negative: 0 assumed."));
1511 demand_empty_rest_of_line ();
1512 ccseg
= CUR_SEG (last_fde
);
1514 /* Open .gnu_extab section. */
1515 get_cfi_seg (ccseg
, ".gnu_extab",
1516 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
1517 | DWARF2_EH_FRAME_READ_ONLY
),
1520 frag_align (align
, 0, 0);
1521 record_alignment (now_seg
, align
);
1522 if (last_fde
->eh_header_type
== EH_COMPACT_HAS_LSDA
)
1523 output_compact_unwind_data (last_fde
, align
);
1529 #else /* !SUPPORT_COMPACT_EH */
1531 dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED
)
1533 as_bad (_(".cfi_inline_lsda is not supported for this target"));
1534 ignore_rest_of_line ();
1538 dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED
)
1540 as_bad (_(".cfi_fde_data is not supported for this target"));
1541 ignore_rest_of_line ();
1545 dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED
)
1547 as_bad (_(".cfi_personality_id is not supported for this target"));
1548 ignore_rest_of_line ();
1553 output_cfi_insn (struct cfi_insn_data
*insn
)
1560 case DW_CFA_advance_loc
:
1562 symbolS
*from
= insn
->u
.ll
.lab1
;
1563 symbolS
*to
= insn
->u
.ll
.lab2
;
1565 if (symbol_get_frag (to
) == symbol_get_frag (from
))
1567 addressT delta
= S_GET_VALUE (to
) - S_GET_VALUE (from
);
1568 addressT scaled
= delta
/ DWARF2_LINE_MIN_INSN_LENGTH
;
1571 out_one (DW_CFA_advance_loc
+ scaled
);
1572 else if (scaled
<= 0xFF)
1574 out_one (DW_CFA_advance_loc1
);
1577 else if (scaled
<= 0xFFFF)
1579 out_one (DW_CFA_advance_loc2
);
1584 out_one (DW_CFA_advance_loc4
);
1592 exp
.X_op
= O_subtract
;
1593 exp
.X_add_symbol
= to
;
1594 exp
.X_op_symbol
= from
;
1595 exp
.X_add_number
= 0;
1597 /* The code in ehopt.c expects that one byte of the encoding
1598 is already allocated to the frag. This comes from the way
1599 that it scans the .eh_frame section looking first for the
1600 .byte DW_CFA_advance_loc4. */
1601 *frag_more (1) = DW_CFA_advance_loc4
;
1603 frag_var (rs_cfa
, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH
<< 3,
1604 make_expr_symbol (&exp
), frag_now_fix () - 1,
1610 case DW_CFA_def_cfa
:
1611 offset
= insn
->u
.ri
.offset
;
1614 out_one (DW_CFA_def_cfa_sf
);
1615 out_uleb128 (insn
->u
.ri
.reg
);
1616 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1620 out_one (DW_CFA_def_cfa
);
1621 out_uleb128 (insn
->u
.ri
.reg
);
1622 out_uleb128 (offset
);
1626 case DW_CFA_def_cfa_register
:
1627 case DW_CFA_undefined
:
1628 case DW_CFA_same_value
:
1629 out_one (insn
->insn
);
1630 out_uleb128 (insn
->u
.r
);
1633 case DW_CFA_def_cfa_offset
:
1637 out_one (DW_CFA_def_cfa_offset_sf
);
1638 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1642 out_one (DW_CFA_def_cfa_offset
);
1643 out_uleb128 (offset
);
1647 case DW_CFA_restore
:
1651 out_one (DW_CFA_restore
+ regno
);
1655 out_one (DW_CFA_restore_extended
);
1656 out_uleb128 (regno
);
1661 regno
= insn
->u
.ri
.reg
;
1662 offset
= insn
->u
.ri
.offset
/ DWARF2_CIE_DATA_ALIGNMENT
;
1665 out_one (DW_CFA_offset_extended_sf
);
1666 out_uleb128 (regno
);
1667 out_sleb128 (offset
);
1669 else if (regno
<= 0x3F)
1671 out_one (DW_CFA_offset
+ regno
);
1672 out_uleb128 (offset
);
1676 out_one (DW_CFA_offset_extended
);
1677 out_uleb128 (regno
);
1678 out_uleb128 (offset
);
1682 case DW_CFA_register
:
1683 out_one (DW_CFA_register
);
1684 out_uleb128 (insn
->u
.rr
.reg1
);
1685 out_uleb128 (insn
->u
.rr
.reg2
);
1688 case DW_CFA_remember_state
:
1689 case DW_CFA_restore_state
:
1690 out_one (insn
->insn
);
1693 case DW_CFA_GNU_window_save
:
1694 out_one (DW_CFA_GNU_window_save
);
1699 struct cfi_escape_data
*e
;
1700 for (e
= insn
->u
.esc
; e
; e
= e
->next
)
1701 emit_expr (&e
->exp
, 1);
1705 case CFI_val_encoded_addr
:
1707 unsigned encoding
= insn
->u
.ea
.encoding
;
1710 if (encoding
== DW_EH_PE_omit
)
1712 out_one (DW_CFA_val_expression
);
1713 out_uleb128 (insn
->u
.ea
.reg
);
1715 switch (encoding
& 0x7)
1717 case DW_EH_PE_absptr
:
1718 enc_size
= DWARF2_ADDR_SIZE (stdoutput
);
1720 case DW_EH_PE_udata2
:
1723 case DW_EH_PE_udata4
:
1726 case DW_EH_PE_udata8
:
1733 /* If the user has requested absolute encoding,
1734 then use the smaller DW_OP_addr encoding. */
1735 if (insn
->u
.ea
.encoding
== DW_EH_PE_absptr
)
1737 out_uleb128 (1 + enc_size
);
1738 out_one (DW_OP_addr
);
1742 out_uleb128 (1 + 1 + enc_size
);
1743 out_one (DW_OP_GNU_encoded_addr
);
1746 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1748 #if CFI_DIFF_EXPR_OK
1749 insn
->u
.ea
.exp
.X_op
= O_subtract
;
1750 insn
->u
.ea
.exp
.X_op_symbol
= symbol_temp_new_now ();
1751 #elif defined (tc_cfi_emit_pcrel_expr)
1752 tc_cfi_emit_pcrel_expr (&insn
->u
.ea
.exp
, enc_size
);
1759 emit_expr (&insn
->u
.ea
.exp
, enc_size
);
1764 colon (insn
->u
.sym_name
);
1773 output_cie (struct cie_entry
*cie
, bfd_boolean eh_frame
, int align
)
1775 symbolS
*after_size_address
, *end_address
;
1777 struct cfi_insn_data
*i
;
1778 offsetT augmentation_size
;
1780 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1782 cie
->start_address
= symbol_temp_new_now ();
1783 after_size_address
= symbol_temp_make ();
1784 end_address
= symbol_temp_make ();
1786 exp
.X_op
= O_subtract
;
1787 exp
.X_add_symbol
= end_address
;
1788 exp
.X_op_symbol
= after_size_address
;
1789 exp
.X_add_number
= 0;
1791 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1792 emit_expr (&exp
, 4); /* Length. */
1795 if (fmt
== dwarf2_format_64bit
)
1797 emit_expr (&exp
, 8); /* Length. */
1799 symbol_set_value_now (after_size_address
);
1801 out_four (0); /* CIE id. */
1804 out_four (-1); /* CIE id. */
1805 if (fmt
!= dwarf2_format_32bit
)
1808 out_one (DW_CIE_VERSION
); /* Version. */
1811 out_one ('z'); /* Augmentation. */
1812 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1814 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1818 if (cie
->signal_frame
)
1821 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH
); /* Code alignment. */
1822 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT
); /* Data alignment. */
1823 if (DW_CIE_VERSION
== 1) /* Return column. */
1824 out_one (cie
->return_column
);
1826 out_uleb128 (cie
->return_column
);
1829 augmentation_size
= 1 + (cie
->lsda_encoding
!= DW_EH_PE_omit
);
1830 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1831 augmentation_size
+= 1 + encoding_size (cie
->per_encoding
);
1832 out_uleb128 (augmentation_size
); /* Augmentation size. */
1834 emit_expr_encoded (&cie
->personality
, cie
->per_encoding
, TRUE
);
1836 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1837 out_one (cie
->lsda_encoding
);
1840 switch (DWARF2_FDE_RELOC_SIZE
)
1843 enc
= DW_EH_PE_sdata2
;
1846 enc
= DW_EH_PE_sdata4
;
1849 enc
= DW_EH_PE_sdata8
;
1854 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1855 enc
|= DW_EH_PE_pcrel
;
1857 #ifdef DWARF2_FDE_RELOC_ENCODING
1858 /* Allow target to override encoding. */
1859 enc
= DWARF2_FDE_RELOC_ENCODING (enc
);
1861 cie
->fde_encoding
= enc
;
1867 for (i
= cie
->first
; i
!= cie
->last
; i
= i
->next
)
1869 if (CUR_SEG (i
) != CUR_SEG (cie
))
1871 output_cfi_insn (i
);
1875 frag_align (align
, DW_CFA_nop
, 0);
1876 symbol_set_value_now (end_address
);
1880 output_fde (struct fde_entry
*fde
, struct cie_entry
*cie
,
1881 bfd_boolean eh_frame
, struct cfi_insn_data
*first
,
1884 symbolS
*after_size_address
, *end_address
;
1886 offsetT augmentation_size
;
1887 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1891 after_size_address
= symbol_temp_make ();
1892 end_address
= symbol_temp_make ();
1894 exp
.X_op
= O_subtract
;
1895 exp
.X_add_symbol
= end_address
;
1896 exp
.X_op_symbol
= after_size_address
;
1897 exp
.X_add_number
= 0;
1898 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1902 if (fmt
== dwarf2_format_64bit
)
1906 emit_expr (&exp
, offset_size
); /* Length. */
1907 symbol_set_value_now (after_size_address
);
1911 exp
.X_op
= O_subtract
;
1912 exp
.X_add_symbol
= after_size_address
;
1913 exp
.X_op_symbol
= cie
->start_address
;
1914 exp
.X_add_number
= 0;
1915 emit_expr (&exp
, offset_size
); /* CIE offset. */
1919 TC_DWARF2_EMIT_OFFSET (cie
->start_address
, offset_size
);
1922 exp
.X_op
= O_symbol
;
1925 bfd_reloc_code_real_type code
1926 = tc_cfi_reloc_for_encoding (cie
->fde_encoding
);
1927 if (code
!= BFD_RELOC_NONE
)
1929 reloc_howto_type
*howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1930 char *p
= frag_more (4);
1931 md_number_to_chars (p
, 0, 4);
1932 fix_new (frag_now
, p
- frag_now
->fr_literal
, 4, fde
->start_address
,
1933 0, howto
->pc_relative
, code
);
1937 exp
.X_op
= O_subtract
;
1938 exp
.X_add_number
= 0;
1939 #if CFI_DIFF_EXPR_OK
1940 exp
.X_add_symbol
= fde
->start_address
;
1941 exp
.X_op_symbol
= symbol_temp_new_now ();
1942 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1944 exp
.X_op
= O_symbol
;
1945 exp
.X_add_symbol
= fde
->start_address
;
1947 #if defined(tc_cfi_emit_pcrel_expr)
1948 tc_cfi_emit_pcrel_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1950 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1954 addr_size
= DWARF2_FDE_RELOC_SIZE
;
1958 exp
.X_add_number
= 0;
1959 exp
.X_add_symbol
= fde
->start_address
;
1960 addr_size
= DWARF2_ADDR_SIZE (stdoutput
);
1961 emit_expr (&exp
, addr_size
);
1964 exp
.X_op
= O_subtract
;
1965 exp
.X_add_symbol
= fde
->end_address
;
1966 exp
.X_op_symbol
= fde
->start_address
; /* Code length. */
1967 exp
.X_add_number
= 0;
1968 emit_expr (&exp
, addr_size
);
1970 augmentation_size
= encoding_size (fde
->lsda_encoding
);
1972 out_uleb128 (augmentation_size
); /* Augmentation size. */
1974 emit_expr_encoded (&fde
->lsda
, cie
->lsda_encoding
, FALSE
);
1976 for (; first
; first
= first
->next
)
1977 if (CUR_SEG (first
) == CUR_SEG (fde
))
1978 output_cfi_insn (first
);
1980 frag_align (align
, DW_CFA_nop
, 0);
1981 symbol_set_value_now (end_address
);
1984 static struct cie_entry
*
1985 select_cie_for_fde (struct fde_entry
*fde
, bfd_boolean eh_frame
,
1986 struct cfi_insn_data
**pfirst
, int align
)
1988 struct cfi_insn_data
*i
, *j
;
1989 struct cie_entry
*cie
;
1991 for (cie
= cie_root
; cie
; cie
= cie
->next
)
1993 if (CUR_SEG (cie
) != CUR_SEG (fde
))
1995 if (cie
->return_column
!= fde
->return_column
1996 || cie
->signal_frame
!= fde
->signal_frame
1997 || cie
->per_encoding
!= fde
->per_encoding
1998 || cie
->lsda_encoding
!= fde
->lsda_encoding
)
2000 if (cie
->per_encoding
!= DW_EH_PE_omit
)
2002 if (cie
->personality
.X_op
!= fde
->personality
.X_op
2003 || cie
->personality
.X_add_number
2004 != fde
->personality
.X_add_number
)
2006 switch (cie
->personality
.X_op
)
2009 if (cie
->personality
.X_unsigned
!= fde
->personality
.X_unsigned
)
2013 if (cie
->personality
.X_add_symbol
2014 != fde
->personality
.X_add_symbol
)
2021 for (i
= cie
->first
, j
= fde
->data
;
2022 i
!= cie
->last
&& j
!= NULL
;
2023 i
= i
->next
, j
= j
->next
)
2025 if (i
->insn
!= j
->insn
)
2029 case DW_CFA_advance_loc
:
2030 case DW_CFA_remember_state
:
2031 /* We reached the first advance/remember in the FDE,
2032 but did not reach the end of the CIE list. */
2036 case DW_CFA_def_cfa
:
2037 if (i
->u
.ri
.reg
!= j
->u
.ri
.reg
)
2039 if (i
->u
.ri
.offset
!= j
->u
.ri
.offset
)
2043 case DW_CFA_register
:
2044 if (i
->u
.rr
.reg1
!= j
->u
.rr
.reg1
)
2046 if (i
->u
.rr
.reg2
!= j
->u
.rr
.reg2
)
2050 case DW_CFA_def_cfa_register
:
2051 case DW_CFA_restore
:
2052 case DW_CFA_undefined
:
2053 case DW_CFA_same_value
:
2054 if (i
->u
.r
!= j
->u
.r
)
2058 case DW_CFA_def_cfa_offset
:
2059 if (i
->u
.i
!= j
->u
.i
)
2064 case CFI_val_encoded_addr
:
2066 /* Don't bother matching these for now. */
2074 /* Success if we reached the end of the CIE list, and we've either
2075 run out of FDE entries or we've encountered an advance,
2076 remember, or escape. */
2079 || j
->insn
== DW_CFA_advance_loc
2080 || j
->insn
== DW_CFA_remember_state
2081 || j
->insn
== CFI_escape
2082 || j
->insn
== CFI_val_encoded_addr
2083 || j
->insn
== CFI_label
))
2092 cie
= (struct cie_entry
*) xmalloc (sizeof (struct cie_entry
));
2093 cie
->next
= cie_root
;
2095 SET_CUR_SEG (cie
, CUR_SEG (fde
));
2096 cie
->return_column
= fde
->return_column
;
2097 cie
->signal_frame
= fde
->signal_frame
;
2098 cie
->per_encoding
= fde
->per_encoding
;
2099 cie
->lsda_encoding
= fde
->lsda_encoding
;
2100 cie
->personality
= fde
->personality
;
2101 cie
->first
= fde
->data
;
2103 for (i
= cie
->first
; i
; i
= i
->next
)
2104 if (i
->insn
== DW_CFA_advance_loc
2105 || i
->insn
== DW_CFA_remember_state
2106 || i
->insn
== CFI_escape
2107 || i
->insn
== CFI_val_encoded_addr
2108 || i
->insn
== CFI_label
)
2114 output_cie (cie
, eh_frame
, align
);
2119 #ifdef md_reg_eh_frame_to_debug_frame
2121 cfi_change_reg_numbers (struct cfi_insn_data
*insn
, segT ccseg
)
2123 for (; insn
; insn
= insn
->next
)
2125 if (CUR_SEG (insn
) != ccseg
)
2129 case DW_CFA_advance_loc
:
2130 case DW_CFA_def_cfa_offset
:
2131 case DW_CFA_remember_state
:
2132 case DW_CFA_restore_state
:
2133 case DW_CFA_GNU_window_save
:
2138 case DW_CFA_def_cfa
:
2140 insn
->u
.ri
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ri
.reg
);
2143 case DW_CFA_def_cfa_register
:
2144 case DW_CFA_undefined
:
2145 case DW_CFA_same_value
:
2146 case DW_CFA_restore
:
2147 insn
->u
.r
= md_reg_eh_frame_to_debug_frame (insn
->u
.r
);
2150 case DW_CFA_register
:
2151 insn
->u
.rr
.reg1
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg1
);
2152 insn
->u
.rr
.reg2
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg2
);
2155 case CFI_val_encoded_addr
:
2156 insn
->u
.ea
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ea
.reg
);
2165 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
2168 #if SUPPORT_COMPACT_EH
2170 cfi_emit_eh_header (symbolS
*sym
, bfd_vma addend
)
2174 exp
.X_add_number
= addend
;
2175 exp
.X_add_symbol
= sym
;
2176 emit_expr_encoded (&exp
, DW_EH_PE_sdata4
| DW_EH_PE_pcrel
, FALSE
);
2180 output_eh_header (struct fde_entry
*fde
)
2185 if (fde
->eh_header_type
== EH_COMPACT_INLINE
)
2190 cfi_emit_eh_header (fde
->start_address
, addend
);
2192 if (fde
->eh_header_type
== EH_COMPACT_INLINE
)
2195 /* Inline entries always use PR1. */
2197 memcpy(p
, fde
->eh_data
, 3);
2201 if (fde
->eh_header_type
== EH_COMPACT_LEGACY
)
2203 else if (fde
->eh_header_type
== EH_COMPACT_OUTLINE
2204 || fde
->eh_header_type
== EH_COMPACT_OUTLINE_DONE
)
2208 cfi_emit_eh_header (fde
->eh_loc
, addend
);
2216 struct cie_entry
*cie
, *cie_next
;
2217 segT cfi_seg
, ccseg
;
2218 struct fde_entry
*fde
;
2219 struct cfi_insn_data
*first
;
2220 int save_flag_traditional_format
, seek_next_seg
;
2222 if (all_fde_data
== 0)
2225 if ((all_cfi_sections
& CFI_EMIT_eh_frame
) != 0
2226 || (all_cfi_sections
& CFI_EMIT_eh_frame_compact
) != 0)
2228 /* Make sure check_eh_frame doesn't do anything with our output. */
2229 save_flag_traditional_format
= flag_traditional_format
;
2230 flag_traditional_format
= 1;
2232 if (!EH_FRAME_LINKONCE
)
2234 /* Open .eh_frame section. */
2235 cfi_seg
= get_cfi_seg (NULL
, ".eh_frame",
2236 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
2237 | DWARF2_EH_FRAME_READ_ONLY
),
2238 EH_FRAME_ALIGNMENT
);
2239 #ifdef md_fix_up_eh_frame
2240 md_fix_up_eh_frame (cfi_seg
);
2251 for (cie
= cie_root
; cie
; cie
= cie_next
)
2253 cie_next
= cie
->next
;
2254 free ((void *) cie
);
2258 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2260 if ((fde
->sections
& CFI_EMIT_eh_frame
) == 0
2261 && (fde
->sections
& CFI_EMIT_eh_frame_compact
) == 0)
2264 #if SUPPORT_COMPACT_EH
2265 /* Emit a LEGACY format header if we have processed all
2266 of the .cfi directives without encountering either inline or
2267 out-of-line compact unwinding opcodes. */
2268 if (fde
->eh_header_type
== EH_COMPACT_HAS_LSDA
2269 || fde
->eh_header_type
== EH_COMPACT_UNKNOWN
)
2270 fde
->eh_header_type
= EH_COMPACT_LEGACY
;
2272 if (fde
->eh_header_type
!= EH_COMPACT_LEGACY
)
2275 if (EH_FRAME_LINKONCE
)
2279 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
2286 ccseg
= CUR_SEG (fde
);
2287 /* Open .eh_frame section. */
2288 cfi_seg
= get_cfi_seg (ccseg
, ".eh_frame",
2289 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
2290 | DWARF2_EH_FRAME_READ_ONLY
),
2291 EH_FRAME_ALIGNMENT
);
2292 #ifdef md_fix_up_eh_frame
2293 md_fix_up_eh_frame (cfi_seg
);
2299 SET_HANDLED (fde
, 1);
2302 if (fde
->end_address
== NULL
)
2304 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
2305 fde
->end_address
= fde
->start_address
;
2308 cie
= select_cie_for_fde (fde
, TRUE
, &first
, 2);
2309 fde
->eh_loc
= symbol_temp_new_now ();
2310 output_fde (fde
, cie
, TRUE
, first
,
2311 fde
->next
== NULL
? EH_FRAME_ALIGNMENT
: 2);
2314 while (EH_FRAME_LINKONCE
&& seek_next_seg
== 2);
2316 if (EH_FRAME_LINKONCE
)
2317 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2318 SET_HANDLED (fde
, 0);
2320 #if SUPPORT_COMPACT_EH
2323 /* Create remaining out of line table entries. */
2329 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2331 if ((fde
->sections
& CFI_EMIT_eh_frame
) == 0
2332 && (fde
->sections
& CFI_EMIT_eh_frame_compact
) == 0)
2335 if (fde
->eh_header_type
!= EH_COMPACT_OUTLINE
)
2339 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
2346 ccseg
= CUR_SEG (fde
);
2347 /* Open .gnu_extab section. */
2348 get_cfi_seg (ccseg
, ".gnu_extab",
2349 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
2350 | DWARF2_EH_FRAME_READ_ONLY
),
2354 SET_HANDLED (fde
, 1);
2356 frag_align (1, 0, 0);
2357 record_alignment (now_seg
, 1);
2358 output_compact_unwind_data (fde
, 1);
2361 while (EH_FRAME_LINKONCE
&& seek_next_seg
== 2);
2363 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2364 SET_HANDLED (fde
, 0);
2366 /* Create index table fragments. */
2372 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2374 if ((fde
->sections
& CFI_EMIT_eh_frame
) == 0
2375 && (fde
->sections
& CFI_EMIT_eh_frame_compact
) == 0)
2380 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
2387 ccseg
= CUR_SEG (fde
);
2388 /* Open .eh_frame_entry section. */
2389 cfi_seg
= get_cfi_seg (ccseg
, ".eh_frame_entry",
2390 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
2391 | DWARF2_EH_FRAME_READ_ONLY
),
2395 SET_HANDLED (fde
, 1);
2397 output_eh_header (fde
);
2400 while (seek_next_seg
== 2);
2402 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2403 SET_HANDLED (fde
, 0);
2405 #endif /* SUPPORT_COMPACT_EH */
2407 flag_traditional_format
= save_flag_traditional_format
;
2410 if ((all_cfi_sections
& CFI_EMIT_debug_frame
) != 0)
2412 int alignment
= ffs (DWARF2_ADDR_SIZE (stdoutput
)) - 1;
2414 if (!SUPPORT_FRAME_LINKONCE
)
2415 get_cfi_seg (NULL
, ".debug_frame",
2416 SEC_READONLY
| SEC_DEBUGGING
,
2424 for (cie
= cie_root
; cie
; cie
= cie_next
)
2426 cie_next
= cie
->next
;
2427 free ((void *) cie
);
2431 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2433 if ((fde
->sections
& CFI_EMIT_debug_frame
) == 0)
2436 if (SUPPORT_FRAME_LINKONCE
)
2440 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
2447 ccseg
= CUR_SEG (fde
);
2448 /* Open .debug_frame section. */
2449 get_cfi_seg (ccseg
, ".debug_frame",
2450 SEC_READONLY
| SEC_DEBUGGING
,
2454 SET_HANDLED (fde
, 1);
2456 if (fde
->end_address
== NULL
)
2458 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
2459 fde
->end_address
= fde
->start_address
;
2462 fde
->per_encoding
= DW_EH_PE_omit
;
2463 fde
->lsda_encoding
= DW_EH_PE_omit
;
2464 cfi_change_reg_numbers (fde
->data
, ccseg
);
2465 cie
= select_cie_for_fde (fde
, FALSE
, &first
, alignment
);
2466 output_fde (fde
, cie
, FALSE
, first
, alignment
);
2469 while (SUPPORT_FRAME_LINKONCE
&& seek_next_seg
== 2);
2471 if (SUPPORT_FRAME_LINKONCE
)
2472 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
2473 SET_HANDLED (fde
, 0);
2477 #else /* TARGET_USE_CFIPOP */
2479 /* Emit an intelligible error message for missing support. */
2482 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED
)
2484 as_bad (_("CFI is not supported for this target"));
2485 ignore_rest_of_line ();
2488 const pseudo_typeS cfi_pseudo_table
[] =
2490 { "cfi_sections", dot_cfi_dummy
, 0 },
2491 { "cfi_startproc", dot_cfi_dummy
, 0 },
2492 { "cfi_endproc", dot_cfi_dummy
, 0 },
2493 { "cfi_fde_data", dot_cfi_dummy
, 0 },
2494 { "cfi_def_cfa", dot_cfi_dummy
, 0 },
2495 { "cfi_def_cfa_register", dot_cfi_dummy
, 0 },
2496 { "cfi_def_cfa_offset", dot_cfi_dummy
, 0 },
2497 { "cfi_adjust_cfa_offset", dot_cfi_dummy
, 0 },
2498 { "cfi_offset", dot_cfi_dummy
, 0 },
2499 { "cfi_rel_offset", dot_cfi_dummy
, 0 },
2500 { "cfi_register", dot_cfi_dummy
, 0 },
2501 { "cfi_return_column", dot_cfi_dummy
, 0 },
2502 { "cfi_restore", dot_cfi_dummy
, 0 },
2503 { "cfi_undefined", dot_cfi_dummy
, 0 },
2504 { "cfi_same_value", dot_cfi_dummy
, 0 },
2505 { "cfi_remember_state", dot_cfi_dummy
, 0 },
2506 { "cfi_restore_state", dot_cfi_dummy
, 0 },
2507 { "cfi_window_save", dot_cfi_dummy
, 0 },
2508 { "cfi_escape", dot_cfi_dummy
, 0 },
2509 { "cfi_signal_frame", dot_cfi_dummy
, 0 },
2510 { "cfi_personality", dot_cfi_dummy
, 0 },
2511 { "cfi_personality_id", dot_cfi_dummy
, 0 },
2512 { "cfi_lsda", dot_cfi_dummy
, 0 },
2513 { "cfi_val_encoded_addr", dot_cfi_dummy
, 0 },
2514 { "cfi_label", dot_cfi_dummy
, 0 },
2515 { "cfi_inline_lsda", dot_cfi_dummy
, 0 },
2523 #endif /* TARGET_USE_CFIPOP */