1 /* dw2gencfi.c - Support for generating Dwarf2 CFI information.
2 Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Michal Ludvig <mludvig@suse.cz>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "dw2gencfi.h"
26 #include "dwarf2dbg.h"
28 #ifdef TARGET_USE_CFIPOP
30 /* By default, use difference expressions if DIFF_EXPR_OK is defined. */
31 #ifndef CFI_DIFF_EXPR_OK
33 # define CFI_DIFF_EXPR_OK 1
35 # define CFI_DIFF_EXPR_OK 0
39 #ifndef CFI_DIFF_LSDA_OK
40 #define CFI_DIFF_LSDA_OK CFI_DIFF_EXPR_OK
43 #if CFI_DIFF_EXPR_OK == 1 && CFI_DIFF_LSDA_OK == 0
44 # error "CFI_DIFF_EXPR_OK should imply CFI_DIFF_LSDA_OK"
47 /* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field
48 of the CIE. Default to 1 if not otherwise specified. */
49 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
50 #define DWARF2_LINE_MIN_INSN_LENGTH 1
53 /* By default, use 32-bit relocations from .eh_frame into .text. */
54 #ifndef DWARF2_FDE_RELOC_SIZE
55 #define DWARF2_FDE_RELOC_SIZE 4
58 /* By default, use a read-only .eh_frame section. */
59 #ifndef DWARF2_EH_FRAME_READ_ONLY
60 #define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY
63 #ifndef EH_FRAME_ALIGNMENT
64 #define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
67 #ifndef tc_cfi_frame_initial_instructions
68 #define tc_cfi_frame_initial_instructions() ((void)0)
71 #ifndef tc_cfi_startproc
72 # define tc_cfi_startproc() ((void)0)
75 #ifndef tc_cfi_endproc
76 # define tc_cfi_endproc(fde) ((void) (fde))
80 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
83 #ifndef DWARF2_ADDR_SIZE
84 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
87 #if SUPPORT_FRAME_LINKONCE
88 #define CUR_SEG(structp) structp->cur_seg
89 #define SET_CUR_SEG(structp, seg) structp->cur_seg = seg
90 #define HANDLED(structp) structp->handled
91 #define SET_HANDLED(structp, val) structp->handled = val
93 #define CUR_SEG(structp) NULL
94 #define SET_CUR_SEG(structp, seg) (void) (0 && seg)
95 #define HANDLED(structp) 0
96 #define SET_HANDLED(structp, val) (void) (0 && val)
99 /* Private segment collection list. */
100 struct dwcfi_seg_list
107 #define FRAME_NAME ".eh_frame"
109 static struct hash_control
*dwcfi_hash
;
111 /* Build based on segment the derived .debug_...
112 segment name containing origin segment's postfix name part. */
115 get_debugseg_name (segT seg
, const char *base_name
)
126 name
= bfd_get_section_name (stdoutput
, seg
);
128 dollar
= strchr (name
, '$');
129 dot
= strchr (name
+ 1, '.');
137 else if (dot
< dollar
)
143 return concat (base_name
, name
, NULL
);
146 /* Allocate a dwcfi_seg_list structure. */
148 static struct dwcfi_seg_list
*
149 alloc_debugseg_item (segT seg
, int subseg
, char *name
)
151 struct dwcfi_seg_list
*r
;
153 r
= (struct dwcfi_seg_list
*)
154 xmalloc (sizeof (struct dwcfi_seg_list
) + strlen (name
));
162 is_now_linkonce_segment (void)
164 if ((bfd_get_section_flags (stdoutput
, now_seg
)
165 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
166 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
167 | SEC_LINK_DUPLICATES_SAME_CONTENTS
)) != 0)
172 /* Generate debug... segment with same linkonce properties
176 make_debug_seg (segT cseg
, char *name
, int sflags
)
178 segT save_seg
= now_seg
;
179 int save_subseg
= now_subseg
;
183 r
= subseg_new (name
, 0);
185 /* Check if code segment is marked as linked once. */
189 flags
= bfd_get_section_flags (stdoutput
, cseg
)
190 & (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
191 | SEC_LINK_DUPLICATES_ONE_ONLY
| SEC_LINK_DUPLICATES_SAME_SIZE
192 | SEC_LINK_DUPLICATES_SAME_CONTENTS
);
194 /* Add standard section flags. */
197 /* Apply possibly linked once flags to new generated segment, too. */
198 if (!bfd_set_section_flags (stdoutput
, r
, flags
))
199 as_bad (_("bfd_set_section_flags: %s"),
200 bfd_errmsg (bfd_get_error ()));
202 /* Restore to previous segment. */
203 if (save_seg
!= NULL
)
204 subseg_set (save_seg
, save_subseg
);
209 dwcfi_hash_insert (const char *name
, struct dwcfi_seg_list
*item
)
211 const char *error_string
;
213 if ((error_string
= hash_jam (dwcfi_hash
, name
, (char *) item
)))
214 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
218 static struct dwcfi_seg_list
*
219 dwcfi_hash_find (char *name
)
221 return (struct dwcfi_seg_list
*) hash_find (dwcfi_hash
, name
);
224 static struct dwcfi_seg_list
*
225 dwcfi_hash_find_or_make (segT cseg
, const char *base_name
, int flags
)
227 struct dwcfi_seg_list
*item
;
230 /* Initialize dwcfi_hash once. */
232 dwcfi_hash
= hash_new ();
234 name
= get_debugseg_name (cseg
, base_name
);
236 item
= dwcfi_hash_find (name
);
239 item
= alloc_debugseg_item (make_debug_seg (cseg
, name
, flags
), 0, name
);
241 dwcfi_hash_insert (item
->seg_name
, item
);
249 /* ??? Share this with dwarf2cfg.c. */
250 #ifndef TC_DWARF2_EMIT_OFFSET
251 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
253 /* Create an offset to .dwarf2_*. */
256 generic_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
261 exp
.X_add_symbol
= symbol
;
262 exp
.X_add_number
= 0;
263 emit_expr (&exp
, size
);
267 struct cfi_escape_data
269 struct cfi_escape_data
*next
;
275 struct cie_entry
*next
;
276 #if SUPPORT_FRAME_LINKONCE
279 symbolS
*start_address
;
280 unsigned int return_column
;
281 unsigned int signal_frame
;
282 unsigned char per_encoding
;
283 unsigned char lsda_encoding
;
284 expressionS personality
;
285 struct cfi_insn_data
*first
, *last
;
288 /* List of FDE entries. */
290 struct fde_entry
*all_fde_data
;
291 static struct fde_entry
**last_fde_data
= &all_fde_data
;
293 /* List of CIEs so that they could be reused. */
294 static struct cie_entry
*cie_root
;
296 /* Stack of old CFI data, for save/restore. */
299 struct cfa_save_data
*next
;
303 /* Current open FDE entry. */
306 struct fde_entry
*cur_fde_data
;
307 symbolS
*last_address
;
308 offsetT cur_cfa_offset
;
309 struct cfa_save_data
*cfa_save_stack
;
312 /* Construct a new FDE structure and add it to the end of the fde list. */
314 static struct fde_entry
*
315 alloc_fde_entry (void)
317 struct fde_entry
*fde
= (struct fde_entry
*)
318 xcalloc (1, sizeof (struct fde_entry
));
320 frchain_now
->frch_cfi_data
= (struct frch_cfi_data
*)
321 xcalloc (1, sizeof (struct frch_cfi_data
));
322 frchain_now
->frch_cfi_data
->cur_fde_data
= fde
;
323 *last_fde_data
= fde
;
324 last_fde_data
= &fde
->next
;
325 SET_CUR_SEG (fde
, is_now_linkonce_segment ());
326 SET_HANDLED (fde
, 0);
327 fde
->last
= &fde
->data
;
328 fde
->return_column
= DWARF2_DEFAULT_RETURN_COLUMN
;
329 fde
->per_encoding
= DW_EH_PE_omit
;
330 fde
->lsda_encoding
= DW_EH_PE_omit
;
335 /* The following functions are available for a backend to construct its
336 own unwind information, usually from legacy unwind directives. */
338 /* Construct a new INSN structure and add it to the end of the insn list
339 for the currently active FDE. */
341 static struct cfi_insn_data
*
342 alloc_cfi_insn_data (void)
344 struct cfi_insn_data
*insn
= (struct cfi_insn_data
*)
345 xcalloc (1, sizeof (struct cfi_insn_data
));
346 struct fde_entry
*cur_fde_data
= frchain_now
->frch_cfi_data
->cur_fde_data
;
348 *cur_fde_data
->last
= insn
;
349 cur_fde_data
->last
= &insn
->next
;
350 SET_CUR_SEG (insn
, is_now_linkonce_segment ());
354 /* Construct a new FDE structure that begins at LABEL. */
357 cfi_new_fde (symbolS
*label
)
359 struct fde_entry
*fde
= alloc_fde_entry ();
360 fde
->start_address
= label
;
361 frchain_now
->frch_cfi_data
->last_address
= label
;
364 /* End the currently open FDE. */
367 cfi_end_fde (symbolS
*label
)
369 frchain_now
->frch_cfi_data
->cur_fde_data
->end_address
= label
;
370 free (frchain_now
->frch_cfi_data
);
371 frchain_now
->frch_cfi_data
= NULL
;
374 /* Set the return column for the current FDE. */
377 cfi_set_return_column (unsigned regno
)
379 frchain_now
->frch_cfi_data
->cur_fde_data
->return_column
= regno
;
382 /* Universal functions to store new instructions. */
385 cfi_add_CFA_insn (int insn
)
387 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
389 insn_ptr
->insn
= insn
;
393 cfi_add_CFA_insn_reg (int insn
, unsigned regno
)
395 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
397 insn_ptr
->insn
= insn
;
398 insn_ptr
->u
.r
= regno
;
402 cfi_add_CFA_insn_offset (int insn
, offsetT offset
)
404 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
406 insn_ptr
->insn
= insn
;
407 insn_ptr
->u
.i
= offset
;
411 cfi_add_CFA_insn_reg_reg (int insn
, unsigned reg1
, unsigned reg2
)
413 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
415 insn_ptr
->insn
= insn
;
416 insn_ptr
->u
.rr
.reg1
= reg1
;
417 insn_ptr
->u
.rr
.reg2
= reg2
;
421 cfi_add_CFA_insn_reg_offset (int insn
, unsigned regno
, offsetT offset
)
423 struct cfi_insn_data
*insn_ptr
= alloc_cfi_insn_data ();
425 insn_ptr
->insn
= insn
;
426 insn_ptr
->u
.ri
.reg
= regno
;
427 insn_ptr
->u
.ri
.offset
= offset
;
430 /* Add a CFI insn to advance the PC from the last address to LABEL. */
433 cfi_add_advance_loc (symbolS
*label
)
435 struct cfi_insn_data
*insn
= alloc_cfi_insn_data ();
437 insn
->insn
= DW_CFA_advance_loc
;
438 insn
->u
.ll
.lab1
= frchain_now
->frch_cfi_data
->last_address
;
439 insn
->u
.ll
.lab2
= label
;
441 frchain_now
->frch_cfi_data
->last_address
= label
;
444 /* Add a DW_CFA_offset record to the CFI data. */
447 cfi_add_CFA_offset (unsigned regno
, offsetT offset
)
449 unsigned int abs_data_align
;
451 gas_assert (DWARF2_CIE_DATA_ALIGNMENT
!= 0);
452 cfi_add_CFA_insn_reg_offset (DW_CFA_offset
, regno
, offset
);
454 abs_data_align
= (DWARF2_CIE_DATA_ALIGNMENT
< 0
455 ? -DWARF2_CIE_DATA_ALIGNMENT
: DWARF2_CIE_DATA_ALIGNMENT
);
456 if (offset
% abs_data_align
)
457 as_bad (_("register save offset not a multiple of %u"), abs_data_align
);
460 /* Add a DW_CFA_def_cfa record to the CFI data. */
463 cfi_add_CFA_def_cfa (unsigned regno
, offsetT offset
)
465 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa
, regno
, offset
);
466 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
469 /* Add a DW_CFA_register record to the CFI data. */
472 cfi_add_CFA_register (unsigned reg1
, unsigned reg2
)
474 cfi_add_CFA_insn_reg_reg (DW_CFA_register
, reg1
, reg2
);
477 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
480 cfi_add_CFA_def_cfa_register (unsigned regno
)
482 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register
, regno
);
485 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
488 cfi_add_CFA_def_cfa_offset (offsetT offset
)
490 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset
, offset
);
491 frchain_now
->frch_cfi_data
->cur_cfa_offset
= offset
;
495 cfi_add_CFA_restore (unsigned regno
)
497 cfi_add_CFA_insn_reg (DW_CFA_restore
, regno
);
501 cfi_add_CFA_undefined (unsigned regno
)
503 cfi_add_CFA_insn_reg (DW_CFA_undefined
, regno
);
507 cfi_add_CFA_same_value (unsigned regno
)
509 cfi_add_CFA_insn_reg (DW_CFA_same_value
, regno
);
513 cfi_add_CFA_remember_state (void)
515 struct cfa_save_data
*p
;
517 cfi_add_CFA_insn (DW_CFA_remember_state
);
519 p
= (struct cfa_save_data
*) xmalloc (sizeof (*p
));
520 p
->cfa_offset
= frchain_now
->frch_cfi_data
->cur_cfa_offset
;
521 p
->next
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
522 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
;
526 cfi_add_CFA_restore_state (void)
528 struct cfa_save_data
*p
;
530 cfi_add_CFA_insn (DW_CFA_restore_state
);
532 p
= frchain_now
->frch_cfi_data
->cfa_save_stack
;
535 frchain_now
->frch_cfi_data
->cur_cfa_offset
= p
->cfa_offset
;
536 frchain_now
->frch_cfi_data
->cfa_save_stack
= p
->next
;
540 as_bad (_("CFI state restore without previous remember"));
544 /* Parse CFI assembler directives. */
546 static void dot_cfi (int);
547 static void dot_cfi_escape (int);
548 static void dot_cfi_sections (int);
549 static void dot_cfi_startproc (int);
550 static void dot_cfi_endproc (int);
551 static void dot_cfi_personality (int);
552 static void dot_cfi_lsda (int);
553 static void dot_cfi_val_encoded_addr (int);
555 const pseudo_typeS cfi_pseudo_table
[] =
557 { "cfi_sections", dot_cfi_sections
, 0 },
558 { "cfi_startproc", dot_cfi_startproc
, 0 },
559 { "cfi_endproc", dot_cfi_endproc
, 0 },
560 { "cfi_def_cfa", dot_cfi
, DW_CFA_def_cfa
},
561 { "cfi_def_cfa_register", dot_cfi
, DW_CFA_def_cfa_register
},
562 { "cfi_def_cfa_offset", dot_cfi
, DW_CFA_def_cfa_offset
},
563 { "cfi_adjust_cfa_offset", dot_cfi
, CFI_adjust_cfa_offset
},
564 { "cfi_offset", dot_cfi
, DW_CFA_offset
},
565 { "cfi_rel_offset", dot_cfi
, CFI_rel_offset
},
566 { "cfi_register", dot_cfi
, DW_CFA_register
},
567 { "cfi_return_column", dot_cfi
, CFI_return_column
},
568 { "cfi_restore", dot_cfi
, DW_CFA_restore
},
569 { "cfi_undefined", dot_cfi
, DW_CFA_undefined
},
570 { "cfi_same_value", dot_cfi
, DW_CFA_same_value
},
571 { "cfi_remember_state", dot_cfi
, DW_CFA_remember_state
},
572 { "cfi_restore_state", dot_cfi
, DW_CFA_restore_state
},
573 { "cfi_window_save", dot_cfi
, DW_CFA_GNU_window_save
},
574 { "cfi_escape", dot_cfi_escape
, 0 },
575 { "cfi_signal_frame", dot_cfi
, CFI_signal_frame
},
576 { "cfi_personality", dot_cfi_personality
, 0 },
577 { "cfi_lsda", dot_cfi_lsda
, 0 },
578 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr
, 0 },
583 cfi_parse_separator (void)
586 if (*input_line_pointer
== ',')
587 input_line_pointer
++;
589 as_bad (_("missing separator"));
592 #ifndef tc_parse_to_dw2regnum
594 tc_parse_to_dw2regnum (expressionS
*exp
)
596 # ifdef tc_regname_to_dw2regnum
598 if (is_name_beginner (*input_line_pointer
)
599 || (*input_line_pointer
== '%'
600 && is_name_beginner (*++input_line_pointer
)))
604 name
= input_line_pointer
;
605 c
= get_symbol_end ();
607 exp
->X_op
= O_constant
;
608 exp
->X_add_number
= tc_regname_to_dw2regnum (name
);
610 *input_line_pointer
= c
;
614 expression_and_evaluate (exp
);
624 tc_parse_to_dw2regnum (&exp
);
629 regno
= exp
.X_add_number
;
639 as_bad (_("bad register expression"));
647 cfi_parse_const (void)
649 return get_absolute_expression ();
658 if (frchain_now
->frch_cfi_data
== NULL
)
660 as_bad (_("CFI instruction used without previous .cfi_startproc"));
661 ignore_rest_of_line ();
665 /* If the last address was not at the current PC, advance to current. */
666 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
667 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
669 cfi_add_advance_loc (symbol_temp_new_now ());
674 reg1
= cfi_parse_reg ();
675 cfi_parse_separator ();
676 offset
= cfi_parse_const ();
677 cfi_add_CFA_offset (reg1
, offset
);
681 reg1
= cfi_parse_reg ();
682 cfi_parse_separator ();
683 offset
= cfi_parse_const ();
684 cfi_add_CFA_offset (reg1
,
685 offset
- frchain_now
->frch_cfi_data
->cur_cfa_offset
);
689 reg1
= cfi_parse_reg ();
690 cfi_parse_separator ();
691 offset
= cfi_parse_const ();
692 cfi_add_CFA_def_cfa (reg1
, offset
);
695 case DW_CFA_register
:
696 reg1
= cfi_parse_reg ();
697 cfi_parse_separator ();
698 reg2
= cfi_parse_reg ();
699 cfi_add_CFA_register (reg1
, reg2
);
702 case DW_CFA_def_cfa_register
:
703 reg1
= cfi_parse_reg ();
704 cfi_add_CFA_def_cfa_register (reg1
);
707 case DW_CFA_def_cfa_offset
:
708 offset
= cfi_parse_const ();
709 cfi_add_CFA_def_cfa_offset (offset
);
712 case CFI_adjust_cfa_offset
:
713 offset
= cfi_parse_const ();
714 cfi_add_CFA_def_cfa_offset (frchain_now
->frch_cfi_data
->cur_cfa_offset
721 reg1
= cfi_parse_reg ();
722 cfi_add_CFA_restore (reg1
);
724 if (*input_line_pointer
!= ',')
726 ++input_line_pointer
;
730 case DW_CFA_undefined
:
733 reg1
= cfi_parse_reg ();
734 cfi_add_CFA_undefined (reg1
);
736 if (*input_line_pointer
!= ',')
738 ++input_line_pointer
;
742 case DW_CFA_same_value
:
743 reg1
= cfi_parse_reg ();
744 cfi_add_CFA_same_value (reg1
);
747 case CFI_return_column
:
748 reg1
= cfi_parse_reg ();
749 cfi_set_return_column (reg1
);
752 case DW_CFA_remember_state
:
753 cfi_add_CFA_remember_state ();
756 case DW_CFA_restore_state
:
757 cfi_add_CFA_restore_state ();
760 case DW_CFA_GNU_window_save
:
761 cfi_add_CFA_insn (DW_CFA_GNU_window_save
);
764 case CFI_signal_frame
:
765 frchain_now
->frch_cfi_data
->cur_fde_data
->signal_frame
= 1;
772 demand_empty_rest_of_line ();
776 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED
)
778 struct cfi_escape_data
*head
, **tail
, *e
;
779 struct cfi_insn_data
*insn
;
781 if (frchain_now
->frch_cfi_data
== NULL
)
783 as_bad (_("CFI instruction used without previous .cfi_startproc"));
784 ignore_rest_of_line ();
788 /* If the last address was not at the current PC, advance to current. */
789 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
790 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
792 cfi_add_advance_loc (symbol_temp_new_now ());
797 e
= (struct cfi_escape_data
*) xmalloc (sizeof (*e
));
798 do_parse_cons_expression (&e
->exp
, 1);
802 while (*input_line_pointer
++ == ',');
805 insn
= alloc_cfi_insn_data ();
806 insn
->insn
= CFI_escape
;
809 --input_line_pointer
;
810 demand_empty_rest_of_line ();
814 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED
)
816 struct fde_entry
*fde
;
819 if (frchain_now
->frch_cfi_data
== NULL
)
821 as_bad (_("CFI instruction used without previous .cfi_startproc"));
822 ignore_rest_of_line ();
826 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
827 encoding
= cfi_parse_const ();
828 if (encoding
== DW_EH_PE_omit
)
830 demand_empty_rest_of_line ();
831 fde
->per_encoding
= encoding
;
835 if ((encoding
& 0xff) != encoding
836 || ((encoding
& 0x70) != 0
837 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
838 && (encoding
& 0x70) != DW_EH_PE_pcrel
841 /* leb128 can be handled, but does something actually need it? */
842 || (encoding
& 7) == DW_EH_PE_uleb128
843 || (encoding
& 7) > DW_EH_PE_udata8
)
845 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
846 ignore_rest_of_line ();
850 if (*input_line_pointer
++ != ',')
852 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
853 ignore_rest_of_line ();
857 expression_and_evaluate (&fde
->personality
);
858 switch (fde
->personality
.X_op
)
863 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
864 encoding
= DW_EH_PE_omit
;
867 encoding
= DW_EH_PE_omit
;
871 fde
->per_encoding
= encoding
;
873 if (encoding
== DW_EH_PE_omit
)
875 as_bad (_("wrong second argument to .cfi_personality"));
876 ignore_rest_of_line ();
880 demand_empty_rest_of_line ();
884 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED
)
886 struct fde_entry
*fde
;
889 if (frchain_now
->frch_cfi_data
== NULL
)
891 as_bad (_("CFI instruction used without previous .cfi_startproc"));
892 ignore_rest_of_line ();
896 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
897 encoding
= cfi_parse_const ();
898 if (encoding
== DW_EH_PE_omit
)
900 demand_empty_rest_of_line ();
901 fde
->lsda_encoding
= encoding
;
905 if ((encoding
& 0xff) != encoding
906 || ((encoding
& 0x70) != 0
907 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
908 && (encoding
& 0x70) != DW_EH_PE_pcrel
911 /* leb128 can be handled, but does something actually need it? */
912 || (encoding
& 7) == DW_EH_PE_uleb128
913 || (encoding
& 7) > DW_EH_PE_udata8
)
915 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
916 ignore_rest_of_line ();
920 if (*input_line_pointer
++ != ',')
922 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
923 ignore_rest_of_line ();
927 fde
->lsda_encoding
= encoding
;
929 expression_and_evaluate (&fde
->lsda
);
930 switch (fde
->lsda
.X_op
)
935 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
936 encoding
= DW_EH_PE_omit
;
939 encoding
= DW_EH_PE_omit
;
943 fde
->lsda_encoding
= encoding
;
945 if (encoding
== DW_EH_PE_omit
)
947 as_bad (_("wrong second argument to .cfi_lsda"));
948 ignore_rest_of_line ();
952 demand_empty_rest_of_line ();
956 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED
)
958 struct cfi_insn_data
*insn_ptr
;
961 if (frchain_now
->frch_cfi_data
== NULL
)
963 as_bad (_("CFI instruction used without previous .cfi_startproc"));
964 ignore_rest_of_line ();
968 /* If the last address was not at the current PC, advance to current. */
969 if (symbol_get_frag (frchain_now
->frch_cfi_data
->last_address
) != frag_now
970 || S_GET_VALUE (frchain_now
->frch_cfi_data
->last_address
)
972 cfi_add_advance_loc (symbol_temp_new_now ());
974 insn_ptr
= alloc_cfi_insn_data ();
975 insn_ptr
->insn
= CFI_val_encoded_addr
;
977 insn_ptr
->u
.ea
.reg
= cfi_parse_reg ();
979 cfi_parse_separator ();
980 encoding
= cfi_parse_const ();
981 if ((encoding
& 0xff) != encoding
982 || ((encoding
& 0x70) != 0
983 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
984 && (encoding
& 0x70) != DW_EH_PE_pcrel
987 /* leb128 can be handled, but does something actually need it? */
988 || (encoding
& 7) == DW_EH_PE_uleb128
989 || (encoding
& 7) > DW_EH_PE_udata8
)
991 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
992 encoding
= DW_EH_PE_omit
;
995 cfi_parse_separator ();
996 expression_and_evaluate (&insn_ptr
->u
.ea
.exp
);
997 switch (insn_ptr
->u
.ea
.exp
.X_op
)
1002 if ((encoding
& 0x70) != DW_EH_PE_pcrel
)
1005 encoding
= DW_EH_PE_omit
;
1009 insn_ptr
->u
.ea
.encoding
= encoding
;
1010 if (encoding
== DW_EH_PE_omit
)
1012 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1013 ignore_rest_of_line ();
1017 demand_empty_rest_of_line ();
1020 /* By default emit .eh_frame only, not .debug_frame. */
1021 #define CFI_EMIT_eh_frame (1 << 0)
1022 #define CFI_EMIT_debug_frame (1 << 1)
1023 #define CFI_EMIT_target (1 << 2)
1024 static int cfi_sections
= CFI_EMIT_eh_frame
;
1027 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED
)
1032 if (is_name_beginner (*input_line_pointer
))
1037 name
= input_line_pointer
;
1038 c
= get_symbol_end ();
1040 if (strncmp (name
, ".eh_frame", sizeof ".eh_frame") == 0
1042 sections
|= CFI_EMIT_eh_frame
;
1043 else if (strncmp (name
, ".debug_frame", sizeof ".debug_frame") == 0)
1044 sections
|= CFI_EMIT_debug_frame
;
1045 #ifdef tc_cfi_section_name
1046 else if (strcmp (name
, tc_cfi_section_name
) == 0)
1047 sections
|= CFI_EMIT_target
;
1051 *input_line_pointer
= c
;
1052 input_line_pointer
= name
;
1056 *input_line_pointer
= c
;
1058 if (*input_line_pointer
== ',')
1060 name
= input_line_pointer
++;
1062 if (!is_name_beginner (*input_line_pointer
))
1064 input_line_pointer
= name
;
1068 else if (is_name_beginner (*input_line_pointer
))
1072 demand_empty_rest_of_line ();
1073 cfi_sections
= sections
;
1077 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED
)
1081 if (frchain_now
->frch_cfi_data
!= NULL
)
1083 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1084 ignore_rest_of_line ();
1088 cfi_new_fde (symbol_temp_new_now ());
1091 if (is_name_beginner (*input_line_pointer
))
1095 name
= input_line_pointer
;
1096 c
= get_symbol_end ();
1098 if (strcmp (name
, "simple") == 0)
1101 *input_line_pointer
= c
;
1104 input_line_pointer
= name
;
1106 demand_empty_rest_of_line ();
1108 frchain_now
->frch_cfi_data
->cur_cfa_offset
= 0;
1110 tc_cfi_frame_initial_instructions ();
1112 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1113 tc_cfi_startproc ();
1117 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED
)
1119 struct fde_entry
*fde
;
1121 if (frchain_now
->frch_cfi_data
== NULL
)
1123 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1124 ignore_rest_of_line ();
1128 fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
1130 cfi_end_fde (symbol_temp_new_now ());
1132 demand_empty_rest_of_line ();
1134 if ((cfi_sections
& CFI_EMIT_target
) != 0)
1135 tc_cfi_endproc (fde
);
1139 /* Emit a single byte into the current segment. */
1144 FRAG_APPEND_1_CHAR (byte
);
1147 /* Emit a two-byte word into the current segment. */
1152 md_number_to_chars (frag_more (2), data
, 2);
1155 /* Emit a four byte word into the current segment. */
1160 md_number_to_chars (frag_more (4), data
, 4);
1163 /* Emit an unsigned "little-endian base 128" number. */
1166 out_uleb128 (addressT value
)
1168 output_leb128 (frag_more (sizeof_leb128 (value
, 0)), value
, 0);
1171 /* Emit an unsigned "little-endian base 128" number. */
1174 out_sleb128 (offsetT value
)
1176 output_leb128 (frag_more (sizeof_leb128 (value
, 1)), value
, 1);
1180 output_cfi_insn (struct cfi_insn_data
*insn
)
1187 case DW_CFA_advance_loc
:
1189 symbolS
*from
= insn
->u
.ll
.lab1
;
1190 symbolS
*to
= insn
->u
.ll
.lab2
;
1192 if (symbol_get_frag (to
) == symbol_get_frag (from
))
1194 addressT delta
= S_GET_VALUE (to
) - S_GET_VALUE (from
);
1195 addressT scaled
= delta
/ DWARF2_LINE_MIN_INSN_LENGTH
;
1198 out_one (DW_CFA_advance_loc
+ scaled
);
1199 else if (scaled
<= 0xFF)
1201 out_one (DW_CFA_advance_loc1
);
1204 else if (scaled
<= 0xFFFF)
1206 out_one (DW_CFA_advance_loc2
);
1211 out_one (DW_CFA_advance_loc4
);
1219 exp
.X_op
= O_subtract
;
1220 exp
.X_add_symbol
= to
;
1221 exp
.X_op_symbol
= from
;
1222 exp
.X_add_number
= 0;
1224 /* The code in ehopt.c expects that one byte of the encoding
1225 is already allocated to the frag. This comes from the way
1226 that it scans the .eh_frame section looking first for the
1227 .byte DW_CFA_advance_loc4. */
1228 *frag_more (1) = DW_CFA_advance_loc4
;
1230 frag_var (rs_cfa
, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH
<< 3,
1231 make_expr_symbol (&exp
), frag_now_fix () - 1,
1237 case DW_CFA_def_cfa
:
1238 offset
= insn
->u
.ri
.offset
;
1241 out_one (DW_CFA_def_cfa_sf
);
1242 out_uleb128 (insn
->u
.ri
.reg
);
1243 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1247 out_one (DW_CFA_def_cfa
);
1248 out_uleb128 (insn
->u
.ri
.reg
);
1249 out_uleb128 (offset
);
1253 case DW_CFA_def_cfa_register
:
1254 case DW_CFA_undefined
:
1255 case DW_CFA_same_value
:
1256 out_one (insn
->insn
);
1257 out_uleb128 (insn
->u
.r
);
1260 case DW_CFA_def_cfa_offset
:
1264 out_one (DW_CFA_def_cfa_offset_sf
);
1265 out_sleb128 (offset
/ DWARF2_CIE_DATA_ALIGNMENT
);
1269 out_one (DW_CFA_def_cfa_offset
);
1270 out_uleb128 (offset
);
1274 case DW_CFA_restore
:
1278 out_one (DW_CFA_restore
+ regno
);
1282 out_one (DW_CFA_restore_extended
);
1283 out_uleb128 (regno
);
1288 regno
= insn
->u
.ri
.reg
;
1289 offset
= insn
->u
.ri
.offset
/ DWARF2_CIE_DATA_ALIGNMENT
;
1292 out_one (DW_CFA_offset_extended_sf
);
1293 out_uleb128 (regno
);
1294 out_sleb128 (offset
);
1296 else if (regno
<= 0x3F)
1298 out_one (DW_CFA_offset
+ regno
);
1299 out_uleb128 (offset
);
1303 out_one (DW_CFA_offset_extended
);
1304 out_uleb128 (regno
);
1305 out_uleb128 (offset
);
1309 case DW_CFA_register
:
1310 out_one (DW_CFA_register
);
1311 out_uleb128 (insn
->u
.rr
.reg1
);
1312 out_uleb128 (insn
->u
.rr
.reg2
);
1315 case DW_CFA_remember_state
:
1316 case DW_CFA_restore_state
:
1317 out_one (insn
->insn
);
1320 case DW_CFA_GNU_window_save
:
1321 out_one (DW_CFA_GNU_window_save
);
1326 struct cfi_escape_data
*e
;
1327 for (e
= insn
->u
.esc
; e
; e
= e
->next
)
1328 emit_expr (&e
->exp
, 1);
1332 case CFI_val_encoded_addr
:
1334 unsigned encoding
= insn
->u
.ea
.encoding
;
1335 offsetT encoding_size
;
1337 if (encoding
== DW_EH_PE_omit
)
1339 out_one (DW_CFA_val_expression
);
1340 out_uleb128 (insn
->u
.ea
.reg
);
1342 switch (encoding
& 0x7)
1344 case DW_EH_PE_absptr
:
1345 encoding_size
= DWARF2_ADDR_SIZE (stdoutput
);
1347 case DW_EH_PE_udata2
:
1350 case DW_EH_PE_udata4
:
1353 case DW_EH_PE_udata8
:
1360 /* If the user has requested absolute encoding,
1361 then use the smaller DW_OP_addr encoding. */
1362 if (insn
->u
.ea
.encoding
== DW_EH_PE_absptr
)
1364 out_uleb128 (1 + encoding_size
);
1365 out_one (DW_OP_addr
);
1369 out_uleb128 (1 + 1 + encoding_size
);
1370 out_one (DW_OP_GNU_encoded_addr
);
1373 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1375 #if CFI_DIFF_EXPR_OK
1376 insn
->u
.ea
.exp
.X_op
= O_subtract
;
1377 insn
->u
.ea
.exp
.X_op_symbol
= symbol_temp_new_now ();
1378 #elif defined (tc_cfi_emit_pcrel_expr)
1379 tc_cfi_emit_pcrel_expr (&insn
->u
.ea
.exp
, encoding_size
);
1386 emit_expr (&insn
->u
.ea
.exp
, encoding_size
);
1396 encoding_size (unsigned char encoding
)
1398 if (encoding
== DW_EH_PE_omit
)
1400 switch (encoding
& 0x7)
1403 return bfd_get_arch_size (stdoutput
) == 64 ? 8 : 4;
1404 case DW_EH_PE_udata2
:
1406 case DW_EH_PE_udata4
:
1408 case DW_EH_PE_udata8
:
1416 output_cie (struct cie_entry
*cie
, bfd_boolean eh_frame
, int align
)
1418 symbolS
*after_size_address
, *end_address
;
1420 struct cfi_insn_data
*i
;
1421 offsetT augmentation_size
;
1423 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1425 cie
->start_address
= symbol_temp_new_now ();
1426 after_size_address
= symbol_temp_make ();
1427 end_address
= symbol_temp_make ();
1429 exp
.X_op
= O_subtract
;
1430 exp
.X_add_symbol
= end_address
;
1431 exp
.X_op_symbol
= after_size_address
;
1432 exp
.X_add_number
= 0;
1434 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1435 emit_expr (&exp
, 4); /* Length. */
1438 if (fmt
== dwarf2_format_64bit
)
1440 emit_expr (&exp
, 8); /* Length. */
1442 symbol_set_value_now (after_size_address
);
1444 out_four (0); /* CIE id. */
1447 out_four (-1); /* CIE id. */
1448 if (fmt
!= dwarf2_format_32bit
)
1451 out_one (DW_CIE_VERSION
); /* Version. */
1454 out_one ('z'); /* Augmentation. */
1455 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1457 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1461 if (cie
->signal_frame
)
1464 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH
); /* Code alignment. */
1465 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT
); /* Data alignment. */
1466 if (DW_CIE_VERSION
== 1) /* Return column. */
1467 out_one (cie
->return_column
);
1469 out_uleb128 (cie
->return_column
);
1472 augmentation_size
= 1 + (cie
->lsda_encoding
!= DW_EH_PE_omit
);
1473 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1474 augmentation_size
+= 1 + encoding_size (cie
->per_encoding
);
1475 out_uleb128 (augmentation_size
); /* Augmentation size. */
1477 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1479 offsetT size
= encoding_size (cie
->per_encoding
);
1480 out_one (cie
->per_encoding
);
1481 exp
= cie
->personality
;
1482 if ((cie
->per_encoding
& 0x70) == DW_EH_PE_pcrel
)
1484 #if CFI_DIFF_EXPR_OK
1485 exp
.X_op
= O_subtract
;
1486 exp
.X_op_symbol
= symbol_temp_new_now ();
1487 emit_expr (&exp
, size
);
1488 #elif defined (tc_cfi_emit_pcrel_expr)
1489 tc_cfi_emit_pcrel_expr (&exp
, size
);
1495 emit_expr (&exp
, size
);
1498 if (cie
->lsda_encoding
!= DW_EH_PE_omit
)
1499 out_one (cie
->lsda_encoding
);
1502 switch (DWARF2_FDE_RELOC_SIZE
)
1505 enc
= DW_EH_PE_sdata2
;
1508 enc
= DW_EH_PE_sdata4
;
1511 enc
= DW_EH_PE_sdata8
;
1516 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1517 enc
|= DW_EH_PE_pcrel
;
1524 for (i
= cie
->first
; i
!= cie
->last
; i
= i
->next
)
1526 if (CUR_SEG (i
) != CUR_SEG (cie
))
1528 output_cfi_insn (i
);
1532 frag_align (align
, DW_CFA_nop
, 0);
1533 symbol_set_value_now (end_address
);
1537 output_fde (struct fde_entry
*fde
, struct cie_entry
*cie
,
1538 bfd_boolean eh_frame
, struct cfi_insn_data
*first
,
1541 symbolS
*after_size_address
, *end_address
;
1543 offsetT augmentation_size
;
1544 enum dwarf2_format fmt
= DWARF2_FORMAT (now_seg
);
1548 after_size_address
= symbol_temp_make ();
1549 end_address
= symbol_temp_make ();
1551 exp
.X_op
= O_subtract
;
1552 exp
.X_add_symbol
= end_address
;
1553 exp
.X_op_symbol
= after_size_address
;
1554 exp
.X_add_number
= 0;
1555 if (eh_frame
|| fmt
== dwarf2_format_32bit
)
1559 if (fmt
== dwarf2_format_64bit
)
1563 emit_expr (&exp
, offset_size
); /* Length. */
1564 symbol_set_value_now (after_size_address
);
1568 exp
.X_op
= O_subtract
;
1569 exp
.X_add_symbol
= after_size_address
;
1570 exp
.X_op_symbol
= cie
->start_address
;
1571 exp
.X_add_number
= 0;
1572 emit_expr (&exp
, offset_size
); /* CIE offset. */
1576 TC_DWARF2_EMIT_OFFSET (cie
->start_address
, offset_size
);
1581 exp
.X_op
= O_subtract
;
1582 exp
.X_add_number
= 0;
1583 #if CFI_DIFF_EXPR_OK
1584 exp
.X_add_symbol
= fde
->start_address
;
1585 exp
.X_op_symbol
= symbol_temp_new_now ();
1586 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1588 exp
.X_op
= O_symbol
;
1589 exp
.X_add_symbol
= fde
->start_address
;
1590 #ifdef tc_cfi_emit_pcrel_expr
1591 tc_cfi_emit_pcrel_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1593 emit_expr (&exp
, DWARF2_FDE_RELOC_SIZE
); /* Code offset. */
1596 addr_size
= DWARF2_FDE_RELOC_SIZE
;
1600 exp
.X_op
= O_symbol
;
1601 exp
.X_add_symbol
= fde
->start_address
;
1602 exp
.X_add_number
= 0;
1603 addr_size
= DWARF2_ADDR_SIZE (stdoutput
);
1604 emit_expr (&exp
, addr_size
);
1607 exp
.X_op
= O_subtract
;
1608 exp
.X_add_symbol
= fde
->end_address
;
1609 exp
.X_op_symbol
= fde
->start_address
; /* Code length. */
1610 exp
.X_add_number
= 0;
1611 emit_expr (&exp
, addr_size
);
1613 augmentation_size
= encoding_size (fde
->lsda_encoding
);
1615 out_uleb128 (augmentation_size
); /* Augmentation size. */
1617 if (fde
->lsda_encoding
!= DW_EH_PE_omit
)
1620 if ((fde
->lsda_encoding
& 0x70) == DW_EH_PE_pcrel
)
1622 #if CFI_DIFF_LSDA_OK
1623 exp
.X_op
= O_subtract
;
1624 exp
.X_op_symbol
= symbol_temp_new_now ();
1625 emit_expr (&exp
, augmentation_size
);
1626 #elif defined (tc_cfi_emit_pcrel_expr)
1627 tc_cfi_emit_pcrel_expr (&exp
, augmentation_size
);
1633 emit_expr (&exp
, augmentation_size
);
1636 for (; first
; first
= first
->next
)
1637 if (CUR_SEG (first
) == CUR_SEG (fde
))
1638 output_cfi_insn (first
);
1640 frag_align (align
, DW_CFA_nop
, 0);
1641 symbol_set_value_now (end_address
);
1644 static struct cie_entry
*
1645 select_cie_for_fde (struct fde_entry
*fde
, bfd_boolean eh_frame
,
1646 struct cfi_insn_data
**pfirst
, int align
)
1648 struct cfi_insn_data
*i
, *j
;
1649 struct cie_entry
*cie
;
1651 for (cie
= cie_root
; cie
; cie
= cie
->next
)
1653 if (CUR_SEG (cie
) != CUR_SEG (fde
))
1655 if (cie
->return_column
!= fde
->return_column
1656 || cie
->signal_frame
!= fde
->signal_frame
1657 || cie
->per_encoding
!= fde
->per_encoding
1658 || cie
->lsda_encoding
!= fde
->lsda_encoding
)
1660 if (cie
->per_encoding
!= DW_EH_PE_omit
)
1662 if (cie
->personality
.X_op
!= fde
->personality
.X_op
1663 || cie
->personality
.X_add_number
1664 != fde
->personality
.X_add_number
)
1666 switch (cie
->personality
.X_op
)
1669 if (cie
->personality
.X_unsigned
!= fde
->personality
.X_unsigned
)
1673 if (cie
->personality
.X_add_symbol
1674 != fde
->personality
.X_add_symbol
)
1681 for (i
= cie
->first
, j
= fde
->data
;
1682 i
!= cie
->last
&& j
!= NULL
;
1683 i
= i
->next
, j
= j
->next
)
1685 if (i
->insn
!= j
->insn
)
1689 case DW_CFA_advance_loc
:
1690 case DW_CFA_remember_state
:
1691 /* We reached the first advance/remember in the FDE,
1692 but did not reach the end of the CIE list. */
1696 case DW_CFA_def_cfa
:
1697 if (i
->u
.ri
.reg
!= j
->u
.ri
.reg
)
1699 if (i
->u
.ri
.offset
!= j
->u
.ri
.offset
)
1703 case DW_CFA_register
:
1704 if (i
->u
.rr
.reg1
!= j
->u
.rr
.reg1
)
1706 if (i
->u
.rr
.reg2
!= j
->u
.rr
.reg2
)
1710 case DW_CFA_def_cfa_register
:
1711 case DW_CFA_restore
:
1712 case DW_CFA_undefined
:
1713 case DW_CFA_same_value
:
1714 if (i
->u
.r
!= j
->u
.r
)
1718 case DW_CFA_def_cfa_offset
:
1719 if (i
->u
.i
!= j
->u
.i
)
1724 case CFI_val_encoded_addr
:
1725 /* Don't bother matching these for now. */
1733 /* Success if we reached the end of the CIE list, and we've either
1734 run out of FDE entries or we've encountered an advance,
1735 remember, or escape. */
1738 || j
->insn
== DW_CFA_advance_loc
1739 || j
->insn
== DW_CFA_remember_state
1740 || j
->insn
== CFI_escape
1741 || j
->insn
== CFI_val_encoded_addr
))
1750 cie
= (struct cie_entry
*) xmalloc (sizeof (struct cie_entry
));
1751 cie
->next
= cie_root
;
1753 SET_CUR_SEG (cie
, CUR_SEG (fde
));
1754 cie
->return_column
= fde
->return_column
;
1755 cie
->signal_frame
= fde
->signal_frame
;
1756 cie
->per_encoding
= fde
->per_encoding
;
1757 cie
->lsda_encoding
= fde
->lsda_encoding
;
1758 cie
->personality
= fde
->personality
;
1759 cie
->first
= fde
->data
;
1761 for (i
= cie
->first
; i
; i
= i
->next
)
1762 if (i
->insn
== DW_CFA_advance_loc
1763 || i
->insn
== DW_CFA_remember_state
1764 || i
->insn
== CFI_escape
1765 || i
->insn
== CFI_val_encoded_addr
)
1771 output_cie (cie
, eh_frame
, align
);
1776 #ifdef md_reg_eh_frame_to_debug_frame
1778 cfi_change_reg_numbers (struct cfi_insn_data
*insn
, segT ccseg
)
1780 for (; insn
; insn
= insn
->next
)
1782 if (CUR_SEG (insn
) != ccseg
)
1786 case DW_CFA_advance_loc
:
1787 case DW_CFA_def_cfa_offset
:
1788 case DW_CFA_remember_state
:
1789 case DW_CFA_restore_state
:
1790 case DW_CFA_GNU_window_save
:
1794 case DW_CFA_def_cfa
:
1796 insn
->u
.ri
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ri
.reg
);
1799 case DW_CFA_def_cfa_register
:
1800 case DW_CFA_undefined
:
1801 case DW_CFA_same_value
:
1802 case DW_CFA_restore
:
1803 insn
->u
.r
= md_reg_eh_frame_to_debug_frame (insn
->u
.r
);
1806 case DW_CFA_register
:
1807 insn
->u
.rr
.reg1
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg1
);
1808 insn
->u
.rr
.reg2
= md_reg_eh_frame_to_debug_frame (insn
->u
.rr
.reg2
);
1811 case CFI_val_encoded_addr
:
1812 insn
->u
.ea
.reg
= md_reg_eh_frame_to_debug_frame (insn
->u
.ea
.reg
);
1821 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
1825 get_cfi_seg (segT cseg
, const char *base
, flagword flags
, int align
)
1827 if (SUPPORT_FRAME_LINKONCE
)
1829 struct dwcfi_seg_list
*l
;
1831 l
= dwcfi_hash_find_or_make (cseg
, base
, flags
);
1834 subseg_set (cseg
, l
->subseg
);
1838 cseg
= subseg_new (base
, 0);
1839 bfd_set_section_flags (stdoutput
, cseg
, flags
);
1841 record_alignment (cseg
, align
);
1848 struct cie_entry
*cie
, *cie_next
;
1849 segT cfi_seg
, ccseg
;
1850 struct fde_entry
*fde
;
1851 struct cfi_insn_data
*first
;
1852 int save_flag_traditional_format
, seek_next_seg
;
1854 if (all_fde_data
== 0)
1857 if ((cfi_sections
& CFI_EMIT_eh_frame
) != 0)
1859 /* Make sure check_eh_frame doesn't do anything with our output. */
1860 save_flag_traditional_format
= flag_traditional_format
;
1861 flag_traditional_format
= 1;
1863 if (!SUPPORT_FRAME_LINKONCE
)
1865 /* Open .eh_frame section. */
1866 cfi_seg
= get_cfi_seg (NULL
, ".eh_frame",
1867 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
1868 | DWARF2_EH_FRAME_READ_ONLY
),
1869 EH_FRAME_ALIGNMENT
);
1870 #ifdef md_fix_up_eh_frame
1871 md_fix_up_eh_frame (cfi_seg
);
1882 for (cie
= cie_root
; cie
; cie
= cie_next
)
1884 cie_next
= cie
->next
;
1885 free ((void *) cie
);
1889 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1891 if (SUPPORT_FRAME_LINKONCE
)
1895 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
1902 ccseg
= CUR_SEG (fde
);
1903 /* Open .eh_frame section. */
1904 cfi_seg
= get_cfi_seg (ccseg
, ".eh_frame",
1905 (SEC_ALLOC
| SEC_LOAD
| SEC_DATA
1906 | DWARF2_EH_FRAME_READ_ONLY
),
1907 EH_FRAME_ALIGNMENT
);
1908 #ifdef md_fix_up_eh_frame
1909 md_fix_up_eh_frame (cfi_seg
);
1915 SET_HANDLED (fde
, 1);
1918 if (fde
->end_address
== NULL
)
1920 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1921 fde
->end_address
= fde
->start_address
;
1924 cie
= select_cie_for_fde (fde
, TRUE
, &first
, 2);
1925 output_fde (fde
, cie
, TRUE
, first
,
1926 fde
->next
== NULL
? EH_FRAME_ALIGNMENT
: 2);
1929 while (SUPPORT_FRAME_LINKONCE
&& seek_next_seg
== 2);
1931 if (SUPPORT_FRAME_LINKONCE
)
1932 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1933 SET_HANDLED (fde
, 0);
1935 flag_traditional_format
= save_flag_traditional_format
;
1938 if ((cfi_sections
& CFI_EMIT_debug_frame
) != 0)
1940 int alignment
= ffs (DWARF2_ADDR_SIZE (stdoutput
)) - 1;
1942 if (!SUPPORT_FRAME_LINKONCE
)
1943 get_cfi_seg (NULL
, ".debug_frame",
1944 SEC_READONLY
| SEC_DEBUGGING
,
1952 for (cie
= cie_root
; cie
; cie
= cie_next
)
1954 cie_next
= cie
->next
;
1955 free ((void *) cie
);
1959 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1961 if (SUPPORT_FRAME_LINKONCE
)
1965 if (seek_next_seg
&& CUR_SEG (fde
) != ccseg
)
1972 ccseg
= CUR_SEG (fde
);
1973 /* Open .debug_frame section. */
1974 get_cfi_seg (ccseg
, ".debug_frame",
1975 SEC_READONLY
| SEC_DEBUGGING
,
1979 SET_HANDLED (fde
, 1);
1981 if (fde
->end_address
== NULL
)
1983 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1984 fde
->end_address
= fde
->start_address
;
1987 fde
->per_encoding
= DW_EH_PE_omit
;
1988 fde
->lsda_encoding
= DW_EH_PE_omit
;
1989 cfi_change_reg_numbers (fde
->data
, ccseg
);
1990 cie
= select_cie_for_fde (fde
, FALSE
, &first
, alignment
);
1991 output_fde (fde
, cie
, FALSE
, first
, alignment
);
1994 while (SUPPORT_FRAME_LINKONCE
&& seek_next_seg
== 2);
1996 if (SUPPORT_FRAME_LINKONCE
)
1997 for (fde
= all_fde_data
; fde
; fde
= fde
->next
)
1998 SET_HANDLED (fde
, 0);
2002 #else /* TARGET_USE_CFIPOP */
2004 /* Emit an intelligible error message for missing support. */
2007 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED
)
2009 as_bad (_("CFI is not supported for this target"));
2010 ignore_rest_of_line ();
2013 const pseudo_typeS cfi_pseudo_table
[] =
2015 { "cfi_sections", dot_cfi_dummy
, 0 },
2016 { "cfi_startproc", dot_cfi_dummy
, 0 },
2017 { "cfi_endproc", dot_cfi_dummy
, 0 },
2018 { "cfi_def_cfa", dot_cfi_dummy
, 0 },
2019 { "cfi_def_cfa_register", dot_cfi_dummy
, 0 },
2020 { "cfi_def_cfa_offset", dot_cfi_dummy
, 0 },
2021 { "cfi_adjust_cfa_offset", dot_cfi_dummy
, 0 },
2022 { "cfi_offset", dot_cfi_dummy
, 0 },
2023 { "cfi_rel_offset", dot_cfi_dummy
, 0 },
2024 { "cfi_register", dot_cfi_dummy
, 0 },
2025 { "cfi_return_column", dot_cfi_dummy
, 0 },
2026 { "cfi_restore", dot_cfi_dummy
, 0 },
2027 { "cfi_undefined", dot_cfi_dummy
, 0 },
2028 { "cfi_same_value", dot_cfi_dummy
, 0 },
2029 { "cfi_remember_state", dot_cfi_dummy
, 0 },
2030 { "cfi_restore_state", dot_cfi_dummy
, 0 },
2031 { "cfi_window_save", dot_cfi_dummy
, 0 },
2032 { "cfi_escape", dot_cfi_dummy
, 0 },
2033 { "cfi_signal_frame", dot_cfi_dummy
, 0 },
2034 { "cfi_personality", dot_cfi_dummy
, 0 },
2035 { "cfi_lsda", dot_cfi_dummy
, 0 },
2036 { "cfi_val_encoded_addr", dot_cfi_dummy
, 0 },
2044 #endif /* TARGET_USE_CFIPOP */