1 /* dw2gencfi.c - Support for generating Dwarf2 CFI information.
2 Copyright (C) 2003-2014 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))
79 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
82 #ifndef DWARF2_ADDR_SIZE
83 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
86 #if SUPPORT_FRAME_LINKONCE
87 #define CUR_SEG(structp) structp->cur_seg
88 #define SET_CUR_SEG(structp, seg) structp->cur_seg = seg
89 #define HANDLED(structp) structp->handled
90 #define SET_HANDLED(structp, val) structp->handled = val
92 #define CUR_SEG(structp) NULL
93 #define SET_CUR_SEG(structp, seg) (void) (0 && seg)
94 #define HANDLED(structp) 0
95 #define SET_HANDLED(structp, val) (void) (0 && val)
98 /* Private segment collection list. */
106 #define FRAME_NAME ".eh_frame"
108 static struct hash_control
*dwcfi_hash
;
110 /* Build based on segment the derived .debug_...
111 segment name containing origin segment's postfix name part. */
114 get_debugseg_name (segT seg
, const char *base_name
)
125 name
= bfd_get_section_name (stdoutput
, seg
);
127 dollar
= strchr (name
, '$');
128 dot
= strchr (name
+ 1, '.');
136 else if (dot
< dollar
)
142 return concat (base_name
, name
, NULL
);
145 /* Allocate a dwcfi_seg_list structure. */
147 static struct dwcfi_seg_list
*
148 alloc_debugseg_item (segT seg
, int subseg
, char *name
)
150 struct dwcfi_seg_list
*r
;
152 r
= (struct dwcfi_seg_list
*)
153 xmalloc (sizeof (struct dwcfi_seg_list
) + strlen (name
));
161 is_now_linkonce_segment (void)
163 if ((bfd_get_section_flags (stdoutput
, now_seg
)
164 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
165 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
166 | SEC_LINK_DUPLICATES_SAME_CONTENTS
)) != 0)
171 /* Generate debug... segment with same linkonce properties
175 make_debug_seg (segT cseg
, char *name
, int sflags
)
177 segT save_seg
= now_seg
;
178 int save_subseg
= now_subseg
;
182 r
= subseg_new (name
, 0);
184 /* Check if code segment is marked as linked once. */
188 flags
= bfd_get_section_flags (stdoutput
, cseg
)
189 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
190 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
191 | SEC_LINK_DUPLICATES_SAME_CONTENTS
);
193 /* Add standard section flags. */
196 /* Apply possibly linked once flags to new generated segment, too. */
197 if (!bfd_set_section_flags (stdoutput
, r
, flags
))
198 as_bad (_("bfd_set_section_flags: %s"),
199 bfd_errmsg (bfd_get_error ()));
201 /* Restore to previous segment. */
202 if (save_seg
!= NULL
)
203 subseg_set (save_seg
, save_subseg
);
208 dwcfi_hash_insert (const char *name
, struct dwcfi_seg_list
*item
)
210 const char *error_string
;
212 if ((error_string
= hash_jam (dwcfi_hash
, name
, (char *) item
)))
213 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
217 static struct dwcfi_seg_list
*
218 dwcfi_hash_find (char *name
)
220 return (struct dwcfi_seg_list
*) hash_find (dwcfi_hash
, name
);
223 static struct dwcfi_seg_list
*
224 dwcfi_hash_find_or_make (segT cseg
, const char *base_name
, int flags
)
226 struct dwcfi_seg_list
*item
;
229 /* Initialize dwcfi_hash once. */
231 dwcfi_hash
= hash_new ();
233 name
= get_debugseg_name (cseg
, base_name
);
235 item
= dwcfi_hash_find (name
);
238 item
= alloc_debugseg_item (make_debug_seg (cseg
, name
, flags
), 0, name
);
240 dwcfi_hash_insert (item
->seg_name
, item
);
248 /* ??? Share this with dwarf2cfg.c. */
249 #ifndef TC_DWARF2_EMIT_OFFSET
250 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
252 /* Create an offset to .dwarf2_*. */
255 generic_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
260 exp
.X_add_symbol
= symbol
;
261 exp
.X_add_number
= 0;
262 emit_expr (&exp
, size
);
266 struct cfi_escape_data
268 struct cfi_escape_data
*next
;
274 struct cie_entry
*next
;
275 #if SUPPORT_FRAME_LINKONCE
278 symbolS
*start_address
;
279 unsigned int return_column
;
280 unsigned int signal_frame
;
281 unsigned char per_encoding
;
282 unsigned char lsda_encoding
;
283 expressionS personality
;
284 struct cfi_insn_data
*first
, *last
;
287 /* List of FDE entries. */
289 struct fde_entry
*all_fde_data
;
290 static struct fde_entry
**last_fde_data
= &all_fde_data
;
292 /* List of CIEs so that they could be reused. */
293 static struct cie_entry
*cie_root
;
295 /* Stack of old CFI data, for save/restore. */
298 struct cfa_save_data
*next
;
302 /* Current open FDE entry. */
305 struct fde_entry
*cur_fde_data
;
306 symbolS
*last_address
;
307 offsetT cur_cfa_offset
;
308 struct cfa_save_data
*cfa_save_stack
;
311 /* Construct a new FDE structure and add it to the end of the fde list. */
313 static struct fde_entry
*
314 alloc_fde_entry (void)
316 struct fde_entry
*fde
= (struct fde_entry
*)
317 xcalloc (1, sizeof (struct fde_entry
));
319 frchain_now
->frch_cfi_data
= (struct frch_cfi_data
*)
320 xcalloc (1, sizeof (struct frch_cfi_data
));
321 frchain_now
->frch_cfi_data
->cur_fde_data
= fde
;
322 *last_fde_data
= fde
;
323 last_fde_data
= &fde
->next
;
324 SET_CUR_SEG (fde
, is_now_linkonce_segment ());
325 SET_HANDLED (fde
, 0);
326 fde
->last
= &fde
->data
;
327 fde
->return_column
= DWARF2_DEFAULT_RETURN_COLUMN
;
328 fde
->per_encoding
= DW_EH_PE_omit
;
329 fde
->lsda_encoding
= DW_EH_PE_omit
;
334 /* The following functions are available for a backend to construct its
335 own unwind information, usually from legacy unwind directives. */
337 /* Construct a new INSN structure and add it to the end of the insn list
338 for the currently active FDE. */
340 static struct cfi_insn_data
*
341 alloc_cfi_insn_data (void)
343 struct cfi_insn_data
*insn
= (struct cfi_insn_data
*)
344 xcalloc (1, sizeof (struct cfi_insn_data
));
345 struct fde_entry
*cur_fde_data
= frchain_now
->frch_cfi_data
->cur_fde_data
;
347 *cur_fde_data
->last
= insn
;
348 cur_fde_data
->last
= &insn
->next
;
349 SET_CUR_SEG (insn
, is_now_linkonce_segment ());
353 /* Construct a new FDE structure that begins at LABEL. */
356 cfi_new_fde (symbolS
*label
)
358 struct fde_entry
*fde
= alloc_fde_entry ();
359 fde
->start_address
= label
;
360 frchain_now
->frch_cfi_data
->last_address
= label
;
363 /* End the currently open FDE. */
366 cfi_end_fde (symbolS
*label
)
368 frchain_now
->frch_cfi_data
->cur_fde_data
->end_address
= label
;
369 free (frchain_now
->frch_cfi_data
);
370 frchain_now
->frch_cfi_data
= NULL
;
373 /* Set the return column for the current FDE. */
376 cfi_set_return_column (unsigned regno
)
378 frchain_now
->frch_cfi_data
->cur_fde_data
->return_column
= regno
;
381 /* Universal functions to store new instructions. */
384 cfi_add_CFA_insn (int insn
)
386 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
388 insn_ptr
->insn
= insn
;
392 cfi_add_CFA_insn_reg (int insn
, unsigned regno
)
394 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
396 insn_ptr
->insn
= insn
;
397 insn_ptr
->u
.r
= regno
;
401 cfi_add_CFA_insn_offset (int insn
, offsetT offset
)
403 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
405 insn_ptr
->insn
= insn
;
406 insn_ptr
->u
.i
= offset
;
410 cfi_add_CFA_insn_reg_reg (int insn
, unsigned reg1
, unsigned reg2
)
412 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
414 insn_ptr
->insn
= insn
;
415 insn_ptr
->u
.rr
.reg1
= reg1
;
416 insn_ptr
->u
.rr
.reg2
= reg2
;
420 cfi_add_CFA_insn_reg_offset (int insn
, unsigned regno
, offsetT offset
)
422 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
424 insn_ptr
->insn
= insn
;
425 insn_ptr
->u
.ri
.reg
= regno
;
426 insn_ptr
->u
.ri
.offset
= offset
;
429 /* Add a CFI insn to advance the PC from the last address to LABEL. */
432 cfi_add_advance_loc (symbolS
*label
)
434 struct cfi_insn_data
*insn
= alloc_cfi_insn_data ();
436 insn
->insn
= DW_CFA_advance_loc
;
437 insn
->u
.ll
.lab1
= frchain_now
->frch_cfi_data
->last_address
;
438 insn
->u
.ll
.lab2
= label
;
440 frchain_now
->frch_cfi_data
->last_address
= label
;
443 /* Add a DW_CFA_offset record to the CFI data. */
446 cfi_add_CFA_offset (unsigned regno
, offsetT offset
)
448 unsigned int abs_data_align
;
450 gas_assert (DWARF2_CIE_DATA_ALIGNMENT
!= 0);
451 cfi_add_CFA_insn_reg_offset (DW_CFA_offset
, regno
, offset
);
453 abs_data_align
= (DWARF2_CIE_DATA_ALIGNMENT
< 0
454 ? -DWARF2_CIE_DATA_ALIGNMENT
: DWARF2_CIE_DATA_ALIGNMENT
);
455 if (offset
% abs_data_align
)
456 as_bad (_("register save offset not a multiple of %u"), abs_data_align
);
459 /* Add a DW_CFA_def_cfa record to the CFI data. */
462 cfi_add_CFA_def_cfa (unsigned regno
, offsetT offset
)
464 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa
, regno
, offset
);
465 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
468 /* Add a DW_CFA_register record to the CFI data. */
471 cfi_add_CFA_register (unsigned reg1
, unsigned reg2
)
473 cfi_add_CFA_insn_reg_reg (DW_CFA_register
, reg1
, reg2
);
476 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
479 cfi_add_CFA_def_cfa_register (unsigned regno
)
481 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register
, regno
);
484 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
487 cfi_add_CFA_def_cfa_offset (offsetT offset
)
489 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset
, offset
);
490 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
494 cfi_add_CFA_restore (unsigned regno
)
496 cfi_add_CFA_insn_reg (DW_CFA_restore
, regno
);
500 cfi_add_CFA_undefined (unsigned regno
)
502 cfi_add_CFA_insn_reg (DW_CFA_undefined
, regno
);
506 cfi_add_CFA_same_value (unsigned regno
)
508 cfi_add_CFA_insn_reg (DW_CFA_same_value
, regno
);
512 cfi_add_CFA_remember_state (void)
514 struct cfa_save_data
*p
;
516 cfi_add_CFA_insn (DW_CFA_remember_state
);
518 p
= (struct cfa_save_data
*) xmalloc (sizeof (*p
));
519 p
->cfa_offset
= frchain_now
->frch_cfi_data
->cur_cfa_offset
;
520 p
->next
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
521 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
;
525 cfi_add_CFA_restore_state (void)
527 struct cfa_save_data
*p
;
529 cfi_add_CFA_insn (DW_CFA_restore_state
);
531 p
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
534 frchain_now
->frch_cfi_data
->cur_cfa_offset
= p
->cfa_offset
;
535 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
->next
;
539 as_bad (_("CFI state restore without previous remember"));
543 /* Parse CFI assembler directives. */
545 static void dot_cfi (int);
546 static void dot_cfi_escape (int);
547 static void dot_cfi_sections (int);
548 static void dot_cfi_startproc (int);
549 static void dot_cfi_endproc (int);
550 static void dot_cfi_personality (int);
551 static void dot_cfi_lsda (int);
552 static void dot_cfi_val_encoded_addr (int);
554 const pseudo_typeS cfi_pseudo_table
[] =
556 { "cfi_sections", dot_cfi_sections
, 0 },
557 { "cfi_startproc", dot_cfi_startproc
, 0 },
558 { "cfi_endproc", dot_cfi_endproc
, 0 },
559 { "cfi_def_cfa", dot_cfi
, DW_CFA_def_cfa
},
560 { "cfi_def_cfa_register", dot_cfi
, DW_CFA_def_cfa_register
},
561 { "cfi_def_cfa_offset", dot_cfi
, DW_CFA_def_cfa_offset
},
562 { "cfi_adjust_cfa_offset", dot_cfi
, CFI_adjust_cfa_offset
},
563 { "cfi_offset", dot_cfi
, DW_CFA_offset
},
564 { "cfi_rel_offset", dot_cfi
, CFI_rel_offset
},
565 { "cfi_register", dot_cfi
, DW_CFA_register
},
566 { "cfi_return_column", dot_cfi
, CFI_return_column
},
567 { "cfi_restore", dot_cfi
, DW_CFA_restore
},
568 { "cfi_undefined", dot_cfi
, DW_CFA_undefined
},
569 { "cfi_same_value", dot_cfi
, DW_CFA_same_value
},
570 { "cfi_remember_state", dot_cfi
, DW_CFA_remember_state
},
571 { "cfi_restore_state", dot_cfi
, DW_CFA_restore_state
},
572 { "cfi_window_save", dot_cfi
, DW_CFA_GNU_window_save
},
573 { "cfi_escape", dot_cfi_escape
, 0 },
574 { "cfi_signal_frame", dot_cfi
, CFI_signal_frame
},
575 { "cfi_personality", dot_cfi_personality
, 0 },
576 { "cfi_lsda", dot_cfi_lsda
, 0 },
577 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr
, 0 },
582 cfi_parse_separator (void)
585 if (*input_line_pointer
== ',')
586 input_line_pointer
++;
588 as_bad (_("missing separator"));
591 #ifndef tc_parse_to_dw2regnum
593 tc_parse_to_dw2regnum (expressionS
*exp
)
595 # ifdef tc_regname_to_dw2regnum
597 if (is_name_beginner (*input_line_pointer
)
598 || (*input_line_pointer
== '%'
599 && is_name_beginner (*++input_line_pointer
)))
603 name
= input_line_pointer
;
604 c
= get_symbol_end ();
606 exp
->X_op
= O_constant
;
607 exp
->X_add_number
= tc_regname_to_dw2regnum (name
);
609 *input_line_pointer
= c
;
613 expression_and_evaluate (exp
);
623 tc_parse_to_dw2regnum (&exp
);
628 regno
= exp
.X_add_number
;
638 as_bad (_("bad register expression"));
646 cfi_parse_const (void)
648 return get_absolute_expression ();
657 if (frchain_now
->frch_cfi_data
== NULL
)
659 as_bad (_("CFI instruction used without previous .cfi_startproc"));
660 ignore_rest_of_line ();
664 /* If the last address was not at the current PC, advance to current. */
665 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
666 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
668 cfi_add_advance_loc (symbol_temp_new_now ());
673 reg1
= cfi_parse_reg ();
674 cfi_parse_separator ();
675 offset
= cfi_parse_const ();
676 cfi_add_CFA_offset (reg1
, offset
);
680 reg1
= cfi_parse_reg ();
681 cfi_parse_separator ();
682 offset
= cfi_parse_const ();
683 cfi_add_CFA_offset (reg1
,
684 offset
- frchain_now
->frch_cfi_data
->cur_cfa_offset
);
688 reg1
= cfi_parse_reg ();
689 cfi_parse_separator ();
690 offset
= cfi_parse_const ();
691 cfi_add_CFA_def_cfa (reg1
, offset
);
694 case DW_CFA_register
:
695 reg1
= cfi_parse_reg ();
696 cfi_parse_separator ();
697 reg2
= cfi_parse_reg ();
698 cfi_add_CFA_register (reg1
, reg2
);
701 case DW_CFA_def_cfa_register
:
702 reg1
= cfi_parse_reg ();
703 cfi_add_CFA_def_cfa_register (reg1
);
706 case DW_CFA_def_cfa_offset
:
707 offset
= cfi_parse_const ();
708 cfi_add_CFA_def_cfa_offset (offset
);
711 case CFI_adjust_cfa_offset
:
712 offset
= cfi_parse_const ();
713 cfi_add_CFA_def_cfa_offset (frchain_now
->frch_cfi_data
->cur_cfa_offset
720 reg1
= cfi_parse_reg ();
721 cfi_add_CFA_restore (reg1
);
723 if (*input_line_pointer
!= ',')
725 ++input_line_pointer
;
729 case DW_CFA_undefined
:
732 reg1
= cfi_parse_reg ();
733 cfi_add_CFA_undefined (reg1
);
735 if (*input_line_pointer
!= ',')
737 ++input_line_pointer
;
741 case DW_CFA_same_value
:
742 reg1
= cfi_parse_reg ();
743 cfi_add_CFA_same_value (reg1
);
746 case CFI_return_column
:
747 reg1
= cfi_parse_reg ();
748 cfi_set_return_column (reg1
);
751 case DW_CFA_remember_state
:
752 cfi_add_CFA_remember_state ();
755 case DW_CFA_restore_state
:
756 cfi_add_CFA_restore_state ();
759 case DW_CFA_GNU_window_save
:
760 cfi_add_CFA_insn (DW_CFA_GNU_window_save
);
763 case CFI_signal_frame
:
764 frchain_now
->frch_cfi_data
->cur_fde_data
->signal_frame
= 1;
771 demand_empty_rest_of_line ();
775 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED
)
777 struct cfi_escape_data
*head
, **tail
, *e
;
778 struct cfi_insn_data
*insn
;
780 if (frchain_now
->frch_cfi_data
== NULL
)
782 as_bad (_("CFI instruction used without previous .cfi_startproc"));
783 ignore_rest_of_line ();
787 /* If the last address was not at the current PC, advance to current. */
788 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
789 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
791 cfi_add_advance_loc (symbol_temp_new_now ());
796 e
= (struct cfi_escape_data
*) xmalloc (sizeof (*e
));
797 do_parse_cons_expression (&e
->exp
, 1);
801 while (*input_line_pointer
++ == ',');
804 insn
= alloc_cfi_insn_data ();
805 insn
->insn
= CFI_escape
;
808 --input_line_pointer
;
809 demand_empty_rest_of_line ();
813 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED
)
815 struct fde_entry
*fde
;
818 if (frchain_now
->frch_cfi_data
== NULL
)
820 as_bad (_("CFI instruction used without previous .cfi_startproc"));
821 ignore_rest_of_line ();
825 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
826 encoding
= cfi_parse_const ();
827 if (encoding
== DW_EH_PE_omit
)
829 demand_empty_rest_of_line ();
830 fde
->per_encoding
= encoding
;
834 if ((encoding
& 0xff) != encoding
835 || ((encoding
& 0x70) != 0
836 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
837 && (encoding
& 0x70) != DW_EH_PE_pcrel
840 /* leb128 can be handled, but does something actually need it? */
841 || (encoding
& 7) == DW_EH_PE_uleb128
842 || (encoding
& 7) > DW_EH_PE_udata8
)
844 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
845 ignore_rest_of_line ();
849 if (*input_line_pointer
++ != ',')
851 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
852 ignore_rest_of_line ();
856 expression_and_evaluate (&fde
->personality
);
857 switch (fde
->personality
.X_op
)
862 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
863 encoding
= DW_EH_PE_omit
;
866 encoding
= DW_EH_PE_omit
;
870 fde
->per_encoding
= encoding
;
872 if (encoding
== DW_EH_PE_omit
)
874 as_bad (_("wrong second argument to .cfi_personality"));
875 ignore_rest_of_line ();
879 demand_empty_rest_of_line ();
883 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED
)
885 struct fde_entry
*fde
;
888 if (frchain_now
->frch_cfi_data
== NULL
)
890 as_bad (_("CFI instruction used without previous .cfi_startproc"));
891 ignore_rest_of_line ();
895 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
896 encoding
= cfi_parse_const ();
897 if (encoding
== DW_EH_PE_omit
)
899 demand_empty_rest_of_line ();
900 fde
->lsda_encoding
= encoding
;
904 if ((encoding
& 0xff) != encoding
905 || ((encoding
& 0x70) != 0
906 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
907 && (encoding
& 0x70) != DW_EH_PE_pcrel
910 /* leb128 can be handled, but does something actually need it? */
911 || (encoding
& 7) == DW_EH_PE_uleb128
912 || (encoding
& 7) > DW_EH_PE_udata8
)
914 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
915 ignore_rest_of_line ();
919 if (*input_line_pointer
++ != ',')
921 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
922 ignore_rest_of_line ();
926 fde
->lsda_encoding
= encoding
;
928 expression_and_evaluate (&fde
->lsda
);
929 switch (fde
->lsda
.X_op
)
934 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
935 encoding
= DW_EH_PE_omit
;
938 encoding
= DW_EH_PE_omit
;
942 fde
->lsda_encoding
= encoding
;
944 if (encoding
== DW_EH_PE_omit
)
946 as_bad (_("wrong second argument to .cfi_lsda"));
947 ignore_rest_of_line ();
951 demand_empty_rest_of_line ();
955 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED
)
957 struct cfi_insn_data
*insn_ptr
;
960 if (frchain_now
->frch_cfi_data
== NULL
)
962 as_bad (_("CFI instruction used without previous .cfi_startproc"));
963 ignore_rest_of_line ();
967 /* If the last address was not at the current PC, advance to current. */
968 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
969 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
971 cfi_add_advance_loc (symbol_temp_new_now ());
973 insn_ptr
= alloc_cfi_insn_data ();
974 insn_ptr
->insn
= CFI_val_encoded_addr
;
976 insn_ptr
->u
.ea
.reg
= cfi_parse_reg ();
978 cfi_parse_separator ();
979 encoding
= cfi_parse_const ();
980 if ((encoding
& 0xff) != encoding
981 || ((encoding
& 0x70) != 0
982 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
983 && (encoding
& 0x70) != DW_EH_PE_pcrel
986 /* leb128 can be handled, but does something actually need it? */
987 || (encoding
& 7) == DW_EH_PE_uleb128
988 || (encoding
& 7) > DW_EH_PE_udata8
)
990 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
991 encoding
= DW_EH_PE_omit
;
994 cfi_parse_separator ();
995 expression_and_evaluate (&insn_ptr
->u
.ea
.exp
);
996 switch (insn_ptr
->u
.ea
.exp
.X_op
)
1001 if ((encoding
& 0x70) != DW_EH_PE_pcrel
)
1004 encoding
= DW_EH_PE_omit
;
1008 insn_ptr
->u
.ea
.encoding
= encoding
;
1009 if (encoding
== DW_EH_PE_omit
)
1011 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1012 ignore_rest_of_line ();
1016 demand_empty_rest_of_line ();
1019 /* By default emit .eh_frame only, not .debug_frame. */
1020 #define CFI_EMIT_eh_frame (1 << 0)
1021 #define CFI_EMIT_debug_frame (1 << 1)
1022 #define CFI_EMIT_target (1 << 2)
1023 static int cfi_sections
= CFI_EMIT_eh_frame
;
1026 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED
)
1031 if (is_name_beginner (*input_line_pointer
))
1036 name
= input_line_pointer
;
1037 c
= get_symbol_end ();
1039 if (strncmp (name
, ".eh_frame", sizeof ".eh_frame") == 0
1041 sections
|= CFI_EMIT_eh_frame
;
1042 else if (strncmp (name
, ".debug_frame", sizeof ".debug_frame") == 0)
1043 sections
|= CFI_EMIT_debug_frame
;
1044 #ifdef tc_cfi_section_name
1045 else if (strcmp (name
, tc_cfi_section_name
) == 0)
1046 sections
|= CFI_EMIT_target
;
1050 *input_line_pointer
= c
;
1051 input_line_pointer
= name
;
1055 *input_line_pointer
= c
;
1057 if (*input_line_pointer
== ',')
1059 name
= input_line_pointer
++;
1061 if (!is_name_beginner (*input_line_pointer
))
1063 input_line_pointer
= name
;
1067 else if (is_name_beginner (*input_line_pointer
))
1071 demand_empty_rest_of_line ();
1072 cfi_sections
= sections
;
1076 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED
)
1080 if (frchain_now
->frch_cfi_data
!= NULL
)
1082 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1083 ignore_rest_of_line ();
1087 cfi_new_fde (symbol_temp_new_now ());
1090 if (is_name_beginner (*input_line_pointer
))
1094 name
= input_line_pointer
;
1095 c
= get_symbol_end ();
1097 if (strcmp (name
, "simple") == 0)
1100 *input_line_pointer
= c
;
1103 input_line_pointer
= name
;
1105 demand_empty_rest_of_line ();
1107 frchain_now
->frch_cfi_data
->cur_cfa_offset
= 0;
1109 tc_cfi_frame_initial_instructions ();
1111 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1112 tc_cfi_startproc ();
1116 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED
)
1118 struct fde_entry
*fde
;
1120 if (frchain_now
->frch_cfi_data
== NULL
)
1122 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1123 ignore_rest_of_line ();
1127 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1129 cfi_end_fde (symbol_temp_new_now ());
1131 demand_empty_rest_of_line ();
1133 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1134 tc_cfi_endproc (fde
);
1138 /* Emit a single byte into the current segment. */
1143 FRAG_APPEND_1_CHAR (byte
);
1146 /* Emit a two-byte word into the current segment. */
1151 md_number_to_chars (frag_more (2), data
, 2);
1154 /* Emit a four byte word into the current segment. */
1159 md_number_to_chars (frag_more (4), data
, 4);
1162 /* Emit an unsigned "little-endian base 128" number. */
1165 out_uleb128 (addressT value
)
1167 output_leb128 (frag_more (sizeof_leb128 (value
, 0)), value
, 0);
1170 /* Emit an unsigned "little-endian base 128" number. */
1173 out_sleb128 (offsetT value
)
1175 output_leb128 (frag_more (sizeof_leb128 (value
, 1)), value
, 1);
1179 output_cfi_insn (struct cfi_insn_data
*insn
)
1186 case DW_CFA_advance_loc
:
1188 symbolS
*from
= insn
->u
.ll
.lab1
;
1189 symbolS
*to
= insn
->u
.ll
.lab2
;
1191 if (symbol_get_frag (to
) == symbol_get_frag (from
))
1193 addressT delta
= S_GET_VALUE (to
) - S_GET_VALUE (from
);
1194 addressT scaled
= delta
/ DWARF2_LINE_MIN_INSN_LENGTH
;
1197 out_one (DW_CFA_advance_loc
+ scaled
);
1198 else if (scaled
<= 0xFF)
1200 out_one (DW_CFA_advance_loc1
);
1203 else if (scaled
<= 0xFFFF)
1205 out_one (DW_CFA_advance_loc2
);
1210 out_one (DW_CFA_advance_loc4
);
1218 exp
.X_op
= O_subtract
;
1219 exp
.X_add_symbol
= to
;
1220 exp
.X_op_symbol
= from
;
1221 exp
.X_add_number
= 0;
1223 /* The code in ehopt.c expects that one byte of the encoding
1224 is already allocated to the frag. This comes from the way
1225 that it scans the .eh_frame section looking first for the
1226 .byte DW_CFA_advance_loc4. */
1227 *frag_more (1) = DW_CFA_advance_loc4
;
1229 frag_var (rs_cfa
, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH
<< 3,
1230 make_expr_symbol (&exp
), frag_now_fix () - 1,
1236 case DW_CFA_def_cfa
:
1237 offset
= insn
->u
.ri
.offset
;
1240 out_one (DW_CFA_def_cfa_sf
);
1241 out_uleb128 (insn
->u
.ri
.reg
);
1242 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1246 out_one (DW_CFA_def_cfa
);
1247 out_uleb128 (insn
->u
.ri
.reg
);
1248 out_uleb128 (offset
);
1252 case DW_CFA_def_cfa_register
:
1253 case DW_CFA_undefined
:
1254 case DW_CFA_same_value
:
1255 out_one (insn
->insn
);
1256 out_uleb128 (insn
->u
.r
);
1259 case DW_CFA_def_cfa_offset
:
1263 out_one (DW_CFA_def_cfa_offset_sf
);
1264 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1268 out_one (DW_CFA_def_cfa_offset
);
1269 out_uleb128 (offset
);
1273 case DW_CFA_restore
:
1277 out_one (DW_CFA_restore
+ regno
);
1281 out_one (DW_CFA_restore_extended
);
1282 out_uleb128 (regno
);
1287 regno
= insn
->u
.ri
.reg
;
1288 offset
= insn
->u
.ri
.offset
/ DWARF2_CIE_DATA_ALIGNMENT
;
1291 out_one (DW_CFA_offset_extended_sf
);
1292 out_uleb128 (regno
);
1293 out_sleb128 (offset
);
1295 else if (regno
<= 0x3F)
1297 out_one (DW_CFA_offset
+ regno
);
1298 out_uleb128 (offset
);
1302 out_one (DW_CFA_offset_extended
);
1303 out_uleb128 (regno
);
1304 out_uleb128 (offset
);
1308 case DW_CFA_register
:
1309 out_one (DW_CFA_register
);
1310 out_uleb128 (insn
->u
.rr
.reg1
);
1311 out_uleb128 (insn
->u
.rr
.reg2
);
1314 case DW_CFA_remember_state
:
1315 case DW_CFA_restore_state
:
1316 out_one (insn
->insn
);
1319 case DW_CFA_GNU_window_save
:
1320 out_one (DW_CFA_GNU_window_save
);
1325 struct cfi_escape_data
*e
;
1326 for (e
= insn
->u
.esc
; e
; e
= e
->next
)
1327 emit_expr (&e
->exp
, 1);
1331 case CFI_val_encoded_addr
:
1333 unsigned encoding
= insn
->u
.ea
.encoding
;
1334 offsetT encoding_size
;
1336 if (encoding
== DW_EH_PE_omit
)
1338 out_one (DW_CFA_val_expression
);
1339 out_uleb128 (insn
->u
.ea
.reg
);
1341 switch (encoding
& 0x7)
1343 case DW_EH_PE_absptr
:
1344 encoding_size
= DWARF2_ADDR_SIZE (stdoutput
);
1346 case DW_EH_PE_udata2
:
1349 case DW_EH_PE_udata4
:
1352 case DW_EH_PE_udata8
:
1359 /* If the user has requested absolute encoding,
1360 then use the smaller DW_OP_addr encoding. */
1361 if (insn
->u
.ea
.encoding
== DW_EH_PE_absptr
)
1363 out_uleb128 (1 + encoding_size
);
1364 out_one (DW_OP_addr
);
1368 out_uleb128 (1 + 1 + encoding_size
);
1369 out_one (DW_OP_GNU_encoded_addr
);
1372 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1374 #if CFI_DIFF_EXPR_OK
1375 insn
->u
.ea
.exp
.X_op
= O_subtract
;
1376 insn
->u
.ea
.exp
.X_op_symbol
= symbol_temp_new_now ();
1377 #elif defined (tc_cfi_emit_pcrel_expr)
1378 tc_cfi_emit_pcrel_expr (&insn
->u
.ea
.exp
, encoding_size
);
1385 emit_expr (&insn
->u
.ea
.exp
, encoding_size
);
1395 encoding_size (unsigned char encoding
)
1397 if (encoding
== DW_EH_PE_omit
)
1399 switch (encoding
& 0x7)
1402 return bfd_get_arch_size (stdoutput
) == 64 ? 8 : 4;
1403 case DW_EH_PE_udata2
:
1405 case DW_EH_PE_udata4
:
1407 case DW_EH_PE_udata8
:
1415 output_cie (struct cie_entry
*cie
, bfd_boolean eh_frame
, int align
)
1417 symbolS
*after_size_address
, *end_address
;
1419 struct cfi_insn_data
*i
;
1420 offsetT augmentation_size
;
1422 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1424 cie
->start_address
= symbol_temp_new_now ();
1425 after_size_address
= symbol_temp_make ();
1426 end_address
= symbol_temp_make ();
1428 exp
.X_op
= O_subtract
;
1429 exp
.X_add_symbol
= end_address
;
1430 exp
.X_op_symbol
= after_size_address
;
1431 exp
.X_add_number
= 0;
1433 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1434 emit_expr (&exp
, 4); /* Length. */
1437 if (fmt
== dwarf2_format_64bit
)
1439 emit_expr (&exp
, 8); /* Length. */
1441 symbol_set_value_now (after_size_address
);
1443 out_four (0); /* CIE id. */
1446 out_four (-1); /* CIE id. */
1447 if (fmt
!= dwarf2_format_32bit
)
1450 out_one (DW_CIE_VERSION
); /* Version. */
1453 out_one ('z'); /* Augmentation. */
1454 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1456 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1460 if (cie
->signal_frame
)
1463 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH
); /* Code alignment. */
1464 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT
); /* Data alignment. */
1465 if (DW_CIE_VERSION
== 1) /* Return column. */
1466 out_one (cie
->return_column
);
1468 out_uleb128 (cie
->return_column
);
1471 augmentation_size
= 1 + (cie
->lsda_encoding
!= DW_EH_PE_omit
);
1472 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1473 augmentation_size
+= 1 + encoding_size (cie
->per_encoding
);
1474 out_uleb128 (augmentation_size
); /* Augmentation size. */
1476 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1478 offsetT size
= encoding_size (cie
->per_encoding
);
1479 out_one (cie
->per_encoding
);
1480 exp
= cie
->personality
;
1481 if ((cie
->per_encoding
& 0x70) == DW_EH_PE_pcrel
)
1483 #if CFI_DIFF_EXPR_OK
1484 exp
.X_op
= O_subtract
;
1485 exp
.X_op_symbol
= symbol_temp_new_now ();
1486 emit_expr (&exp
, size
);
1487 #elif defined (tc_cfi_emit_pcrel_expr)
1488 tc_cfi_emit_pcrel_expr (&exp
, size
);
1494 emit_expr (&exp
, size
);
1497 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1498 out_one (cie
->lsda_encoding
);
1501 switch (DWARF2_FDE_RELOC_SIZE
)
1504 enc
= DW_EH_PE_sdata2
;
1507 enc
= DW_EH_PE_sdata4
;
1510 enc
= DW_EH_PE_sdata8
;
1515 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1516 enc
|= DW_EH_PE_pcrel
;
1523 for (i
= cie
->first
; i
!= cie
->last
; i
= i
->next
)
1525 if (CUR_SEG (i
) != CUR_SEG (cie
))
1527 output_cfi_insn (i
);
1531 frag_align (align
, DW_CFA_nop
, 0);
1532 symbol_set_value_now (end_address
);
1536 output_fde (struct fde_entry
*fde
, struct cie_entry
*cie
,
1537 bfd_boolean eh_frame
, struct cfi_insn_data
*first
,
1540 symbolS
*after_size_address
, *end_address
;
1542 offsetT augmentation_size
;
1543 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1547 after_size_address
= symbol_temp_make ();
1548 end_address
= symbol_temp_make ();
1550 exp
.X_op
= O_subtract
;
1551 exp
.X_add_symbol
= end_address
;
1552 exp
.X_op_symbol
= after_size_address
;
1553 exp
.X_add_number
= 0;
1554 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1558 if (fmt
== dwarf2_format_64bit
)
1562 emit_expr (&exp
, offset_size
); /* Length. */
1563 symbol_set_value_now (after_size_address
);
1567 exp
.X_op
= O_subtract
;
1568 exp
.X_add_symbol
= after_size_address
;
1569 exp
.X_op_symbol
= cie
->start_address
;
1570 exp
.X_add_number
= 0;
1571 emit_expr (&exp
, offset_size
); /* CIE offset. */
1575 TC_DWARF2_EMIT_OFFSET (cie
->start_address
, offset_size
);
1580 exp
.X_op
= O_subtract
;
1581 exp
.X_add_number
= 0;
1582 #if CFI_DIFF_EXPR_OK
1583 exp
.X_add_symbol
= fde
->start_address
;
1584 exp
.X_op_symbol
= symbol_temp_new_now ();
1585 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1587 exp
.X_op
= O_symbol
;
1588 exp
.X_add_symbol
= fde
->start_address
;
1589 #ifdef tc_cfi_emit_pcrel_expr
1590 tc_cfi_emit_pcrel_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1592 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1595 addr_size
= DWARF2_FDE_RELOC_SIZE
;
1599 exp
.X_op
= O_symbol
;
1600 exp
.X_add_symbol
= fde
->start_address
;
1601 exp
.X_add_number
= 0;
1602 addr_size
= DWARF2_ADDR_SIZE (stdoutput
);
1603 emit_expr (&exp
, addr_size
);
1606 exp
.X_op
= O_subtract
;
1607 exp
.X_add_symbol
= fde
->end_address
;
1608 exp
.X_op_symbol
= fde
->start_address
; /* Code length. */
1609 exp
.X_add_number
= 0;
1610 emit_expr (&exp
, addr_size
);
1612 augmentation_size
= encoding_size (fde
->lsda_encoding
);
1614 out_uleb128 (augmentation_size
); /* Augmentation size. */
1616 if (fde
->lsda_encoding
!= DW_EH_PE_omit
)
1619 if ((fde
->lsda_encoding
& 0x70) == DW_EH_PE_pcrel
)
1621 #if CFI_DIFF_LSDA_OK
1622 exp
.X_op
= O_subtract
;
1623 exp
.X_op_symbol
= symbol_temp_new_now ();
1624 emit_expr (&exp
, augmentation_size
);
1625 #elif defined (tc_cfi_emit_pcrel_expr)
1626 tc_cfi_emit_pcrel_expr (&exp
, augmentation_size
);
1632 emit_expr (&exp
, augmentation_size
);
1635 for (; first
; first
= first
->next
)
1636 if (CUR_SEG (first
) == CUR_SEG (fde
))
1637 output_cfi_insn (first
);
1639 frag_align (align
, DW_CFA_nop
, 0);
1640 symbol_set_value_now (end_address
);
1643 static struct cie_entry
*
1644 select_cie_for_fde (struct fde_entry
*fde
, bfd_boolean eh_frame
,
1645 struct cfi_insn_data
**pfirst
, int align
)
1647 struct cfi_insn_data
*i
, *j
;
1648 struct cie_entry
*cie
;
1650 for (cie
= cie_root
; cie
; cie
= cie
->next
)
1652 if (CUR_SEG (cie
) != CUR_SEG (fde
))
1654 if (cie
->return_column
!= fde
->return_column
1655 || cie
->signal_frame
!= fde
->signal_frame
1656 || cie
->per_encoding
!= fde
->per_encoding
1657 || cie
->lsda_encoding
!= fde
->lsda_encoding
)
1659 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1661 if (cie
->personality
.X_op
!= fde
->personality
.X_op
1662 || cie
->personality
.X_add_number
1663 != fde
->personality
.X_add_number
)
1665 switch (cie
->personality
.X_op
)
1668 if (cie
->personality
.X_unsigned
!= fde
->personality
.X_unsigned
)
1672 if (cie
->personality
.X_add_symbol
1673 != fde
->personality
.X_add_symbol
)
1680 for (i
= cie
->first
, j
= fde
->data
;
1681 i
!= cie
->last
&& j
!= NULL
;
1682 i
= i
->next
, j
= j
->next
)
1684 if (i
->insn
!= j
->insn
)
1688 case DW_CFA_advance_loc
:
1689 case DW_CFA_remember_state
:
1690 /* We reached the first advance/remember in the FDE,
1691 but did not reach the end of the CIE list. */
1695 case DW_CFA_def_cfa
:
1696 if (i
->u
.ri
.reg
!= j
->u
.ri
.reg
)
1698 if (i
->u
.ri
.offset
!= j
->u
.ri
.offset
)
1702 case DW_CFA_register
:
1703 if (i
->u
.rr
.reg1
!= j
->u
.rr
.reg1
)
1705 if (i
->u
.rr
.reg2
!= j
->u
.rr
.reg2
)
1709 case DW_CFA_def_cfa_register
:
1710 case DW_CFA_restore
:
1711 case DW_CFA_undefined
:
1712 case DW_CFA_same_value
:
1713 if (i
->u
.r
!= j
->u
.r
)
1717 case DW_CFA_def_cfa_offset
:
1718 if (i
->u
.i
!= j
->u
.i
)
1723 case CFI_val_encoded_addr
:
1724 /* Don't bother matching these for now. */
1732 /* Success if we reached the end of the CIE list, and we've either
1733 run out of FDE entries or we've encountered an advance,
1734 remember, or escape. */
1737 || j
->insn
== DW_CFA_advance_loc
1738 || j
->insn
== DW_CFA_remember_state
1739 || j
->insn
== CFI_escape
1740 || j
->insn
== CFI_val_encoded_addr
))
1749 cie
= (struct cie_entry
*) xmalloc (sizeof (struct cie_entry
));
1750 cie
->next
= cie_root
;
1752 SET_CUR_SEG (cie
, CUR_SEG (fde
));
1753 cie
->return_column
= fde
->return_column
;
1754 cie
->signal_frame
= fde
->signal_frame
;
1755 cie
->per_encoding
= fde
->per_encoding
;
1756 cie
->lsda_encoding
= fde
->lsda_encoding
;
1757 cie
->personality
= fde
->personality
;
1758 cie
->first
= fde
->data
;
1760 for (i
= cie
->first
; i
; i
= i
->next
)
1761 if (i
->insn
== DW_CFA_advance_loc
1762 || i
->insn
== DW_CFA_remember_state
1763 || i
->insn
== CFI_escape
1764 || i
->insn
== CFI_val_encoded_addr
)
1770 output_cie (cie
, eh_frame
, align
);
1775 #ifdef md_reg_eh_frame_to_debug_frame
1777 cfi_change_reg_numbers (struct cfi_insn_data
*insn
, segT ccseg
)
1779 for (; insn
; insn
= insn
->next
)
1781 if (CUR_SEG (insn
) != ccseg
)
1785 case DW_CFA_advance_loc
:
1786 case DW_CFA_def_cfa_offset
:
1787 case DW_CFA_remember_state
:
1788 case DW_CFA_restore_state
:
1789 case DW_CFA_GNU_window_save
:
1793 case DW_CFA_def_cfa
:
1795 insn
->u
.ri
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ri
.reg
);
1798 case DW_CFA_def_cfa_register
:
1799 case DW_CFA_undefined
:
1800 case DW_CFA_same_value
:
1801 case DW_CFA_restore
:
1802 insn
->u
.r
= md_reg_eh_frame_to_debug_frame (insn
->u
.r
);
1805 case DW_CFA_register
:
1806 insn
->u
.rr
.reg1
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg1
);
1807 insn
->u
.rr
.reg2
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg2
);
1810 case CFI_val_encoded_addr
:
1811 insn
->u
.ea
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ea
.reg
);
1820 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
1824 get_cfi_seg (segT cseg
, const char *base
, flagword flags
, int align
)
1826 if (SUPPORT_FRAME_LINKONCE
)
1828 struct dwcfi_seg_list
*l
;
1830 l
= dwcfi_hash_find_or_make (cseg
, base
, flags
);
1833 subseg_set (cseg
, l
->subseg
);
1837 cseg
= subseg_new (base
, 0);
1838 bfd_set_section_flags (stdoutput
, cseg
, flags
);
1840 record_alignment (cseg
, align
);
1847 struct cie_entry
*cie
, *cie_next
;
1848 segT cfi_seg
, ccseg
;
1849 struct fde_entry
*fde
;
1850 struct cfi_insn_data
*first
;
1851 int save_flag_traditional_format
, seek_next_seg
;
1853 if (all_fde_data
== 0)
1856 if ((cfi_sections
& CFI_EMIT_eh_frame
) != 0)
1858 /* Make sure check_eh_frame doesn't do anything with our output. */
1859 save_flag_traditional_format
= flag_traditional_format
;
1860 flag_traditional_format
= 1;
1862 if (!SUPPORT_FRAME_LINKONCE
)
1864 /* Open .eh_frame section. */
1865 cfi_seg
= get_cfi_seg (NULL
, ".eh_frame",
1866 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
1867 | DWARF2_EH_FRAME_READ_ONLY
),
1868 EH_FRAME_ALIGNMENT
);
1869 #ifdef md_fix_up_eh_frame
1870 md_fix_up_eh_frame (cfi_seg
);
1881 for (cie
= cie_root
; cie
; cie
= cie_next
)
1883 cie_next
= cie
->next
;
1884 free ((void *) cie
);
1888 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1890 if (SUPPORT_FRAME_LINKONCE
)
1894 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
1901 ccseg
= CUR_SEG (fde
);
1902 /* Open .eh_frame section. */
1903 cfi_seg
= get_cfi_seg (ccseg
, ".eh_frame",
1904 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
1905 | DWARF2_EH_FRAME_READ_ONLY
),
1906 EH_FRAME_ALIGNMENT
);
1907 #ifdef md_fix_up_eh_frame
1908 md_fix_up_eh_frame (cfi_seg
);
1914 SET_HANDLED (fde
, 1);
1917 if (fde
->end_address
== NULL
)
1919 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1920 fde
->end_address
= fde
->start_address
;
1923 cie
= select_cie_for_fde (fde
, TRUE
, &first
, 2);
1924 output_fde (fde
, cie
, TRUE
, first
,
1925 fde
->next
== NULL
? EH_FRAME_ALIGNMENT
: 2);
1928 while (SUPPORT_FRAME_LINKONCE
&& seek_next_seg
== 2);
1930 if (SUPPORT_FRAME_LINKONCE
)
1931 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1932 SET_HANDLED (fde
, 0);
1934 flag_traditional_format
= save_flag_traditional_format
;
1937 if ((cfi_sections
& CFI_EMIT_debug_frame
) != 0)
1939 int alignment
= ffs (DWARF2_ADDR_SIZE (stdoutput
)) - 1;
1941 if (!SUPPORT_FRAME_LINKONCE
)
1942 get_cfi_seg (NULL
, ".debug_frame",
1943 SEC_READONLY
| SEC_DEBUGGING
,
1951 for (cie
= cie_root
; cie
; cie
= cie_next
)
1953 cie_next
= cie
->next
;
1954 free ((void *) cie
);
1958 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1960 if (SUPPORT_FRAME_LINKONCE
)
1964 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
1971 ccseg
= CUR_SEG (fde
);
1972 /* Open .debug_frame section. */
1973 get_cfi_seg (ccseg
, ".debug_frame",
1974 SEC_READONLY
| SEC_DEBUGGING
,
1978 SET_HANDLED (fde
, 1);
1980 if (fde
->end_address
== NULL
)
1982 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1983 fde
->end_address
= fde
->start_address
;
1986 fde
->per_encoding
= DW_EH_PE_omit
;
1987 fde
->lsda_encoding
= DW_EH_PE_omit
;
1988 cfi_change_reg_numbers (fde
->data
, ccseg
);
1989 cie
= select_cie_for_fde (fde
, FALSE
, &first
, alignment
);
1990 output_fde (fde
, cie
, FALSE
, first
, alignment
);
1993 while (SUPPORT_FRAME_LINKONCE
&& seek_next_seg
== 2);
1995 if (SUPPORT_FRAME_LINKONCE
)
1996 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1997 SET_HANDLED (fde
, 0);
2001 #else /* TARGET_USE_CFIPOP */
2003 /* Emit an intelligible error message for missing support. */
2006 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED
)
2008 as_bad (_("CFI is not supported for this target"));
2009 ignore_rest_of_line ();
2012 const pseudo_typeS cfi_pseudo_table
[] =
2014 { "cfi_sections", dot_cfi_dummy
, 0 },
2015 { "cfi_startproc", dot_cfi_dummy
, 0 },
2016 { "cfi_endproc", dot_cfi_dummy
, 0 },
2017 { "cfi_def_cfa", dot_cfi_dummy
, 0 },
2018 { "cfi_def_cfa_register", dot_cfi_dummy
, 0 },
2019 { "cfi_def_cfa_offset", dot_cfi_dummy
, 0 },
2020 { "cfi_adjust_cfa_offset", dot_cfi_dummy
, 0 },
2021 { "cfi_offset", dot_cfi_dummy
, 0 },
2022 { "cfi_rel_offset", dot_cfi_dummy
, 0 },
2023 { "cfi_register", dot_cfi_dummy
, 0 },
2024 { "cfi_return_column", dot_cfi_dummy
, 0 },
2025 { "cfi_restore", dot_cfi_dummy
, 0 },
2026 { "cfi_undefined", dot_cfi_dummy
, 0 },
2027 { "cfi_same_value", dot_cfi_dummy
, 0 },
2028 { "cfi_remember_state", dot_cfi_dummy
, 0 },
2029 { "cfi_restore_state", dot_cfi_dummy
, 0 },
2030 { "cfi_window_save", dot_cfi_dummy
, 0 },
2031 { "cfi_escape", dot_cfi_dummy
, 0 },
2032 { "cfi_signal_frame", dot_cfi_dummy
, 0 },
2033 { "cfi_personality", dot_cfi_dummy
, 0 },
2034 { "cfi_lsda", dot_cfi_dummy
, 0 },
2035 { "cfi_val_encoded_addr", dot_cfi_dummy
, 0 },
2043 #endif /* TARGET_USE_CFIPOP */