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)
72 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
75 #ifndef DWARF2_ADDR_SIZE
76 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
79 #if defined (TE_PE) || defined (TE_PEP)
80 #define SUPPORT_FRAME_LINKONCE 1
82 #define SUPPORT_FRAME_LINKONCE 0
85 #if SUPPORT_FRAME_LINKONCE
86 /* Private segment collection list. */
94 #define FRAME_NAME ".eh_frame"
96 static struct hash_control *dwcfi_hash;
98 /* Build based on segment the derived .debug_...
99 segment name containing origin segment's postfix name part. */
102 get_debugseg_name (segT seg, const char *base_name)
113 name = bfd_get_section_name (stdoutput, seg);
115 dollar = strchr (name, '$');
116 dot = strchr (name + 1, '.');
124 else if (dot < dollar)
130 return concat (base_name, name, NULL);
133 /* Allocate a dwcfi_seg_list structure. */
135 static struct dwcfi_seg_list *
136 alloc_debugseg_item (segT seg, int subseg, char *name)
138 struct dwcfi_seg_list *r;
140 r = (struct dwcfi_seg_list *)
141 xmalloc (sizeof (struct dwcfi_seg_list) + strlen (name));
149 is_now_linkonce_segment (void)
151 if ((bfd_get_section_flags (stdoutput, now_seg)
152 & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
153 | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
154 | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0)
159 /* Generate debug... segment with same linkonce properties
163 make_debug_seg (segT cseg, char *name, int sflags)
165 segT save_seg = now_seg;
166 int save_subseg = now_subseg;
170 r = subseg_new (name, 0);
172 /* Check if code segment is marked as linked once. */
176 flags = bfd_get_section_flags (stdoutput, cseg)
177 & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
178 | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
179 | SEC_LINK_DUPLICATES_SAME_CONTENTS);
181 /* Add standard section flags. */
184 /* Apply possibly linked once flags to new generated segment, too. */
185 if (!bfd_set_section_flags (stdoutput, r, flags))
186 as_bad (_("bfd_set_section_flags: %s"),
187 bfd_errmsg (bfd_get_error ()));
189 /* Restore to previous segment. */
190 if (save_seg != NULL)
191 subseg_set (save_seg, save_subseg);
196 dwcfi_hash_insert (const char *name, struct dwcfi_seg_list *item)
198 const char *error_string;
200 if ((error_string = hash_jam (dwcfi_hash, name, (char *) item)))
201 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
205 static struct dwcfi_seg_list *
206 dwcfi_hash_find (char *name)
208 return (struct dwcfi_seg_list *) hash_find (dwcfi_hash, name);
211 static struct dwcfi_seg_list *
212 dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags)
214 struct dwcfi_seg_list *item;
217 /* Initialize dwcfi_hash once. */
219 dwcfi_hash = hash_new ();
221 name = get_debugseg_name (cseg, base_name);
223 item = dwcfi_hash_find (name);
226 item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name);
228 dwcfi_hash_insert (item->seg_name, item);
237 /* ??? Share this with dwarf2cfg.c. */
238 #ifndef TC_DWARF2_EMIT_OFFSET
239 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
241 /* Create an offset to .dwarf2_*. */
244 generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
249 exp.X_add_symbol = symbol;
250 exp.X_add_number = 0;
251 emit_expr (&exp, size);
255 struct cfi_escape_data
257 struct cfi_escape_data *next;
263 struct cfi_insn_data *next;
264 #if SUPPORT_FRAME_LINKONCE
291 struct cfi_escape_data *esc;
295 unsigned reg, encoding;
303 struct fde_entry *next;
304 #if SUPPORT_FRAME_LINKONCE
307 symbolS *start_address;
308 symbolS *end_address;
309 struct cfi_insn_data *data;
310 struct cfi_insn_data **last;
311 unsigned char per_encoding;
312 unsigned char lsda_encoding;
313 expressionS personality;
315 unsigned int return_column;
316 unsigned int signal_frame;
317 #if SUPPORT_FRAME_LINKONCE
324 struct cie_entry *next;
325 #if SUPPORT_FRAME_LINKONCE
328 symbolS *start_address;
329 unsigned int return_column;
330 unsigned int signal_frame;
331 unsigned char per_encoding;
332 unsigned char lsda_encoding;
333 expressionS personality;
334 struct cfi_insn_data *first, *last;
337 /* List of FDE entries. */
339 static struct fde_entry *all_fde_data;
340 static struct fde_entry **last_fde_data = &all_fde_data;
342 /* List of CIEs so that they could be reused. */
343 static struct cie_entry *cie_root;
345 /* Stack of old CFI data, for save/restore. */
348 struct cfa_save_data *next;
352 /* Current open FDE entry. */
355 struct fde_entry *cur_fde_data;
356 symbolS *last_address;
357 offsetT cur_cfa_offset;
358 struct cfa_save_data *cfa_save_stack;
361 /* Construct a new FDE structure and add it to the end of the fde list. */
363 static struct fde_entry *
364 alloc_fde_entry (void)
366 struct fde_entry *fde = (struct fde_entry *)
367 xcalloc (1, sizeof (struct fde_entry));
369 frchain_now->frch_cfi_data = (struct frch_cfi_data *)
370 xcalloc (1, sizeof (struct frch_cfi_data));
371 frchain_now->frch_cfi_data->cur_fde_data = fde;
372 *last_fde_data = fde;
373 last_fde_data = &fde->next;
374 #if SUPPORT_FRAME_LINKONCE
375 fde->cseg = is_now_linkonce_segment ();
378 fde->last = &fde->data;
379 fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
380 fde->per_encoding = DW_EH_PE_omit;
381 fde->lsda_encoding = DW_EH_PE_omit;
386 /* The following functions are available for a backend to construct its
387 own unwind information, usually from legacy unwind directives. */
389 /* Construct a new INSN structure and add it to the end of the insn list
390 for the currently active FDE. */
392 static struct cfi_insn_data *
393 alloc_cfi_insn_data (void)
395 struct cfi_insn_data *insn = (struct cfi_insn_data *)
396 xcalloc (1, sizeof (struct cfi_insn_data));
397 struct fde_entry *cur_fde_data = frchain_now->frch_cfi_data->cur_fde_data;
399 *cur_fde_data->last = insn;
400 cur_fde_data->last = &insn->next;
401 #if SUPPORT_FRAME_LINKONCE
402 insn->cur_seg = is_now_linkonce_segment ();
407 /* Construct a new FDE structure that begins at LABEL. */
410 cfi_new_fde (symbolS *label)
412 struct fde_entry *fde = alloc_fde_entry ();
413 fde->start_address = label;
414 frchain_now->frch_cfi_data->last_address = label;
417 /* End the currently open FDE. */
420 cfi_end_fde (symbolS *label)
422 frchain_now->frch_cfi_data->cur_fde_data->end_address = label;
423 free (frchain_now->frch_cfi_data);
424 frchain_now->frch_cfi_data = NULL;
427 /* Set the return column for the current FDE. */
430 cfi_set_return_column (unsigned regno)
432 frchain_now->frch_cfi_data->cur_fde_data->return_column = regno;
435 /* Universal functions to store new instructions. */
438 cfi_add_CFA_insn (int insn)
440 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
442 insn_ptr->insn = insn;
446 cfi_add_CFA_insn_reg (int insn, unsigned regno)
448 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
450 insn_ptr->insn = insn;
451 insn_ptr->u.r = regno;
455 cfi_add_CFA_insn_offset (int insn, offsetT offset)
457 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
459 insn_ptr->insn = insn;
460 insn_ptr->u.i = offset;
464 cfi_add_CFA_insn_reg_reg (int insn, unsigned reg1, unsigned reg2)
466 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
468 insn_ptr->insn = insn;
469 insn_ptr->u.rr.reg1 = reg1;
470 insn_ptr->u.rr.reg2 = reg2;
474 cfi_add_CFA_insn_reg_offset (int insn, unsigned regno, offsetT offset)
476 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
478 insn_ptr->insn = insn;
479 insn_ptr->u.ri.reg = regno;
480 insn_ptr->u.ri.offset = offset;
483 /* Add a CFI insn to advance the PC from the last address to LABEL. */
486 cfi_add_advance_loc (symbolS *label)
488 struct cfi_insn_data *insn = alloc_cfi_insn_data ();
490 insn->insn = DW_CFA_advance_loc;
491 insn->u.ll.lab1 = frchain_now->frch_cfi_data->last_address;
492 insn->u.ll.lab2 = label;
494 frchain_now->frch_cfi_data->last_address = label;
497 /* Add a DW_CFA_offset record to the CFI data. */
500 cfi_add_CFA_offset (unsigned regno, offsetT offset)
502 unsigned int abs_data_align;
504 gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0);
505 cfi_add_CFA_insn_reg_offset (DW_CFA_offset, regno, offset);
507 abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
508 ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
509 if (offset % abs_data_align)
510 as_bad (_("register save offset not a multiple of %u"), abs_data_align);
513 /* Add a DW_CFA_def_cfa record to the CFI data. */
516 cfi_add_CFA_def_cfa (unsigned regno, offsetT offset)
518 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa, regno, offset);
519 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
522 /* Add a DW_CFA_register record to the CFI data. */
525 cfi_add_CFA_register (unsigned reg1, unsigned reg2)
527 cfi_add_CFA_insn_reg_reg (DW_CFA_register, reg1, reg2);
530 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
533 cfi_add_CFA_def_cfa_register (unsigned regno)
535 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register, regno);
538 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
541 cfi_add_CFA_def_cfa_offset (offsetT offset)
543 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset, offset);
544 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
548 cfi_add_CFA_restore (unsigned regno)
550 cfi_add_CFA_insn_reg (DW_CFA_restore, regno);
554 cfi_add_CFA_undefined (unsigned regno)
556 cfi_add_CFA_insn_reg (DW_CFA_undefined, regno);
560 cfi_add_CFA_same_value (unsigned regno)
562 cfi_add_CFA_insn_reg (DW_CFA_same_value, regno);
566 cfi_add_CFA_remember_state (void)
568 struct cfa_save_data *p;
570 cfi_add_CFA_insn (DW_CFA_remember_state);
572 p = (struct cfa_save_data *) xmalloc (sizeof (*p));
573 p->cfa_offset = frchain_now->frch_cfi_data->cur_cfa_offset;
574 p->next = frchain_now->frch_cfi_data->cfa_save_stack;
575 frchain_now->frch_cfi_data->cfa_save_stack = p;
579 cfi_add_CFA_restore_state (void)
581 struct cfa_save_data *p;
583 cfi_add_CFA_insn (DW_CFA_restore_state);
585 p = frchain_now->frch_cfi_data->cfa_save_stack;
588 frchain_now->frch_cfi_data->cur_cfa_offset = p->cfa_offset;
589 frchain_now->frch_cfi_data->cfa_save_stack = p->next;
593 as_bad (_("CFI state restore without previous remember"));
597 /* Parse CFI assembler directives. */
599 static void dot_cfi (int);
600 static void dot_cfi_escape (int);
601 static void dot_cfi_sections (int);
602 static void dot_cfi_startproc (int);
603 static void dot_cfi_endproc (int);
604 static void dot_cfi_personality (int);
605 static void dot_cfi_lsda (int);
606 static void dot_cfi_val_encoded_addr (int);
608 /* Fake CFI type; outside the byte range of any real CFI insn. */
609 #define CFI_adjust_cfa_offset 0x100
610 #define CFI_return_column 0x101
611 #define CFI_rel_offset 0x102
612 #define CFI_escape 0x103
613 #define CFI_signal_frame 0x104
614 #define CFI_val_encoded_addr 0x105
616 const pseudo_typeS cfi_pseudo_table[] =
618 { "cfi_sections", dot_cfi_sections, 0 },
619 { "cfi_startproc", dot_cfi_startproc, 0 },
620 { "cfi_endproc", dot_cfi_endproc, 0 },
621 { "cfi_def_cfa", dot_cfi, DW_CFA_def_cfa },
622 { "cfi_def_cfa_register", dot_cfi, DW_CFA_def_cfa_register },
623 { "cfi_def_cfa_offset", dot_cfi, DW_CFA_def_cfa_offset },
624 { "cfi_adjust_cfa_offset", dot_cfi, CFI_adjust_cfa_offset },
625 { "cfi_offset", dot_cfi, DW_CFA_offset },
626 { "cfi_rel_offset", dot_cfi, CFI_rel_offset },
627 { "cfi_register", dot_cfi, DW_CFA_register },
628 { "cfi_return_column", dot_cfi, CFI_return_column },
629 { "cfi_restore", dot_cfi, DW_CFA_restore },
630 { "cfi_undefined", dot_cfi, DW_CFA_undefined },
631 { "cfi_same_value", dot_cfi, DW_CFA_same_value },
632 { "cfi_remember_state", dot_cfi, DW_CFA_remember_state },
633 { "cfi_restore_state", dot_cfi, DW_CFA_restore_state },
634 { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save },
635 { "cfi_escape", dot_cfi_escape, 0 },
636 { "cfi_signal_frame", dot_cfi, CFI_signal_frame },
637 { "cfi_personality", dot_cfi_personality, 0 },
638 { "cfi_lsda", dot_cfi_lsda, 0 },
639 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr, 0 },
644 cfi_parse_separator (void)
647 if (*input_line_pointer == ',')
648 input_line_pointer++;
650 as_bad (_("missing separator"));
653 #ifndef tc_parse_to_dw2regnum
655 tc_parse_to_dw2regnum (expressionS *exp)
657 # ifdef tc_regname_to_dw2regnum
659 if (is_name_beginner (*input_line_pointer)
660 || (*input_line_pointer == '%'
661 && is_name_beginner (*++input_line_pointer)))
665 name = input_line_pointer;
666 c = get_symbol_end ();
668 exp->X_op = O_constant;
669 exp->X_add_number = tc_regname_to_dw2regnum (name);
671 *input_line_pointer = c;
675 expression_and_evaluate (exp);
685 tc_parse_to_dw2regnum (&exp);
690 regno = exp.X_add_number;
700 as_bad (_("bad register expression"));
708 cfi_parse_const (void)
710 return get_absolute_expression ();
719 if (frchain_now->frch_cfi_data == NULL)
721 as_bad (_("CFI instruction used without previous .cfi_startproc"));
722 ignore_rest_of_line ();
726 /* If the last address was not at the current PC, advance to current. */
727 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
728 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
730 cfi_add_advance_loc (symbol_temp_new_now ());
735 reg1 = cfi_parse_reg ();
736 cfi_parse_separator ();
737 offset = cfi_parse_const ();
738 cfi_add_CFA_offset (reg1, offset);
742 reg1 = cfi_parse_reg ();
743 cfi_parse_separator ();
744 offset = cfi_parse_const ();
745 cfi_add_CFA_offset (reg1,
746 offset - frchain_now->frch_cfi_data->cur_cfa_offset);
750 reg1 = cfi_parse_reg ();
751 cfi_parse_separator ();
752 offset = cfi_parse_const ();
753 cfi_add_CFA_def_cfa (reg1, offset);
756 case DW_CFA_register:
757 reg1 = cfi_parse_reg ();
758 cfi_parse_separator ();
759 reg2 = cfi_parse_reg ();
760 cfi_add_CFA_register (reg1, reg2);
763 case DW_CFA_def_cfa_register:
764 reg1 = cfi_parse_reg ();
765 cfi_add_CFA_def_cfa_register (reg1);
768 case DW_CFA_def_cfa_offset:
769 offset = cfi_parse_const ();
770 cfi_add_CFA_def_cfa_offset (offset);
773 case CFI_adjust_cfa_offset:
774 offset = cfi_parse_const ();
775 cfi_add_CFA_def_cfa_offset (frchain_now->frch_cfi_data->cur_cfa_offset
782 reg1 = cfi_parse_reg ();
783 cfi_add_CFA_restore (reg1);
785 if (*input_line_pointer != ',')
787 ++input_line_pointer;
791 case DW_CFA_undefined:
794 reg1 = cfi_parse_reg ();
795 cfi_add_CFA_undefined (reg1);
797 if (*input_line_pointer != ',')
799 ++input_line_pointer;
803 case DW_CFA_same_value:
804 reg1 = cfi_parse_reg ();
805 cfi_add_CFA_same_value (reg1);
808 case CFI_return_column:
809 reg1 = cfi_parse_reg ();
810 cfi_set_return_column (reg1);
813 case DW_CFA_remember_state:
814 cfi_add_CFA_remember_state ();
817 case DW_CFA_restore_state:
818 cfi_add_CFA_restore_state ();
821 case DW_CFA_GNU_window_save:
822 cfi_add_CFA_insn (DW_CFA_GNU_window_save);
825 case CFI_signal_frame:
826 frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1;
833 demand_empty_rest_of_line ();
837 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED)
839 struct cfi_escape_data *head, **tail, *e;
840 struct cfi_insn_data *insn;
842 if (frchain_now->frch_cfi_data == NULL)
844 as_bad (_("CFI instruction used without previous .cfi_startproc"));
845 ignore_rest_of_line ();
849 /* If the last address was not at the current PC, advance to current. */
850 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
851 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
853 cfi_add_advance_loc (symbol_temp_new_now ());
858 e = (struct cfi_escape_data *) xmalloc (sizeof (*e));
859 do_parse_cons_expression (&e->exp, 1);
863 while (*input_line_pointer++ == ',');
866 insn = alloc_cfi_insn_data ();
867 insn->insn = CFI_escape;
870 --input_line_pointer;
871 demand_empty_rest_of_line ();
875 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED)
877 struct fde_entry *fde;
880 if (frchain_now->frch_cfi_data == NULL)
882 as_bad (_("CFI instruction used without previous .cfi_startproc"));
883 ignore_rest_of_line ();
887 fde = frchain_now->frch_cfi_data->cur_fde_data;
888 encoding = cfi_parse_const ();
889 if (encoding == DW_EH_PE_omit)
891 demand_empty_rest_of_line ();
892 fde->per_encoding = encoding;
896 if ((encoding & 0xff) != encoding
897 || ((encoding & 0x70) != 0
898 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
899 && (encoding & 0x70) != DW_EH_PE_pcrel
902 /* leb128 can be handled, but does something actually need it? */
903 || (encoding & 7) == DW_EH_PE_uleb128
904 || (encoding & 7) > DW_EH_PE_udata8)
906 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
907 ignore_rest_of_line ();
911 if (*input_line_pointer++ != ',')
913 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
914 ignore_rest_of_line ();
918 expression_and_evaluate (&fde->personality);
919 switch (fde->personality.X_op)
924 if ((encoding & 0x70) == DW_EH_PE_pcrel)
925 encoding = DW_EH_PE_omit;
928 encoding = DW_EH_PE_omit;
932 fde->per_encoding = encoding;
934 if (encoding == DW_EH_PE_omit)
936 as_bad (_("wrong second argument to .cfi_personality"));
937 ignore_rest_of_line ();
941 demand_empty_rest_of_line ();
945 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED)
947 struct fde_entry *fde;
950 if (frchain_now->frch_cfi_data == NULL)
952 as_bad (_("CFI instruction used without previous .cfi_startproc"));
953 ignore_rest_of_line ();
957 fde = frchain_now->frch_cfi_data->cur_fde_data;
958 encoding = cfi_parse_const ();
959 if (encoding == DW_EH_PE_omit)
961 demand_empty_rest_of_line ();
962 fde->lsda_encoding = encoding;
966 if ((encoding & 0xff) != encoding
967 || ((encoding & 0x70) != 0
968 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
969 && (encoding & 0x70) != DW_EH_PE_pcrel
972 /* leb128 can be handled, but does something actually need it? */
973 || (encoding & 7) == DW_EH_PE_uleb128
974 || (encoding & 7) > DW_EH_PE_udata8)
976 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
977 ignore_rest_of_line ();
981 if (*input_line_pointer++ != ',')
983 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
984 ignore_rest_of_line ();
988 fde->lsda_encoding = encoding;
990 expression_and_evaluate (&fde->lsda);
991 switch (fde->lsda.X_op)
996 if ((encoding & 0x70) == DW_EH_PE_pcrel)
997 encoding = DW_EH_PE_omit;
1000 encoding = DW_EH_PE_omit;
1004 fde->lsda_encoding = encoding;
1006 if (encoding == DW_EH_PE_omit)
1008 as_bad (_("wrong second argument to .cfi_lsda"));
1009 ignore_rest_of_line ();
1013 demand_empty_rest_of_line ();
1017 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED)
1019 struct cfi_insn_data *insn_ptr;
1022 if (frchain_now->frch_cfi_data == NULL)
1024 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1025 ignore_rest_of_line ();
1029 /* If the last address was not at the current PC, advance to current. */
1030 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
1031 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
1033 cfi_add_advance_loc (symbol_temp_new_now ());
1035 insn_ptr = alloc_cfi_insn_data ();
1036 insn_ptr->insn = CFI_val_encoded_addr;
1038 insn_ptr->u.ea.reg = cfi_parse_reg ();
1040 cfi_parse_separator ();
1041 encoding = cfi_parse_const ();
1042 if ((encoding & 0xff) != encoding
1043 || ((encoding & 0x70) != 0
1044 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1045 && (encoding & 0x70) != DW_EH_PE_pcrel
1048 /* leb128 can be handled, but does something actually need it? */
1049 || (encoding & 7) == DW_EH_PE_uleb128
1050 || (encoding & 7) > DW_EH_PE_udata8)
1052 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1053 encoding = DW_EH_PE_omit;
1056 cfi_parse_separator ();
1057 expression_and_evaluate (&insn_ptr->u.ea.exp);
1058 switch (insn_ptr->u.ea.exp.X_op)
1063 if ((encoding & 0x70) != DW_EH_PE_pcrel)
1066 encoding = DW_EH_PE_omit;
1070 insn_ptr->u.ea.encoding = encoding;
1071 if (encoding == DW_EH_PE_omit)
1073 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1074 ignore_rest_of_line ();
1078 demand_empty_rest_of_line ();
1081 /* By default emit .eh_frame only, not .debug_frame. */
1082 #define CFI_EMIT_eh_frame (1 << 0)
1083 #define CFI_EMIT_debug_frame (1 << 1)
1084 static int cfi_sections = CFI_EMIT_eh_frame;
1087 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
1092 if (is_name_beginner (*input_line_pointer))
1097 name = input_line_pointer;
1098 c = get_symbol_end ();
1100 if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0
1102 sections |= CFI_EMIT_eh_frame;
1103 else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0)
1104 sections |= CFI_EMIT_debug_frame;
1107 *input_line_pointer = c;
1108 input_line_pointer = name;
1112 *input_line_pointer = c;
1114 if (*input_line_pointer == ',')
1116 name = input_line_pointer++;
1118 if (!is_name_beginner (*input_line_pointer))
1120 input_line_pointer = name;
1124 else if (is_name_beginner (*input_line_pointer))
1128 demand_empty_rest_of_line ();
1129 cfi_sections = sections;
1133 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
1137 if (frchain_now->frch_cfi_data != NULL)
1139 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1140 ignore_rest_of_line ();
1144 cfi_new_fde (symbol_temp_new_now ());
1147 if (is_name_beginner (*input_line_pointer))
1151 name = input_line_pointer;
1152 c = get_symbol_end ();
1154 if (strcmp (name, "simple") == 0)
1157 *input_line_pointer = c;
1160 input_line_pointer = name;
1162 demand_empty_rest_of_line ();
1164 frchain_now->frch_cfi_data->cur_cfa_offset = 0;
1166 tc_cfi_frame_initial_instructions ();
1170 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED)
1172 if (frchain_now->frch_cfi_data == NULL)
1174 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1175 ignore_rest_of_line ();
1179 cfi_end_fde (symbol_temp_new_now ());
1181 demand_empty_rest_of_line ();
1185 /* Emit a single byte into the current segment. */
1190 FRAG_APPEND_1_CHAR (byte);
1193 /* Emit a two-byte word into the current segment. */
1198 md_number_to_chars (frag_more (2), data, 2);
1201 /* Emit a four byte word into the current segment. */
1206 md_number_to_chars (frag_more (4), data, 4);
1209 /* Emit an unsigned "little-endian base 128" number. */
1212 out_uleb128 (addressT value)
1214 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
1217 /* Emit an unsigned "little-endian base 128" number. */
1220 out_sleb128 (offsetT value)
1222 output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
1226 output_cfi_insn (struct cfi_insn_data *insn)
1233 case DW_CFA_advance_loc:
1235 symbolS *from = insn->u.ll.lab1;
1236 symbolS *to = insn->u.ll.lab2;
1238 if (symbol_get_frag (to) == symbol_get_frag (from))
1240 addressT delta = S_GET_VALUE (to) - S_GET_VALUE (from);
1241 addressT scaled = delta / DWARF2_LINE_MIN_INSN_LENGTH;
1244 out_one (DW_CFA_advance_loc + scaled);
1245 else if (scaled <= 0xFF)
1247 out_one (DW_CFA_advance_loc1);
1250 else if (scaled <= 0xFFFF)
1252 out_one (DW_CFA_advance_loc2);
1257 out_one (DW_CFA_advance_loc4);
1265 exp.X_op = O_subtract;
1266 exp.X_add_symbol = to;
1267 exp.X_op_symbol = from;
1268 exp.X_add_number = 0;
1270 /* The code in ehopt.c expects that one byte of the encoding
1271 is already allocated to the frag. This comes from the way
1272 that it scans the .eh_frame section looking first for the
1273 .byte DW_CFA_advance_loc4. */
1274 *frag_more (1) = DW_CFA_advance_loc4;
1276 frag_var (rs_cfa, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH << 3,
1277 make_expr_symbol (&exp), frag_now_fix () - 1,
1283 case DW_CFA_def_cfa:
1284 offset = insn->u.ri.offset;
1287 out_one (DW_CFA_def_cfa_sf);
1288 out_uleb128 (insn->u.ri.reg);
1289 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1293 out_one (DW_CFA_def_cfa);
1294 out_uleb128 (insn->u.ri.reg);
1295 out_uleb128 (offset);
1299 case DW_CFA_def_cfa_register:
1300 case DW_CFA_undefined:
1301 case DW_CFA_same_value:
1302 out_one (insn->insn);
1303 out_uleb128 (insn->u.r);
1306 case DW_CFA_def_cfa_offset:
1310 out_one (DW_CFA_def_cfa_offset_sf);
1311 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1315 out_one (DW_CFA_def_cfa_offset);
1316 out_uleb128 (offset);
1320 case DW_CFA_restore:
1324 out_one (DW_CFA_restore + regno);
1328 out_one (DW_CFA_restore_extended);
1329 out_uleb128 (regno);
1334 regno = insn->u.ri.reg;
1335 offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT;
1338 out_one (DW_CFA_offset_extended_sf);
1339 out_uleb128 (regno);
1340 out_sleb128 (offset);
1342 else if (regno <= 0x3F)
1344 out_one (DW_CFA_offset + regno);
1345 out_uleb128 (offset);
1349 out_one (DW_CFA_offset_extended);
1350 out_uleb128 (regno);
1351 out_uleb128 (offset);
1355 case DW_CFA_register:
1356 out_one (DW_CFA_register);
1357 out_uleb128 (insn->u.rr.reg1);
1358 out_uleb128 (insn->u.rr.reg2);
1361 case DW_CFA_remember_state:
1362 case DW_CFA_restore_state:
1363 out_one (insn->insn);
1366 case DW_CFA_GNU_window_save:
1367 out_one (DW_CFA_GNU_window_save);
1372 struct cfi_escape_data *e;
1373 for (e = insn->u.esc; e ; e = e->next)
1374 emit_expr (&e->exp, 1);
1378 case CFI_val_encoded_addr:
1380 unsigned encoding = insn->u.ea.encoding;
1381 offsetT encoding_size;
1383 if (encoding == DW_EH_PE_omit)
1385 out_one (DW_CFA_val_expression);
1386 out_uleb128 (insn->u.ea.reg);
1388 switch (encoding & 0x7)
1390 case DW_EH_PE_absptr:
1391 encoding_size = DWARF2_ADDR_SIZE (stdoutput);
1393 case DW_EH_PE_udata2:
1396 case DW_EH_PE_udata4:
1399 case DW_EH_PE_udata8:
1406 /* If the user has requested absolute encoding,
1407 then use the smaller DW_OP_addr encoding. */
1408 if (insn->u.ea.encoding == DW_EH_PE_absptr)
1410 out_uleb128 (1 + encoding_size);
1411 out_one (DW_OP_addr);
1415 out_uleb128 (1 + 1 + encoding_size);
1416 out_one (DW_OP_GNU_encoded_addr);
1419 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1421 #if CFI_DIFF_EXPR_OK
1422 insn->u.ea.exp.X_op = O_subtract;
1423 insn->u.ea.exp.X_op_symbol = symbol_temp_new_now ();
1424 #elif defined (tc_cfi_emit_pcrel_expr)
1425 tc_cfi_emit_pcrel_expr (&insn->u.ea.exp, encoding_size);
1432 emit_expr (&insn->u.ea.exp, encoding_size);
1442 encoding_size (unsigned char encoding)
1444 if (encoding == DW_EH_PE_omit)
1446 switch (encoding & 0x7)
1449 return bfd_get_arch_size (stdoutput) == 64 ? 8 : 4;
1450 case DW_EH_PE_udata2:
1452 case DW_EH_PE_udata4:
1454 case DW_EH_PE_udata8:
1462 output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
1464 symbolS *after_size_address, *end_address;
1466 struct cfi_insn_data *i;
1467 offsetT augmentation_size;
1469 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1471 cie->start_address = symbol_temp_new_now ();
1472 after_size_address = symbol_temp_make ();
1473 end_address = symbol_temp_make ();
1475 exp.X_op = O_subtract;
1476 exp.X_add_symbol = end_address;
1477 exp.X_op_symbol = after_size_address;
1478 exp.X_add_number = 0;
1480 if (eh_frame || fmt == dwarf2_format_32bit)
1481 emit_expr (&exp, 4); /* Length. */
1484 if (fmt == dwarf2_format_64bit)
1486 emit_expr (&exp, 8); /* Length. */
1488 symbol_set_value_now (after_size_address);
1490 out_four (0); /* CIE id. */
1493 out_four (-1); /* CIE id. */
1494 if (fmt != dwarf2_format_32bit)
1497 out_one (DW_CIE_VERSION); /* Version. */
1500 out_one ('z'); /* Augmentation. */
1501 if (cie->per_encoding != DW_EH_PE_omit)
1503 if (cie->lsda_encoding != DW_EH_PE_omit)
1507 if (cie->signal_frame)
1510 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment. */
1511 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment. */
1512 if (DW_CIE_VERSION == 1) /* Return column. */
1513 out_one (cie->return_column);
1515 out_uleb128 (cie->return_column);
1518 augmentation_size = 1 + (cie->lsda_encoding != DW_EH_PE_omit);
1519 if (cie->per_encoding != DW_EH_PE_omit)
1520 augmentation_size += 1 + encoding_size (cie->per_encoding);
1521 out_uleb128 (augmentation_size); /* Augmentation size. */
1523 if (cie->per_encoding != DW_EH_PE_omit)
1525 offsetT size = encoding_size (cie->per_encoding);
1526 out_one (cie->per_encoding);
1527 exp = cie->personality;
1528 if ((cie->per_encoding & 0x70) == DW_EH_PE_pcrel)
1530 #if CFI_DIFF_EXPR_OK
1531 exp.X_op = O_subtract;
1532 exp.X_op_symbol = symbol_temp_new_now ();
1533 emit_expr (&exp, size);
1534 #elif defined (tc_cfi_emit_pcrel_expr)
1535 tc_cfi_emit_pcrel_expr (&exp, size);
1541 emit_expr (&exp, size);
1544 if (cie->lsda_encoding != DW_EH_PE_omit)
1545 out_one (cie->lsda_encoding);
1548 switch (DWARF2_FDE_RELOC_SIZE)
1551 enc = DW_EH_PE_sdata2;
1554 enc = DW_EH_PE_sdata4;
1557 enc = DW_EH_PE_sdata8;
1562 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1563 enc |= DW_EH_PE_pcrel;
1570 for (i = cie->first; i != cie->last; i = i->next)
1572 #if SUPPORT_FRAME_LINKONCE
1573 if (i->cur_seg != cie->cur_seg)
1576 output_cfi_insn (i);
1580 frag_align (align, DW_CFA_nop, 0);
1581 symbol_set_value_now (end_address);
1585 output_fde (struct fde_entry *fde, struct cie_entry *cie,
1586 bfd_boolean eh_frame, struct cfi_insn_data *first,
1589 symbolS *after_size_address, *end_address;
1591 offsetT augmentation_size;
1592 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1596 after_size_address = symbol_temp_make ();
1597 end_address = symbol_temp_make ();
1599 exp.X_op = O_subtract;
1600 exp.X_add_symbol = end_address;
1601 exp.X_op_symbol = after_size_address;
1602 exp.X_add_number = 0;
1603 if (eh_frame || fmt == dwarf2_format_32bit)
1607 if (fmt == dwarf2_format_64bit)
1611 emit_expr (&exp, offset_size); /* Length. */
1612 symbol_set_value_now (after_size_address);
1616 exp.X_op = O_subtract;
1617 exp.X_add_symbol = after_size_address;
1618 exp.X_op_symbol = cie->start_address;
1619 exp.X_add_number = 0;
1620 emit_expr (&exp, offset_size); /* CIE offset. */
1624 TC_DWARF2_EMIT_OFFSET (cie->start_address, offset_size);
1629 exp.X_op = O_subtract;
1630 exp.X_add_number = 0;
1631 #if CFI_DIFF_EXPR_OK
1632 exp.X_add_symbol = fde->start_address;
1633 exp.X_op_symbol = symbol_temp_new_now ();
1634 emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1636 exp.X_op = O_symbol;
1637 exp.X_add_symbol = fde->start_address;
1638 #ifdef tc_cfi_emit_pcrel_expr
1639 tc_cfi_emit_pcrel_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1641 emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1644 addr_size = DWARF2_FDE_RELOC_SIZE;
1648 exp.X_op = O_symbol;
1649 exp.X_add_symbol = fde->start_address;
1650 exp.X_add_number = 0;
1651 addr_size = DWARF2_ADDR_SIZE (stdoutput);
1652 emit_expr (&exp, addr_size);
1655 exp.X_op = O_subtract;
1656 exp.X_add_symbol = fde->end_address;
1657 exp.X_op_symbol = fde->start_address; /* Code length. */
1658 exp.X_add_number = 0;
1659 emit_expr (&exp, addr_size);
1661 augmentation_size = encoding_size (fde->lsda_encoding);
1663 out_uleb128 (augmentation_size); /* Augmentation size. */
1665 if (fde->lsda_encoding != DW_EH_PE_omit)
1668 if ((fde->lsda_encoding & 0x70) == DW_EH_PE_pcrel)
1670 #if CFI_DIFF_LSDA_OK
1671 exp.X_op = O_subtract;
1672 exp.X_op_symbol = symbol_temp_new_now ();
1673 emit_expr (&exp, augmentation_size);
1674 #elif defined (tc_cfi_emit_pcrel_expr)
1675 tc_cfi_emit_pcrel_expr (&exp, augmentation_size);
1681 emit_expr (&exp, augmentation_size);
1684 for (; first; first = first->next)
1685 #if SUPPORT_FRAME_LINKONCE
1686 if (first->cur_seg == fde->cseg)
1688 output_cfi_insn (first);
1690 frag_align (align, DW_CFA_nop, 0);
1691 symbol_set_value_now (end_address);
1694 static struct cie_entry *
1695 select_cie_for_fde (struct fde_entry *fde, bfd_boolean eh_frame,
1696 struct cfi_insn_data **pfirst, int align)
1698 struct cfi_insn_data *i, *j;
1699 struct cie_entry *cie;
1701 for (cie = cie_root; cie; cie = cie->next)
1703 #if SUPPORT_FRAME_LINKONCE
1704 if (cie->cur_seg != fde->cseg)
1707 if (cie->return_column != fde->return_column
1708 || cie->signal_frame != fde->signal_frame
1709 || cie->per_encoding != fde->per_encoding
1710 || cie->lsda_encoding != fde->lsda_encoding)
1712 if (cie->per_encoding != DW_EH_PE_omit)
1714 if (cie->personality.X_op != fde->personality.X_op
1715 || cie->personality.X_add_number
1716 != fde->personality.X_add_number)
1718 switch (cie->personality.X_op)
1721 if (cie->personality.X_unsigned != fde->personality.X_unsigned)
1725 if (cie->personality.X_add_symbol
1726 != fde->personality.X_add_symbol)
1733 for (i = cie->first, j = fde->data;
1734 i != cie->last && j != NULL;
1735 i = i->next, j = j->next)
1737 if (i->insn != j->insn)
1741 case DW_CFA_advance_loc:
1742 case DW_CFA_remember_state:
1743 /* We reached the first advance/remember in the FDE,
1744 but did not reach the end of the CIE list. */
1748 case DW_CFA_def_cfa:
1749 if (i->u.ri.reg != j->u.ri.reg)
1751 if (i->u.ri.offset != j->u.ri.offset)
1755 case DW_CFA_register:
1756 if (i->u.rr.reg1 != j->u.rr.reg1)
1758 if (i->u.rr.reg2 != j->u.rr.reg2)
1762 case DW_CFA_def_cfa_register:
1763 case DW_CFA_restore:
1764 case DW_CFA_undefined:
1765 case DW_CFA_same_value:
1766 if (i->u.r != j->u.r)
1770 case DW_CFA_def_cfa_offset:
1771 if (i->u.i != j->u.i)
1776 case CFI_val_encoded_addr:
1777 /* Don't bother matching these for now. */
1785 /* Success if we reached the end of the CIE list, and we've either
1786 run out of FDE entries or we've encountered an advance,
1787 remember, or escape. */
1790 || j->insn == DW_CFA_advance_loc
1791 || j->insn == DW_CFA_remember_state
1792 || j->insn == CFI_escape
1793 || j->insn == CFI_val_encoded_addr))
1802 cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
1803 cie->next = cie_root;
1805 #if SUPPORT_FRAME_LINKONCE
1806 cie->cur_seg = fde->cseg;
1808 cie->return_column = fde->return_column;
1809 cie->signal_frame = fde->signal_frame;
1810 cie->per_encoding = fde->per_encoding;
1811 cie->lsda_encoding = fde->lsda_encoding;
1812 cie->personality = fde->personality;
1813 cie->first = fde->data;
1815 for (i = cie->first; i ; i = i->next)
1816 if (i->insn == DW_CFA_advance_loc
1817 || i->insn == DW_CFA_remember_state
1818 || i->insn == CFI_escape
1819 || i->insn == CFI_val_encoded_addr)
1825 output_cie (cie, eh_frame, align);
1830 #ifdef md_reg_eh_frame_to_debug_frame
1832 cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg ATTRIBUTE_UNUSED)
1834 for (; insn; insn = insn->next)
1836 #if SUPPORT_FRAME_LINKONCE
1837 if (insn->cur_seg != ccseg)
1842 case DW_CFA_advance_loc:
1843 case DW_CFA_def_cfa_offset:
1844 case DW_CFA_remember_state:
1845 case DW_CFA_restore_state:
1846 case DW_CFA_GNU_window_save:
1850 case DW_CFA_def_cfa:
1852 insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
1855 case DW_CFA_def_cfa_register:
1856 case DW_CFA_undefined:
1857 case DW_CFA_same_value:
1858 case DW_CFA_restore:
1859 insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
1862 case DW_CFA_register:
1863 insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
1864 insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
1867 case CFI_val_encoded_addr:
1868 insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
1877 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
1881 get_cfi_seg (segT cseg ATTRIBUTE_UNUSED,
1882 const char *base, flagword flags, int align)
1884 #if SUPPORT_FRAME_LINKONCE
1885 struct dwcfi_seg_list *l;
1887 l = dwcfi_hash_find_or_make (cseg, base, flags);
1890 subseg_set (cseg, l->subseg);
1892 cseg = subseg_new (base, 0);
1893 bfd_set_section_flags (stdoutput, cseg, flags);
1895 record_alignment (cseg, align);
1902 struct cie_entry *cie, *cie_next;
1903 segT cfi_seg, ccseg;
1904 struct fde_entry *fde;
1905 struct cfi_insn_data *first;
1906 int save_flag_traditional_format, seek_next_seg;
1908 if (all_fde_data == 0)
1911 if ((cfi_sections & CFI_EMIT_eh_frame) != 0)
1913 /* Make sure check_eh_frame doesn't do anything with our output. */
1914 save_flag_traditional_format = flag_traditional_format;
1915 flag_traditional_format = 1;
1917 #if !SUPPORT_FRAME_LINKONCE
1918 /* Open .eh_frame section. */
1919 cfi_seg = get_cfi_seg (NULL, ".eh_frame",
1920 SEC_ALLOC | SEC_LOAD | SEC_DATA
1921 | DWARF2_EH_FRAME_READ_ONLY,
1922 EH_FRAME_ALIGNMENT);
1923 #ifdef md_fix_up_eh_frame
1924 md_fix_up_eh_frame (cfi_seg);
1935 for (cie = cie_root; cie; cie = cie_next)
1937 cie_next = cie->next;
1938 free ((void *) cie);
1942 for (fde = all_fde_data; fde ; fde = fde->next)
1944 #if SUPPORT_FRAME_LINKONCE
1945 if (fde->handled != 0)
1947 if (seek_next_seg && fde->cseg != ccseg)
1955 /* Open .eh_frame section. */
1956 cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
1957 SEC_ALLOC | SEC_LOAD | SEC_DATA
1958 | DWARF2_EH_FRAME_READ_ONLY,
1959 EH_FRAME_ALIGNMENT);
1960 #ifdef md_fix_up_eh_frame
1961 md_fix_up_eh_frame (cfi_seg);
1970 if (fde->end_address == NULL)
1972 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1973 fde->end_address = fde->start_address;
1976 cie = select_cie_for_fde (fde, TRUE, &first, 2);
1977 output_fde (fde, cie, TRUE, first,
1978 fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
1981 while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
1983 #if SUPPORT_FRAME_LINKONCE
1984 for (fde = all_fde_data; fde ; fde = fde->next)
1988 flag_traditional_format = save_flag_traditional_format;
1991 if ((cfi_sections & CFI_EMIT_debug_frame) != 0)
1993 int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
1995 #if !SUPPORT_FRAME_LINKONCE
1996 get_cfi_seg (NULL, ".debug_frame",
1997 SEC_READONLY | SEC_DEBUGGING,
2005 for (cie = cie_root; cie; cie = cie_next)
2007 cie_next = cie->next;
2008 free ((void *) cie);
2012 for (fde = all_fde_data; fde ; fde = fde->next)
2014 #if SUPPORT_FRAME_LINKONCE
2015 if (fde->handled != 0)
2017 if (seek_next_seg && fde->cseg != ccseg)
2025 /* Open .debug_frame section. */
2026 get_cfi_seg (ccseg, ".debug_frame",
2027 SEC_READONLY | SEC_DEBUGGING,
2033 if (fde->end_address == NULL)
2035 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
2036 fde->end_address = fde->start_address;
2039 fde->per_encoding = DW_EH_PE_omit;
2040 fde->lsda_encoding = DW_EH_PE_omit;
2041 cfi_change_reg_numbers (fde->data, ccseg);
2042 cie = select_cie_for_fde (fde, FALSE, &first, alignment);
2043 output_fde (fde, cie, FALSE, first, alignment);
2046 while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
2048 #if SUPPORT_FRAME_LINKONCE
2049 for (fde = all_fde_data; fde ; fde = fde->next)
2055 #else /* TARGET_USE_CFIPOP */
2057 /* Emit an intelligible error message for missing support. */
2060 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED)
2062 as_bad (_("CFI is not supported for this target"));
2063 ignore_rest_of_line ();
2066 const pseudo_typeS cfi_pseudo_table[] =
2068 { "cfi_sections", dot_cfi_dummy, 0 },
2069 { "cfi_startproc", dot_cfi_dummy, 0 },
2070 { "cfi_endproc", dot_cfi_dummy, 0 },
2071 { "cfi_def_cfa", dot_cfi_dummy, 0 },
2072 { "cfi_def_cfa_register", dot_cfi_dummy, 0 },
2073 { "cfi_def_cfa_offset", dot_cfi_dummy, 0 },
2074 { "cfi_adjust_cfa_offset", dot_cfi_dummy, 0 },
2075 { "cfi_offset", dot_cfi_dummy, 0 },
2076 { "cfi_rel_offset", dot_cfi_dummy, 0 },
2077 { "cfi_register", dot_cfi_dummy, 0 },
2078 { "cfi_return_column", dot_cfi_dummy, 0 },
2079 { "cfi_restore", dot_cfi_dummy, 0 },
2080 { "cfi_undefined", dot_cfi_dummy, 0 },
2081 { "cfi_same_value", dot_cfi_dummy, 0 },
2082 { "cfi_remember_state", dot_cfi_dummy, 0 },
2083 { "cfi_restore_state", dot_cfi_dummy, 0 },
2084 { "cfi_window_save", dot_cfi_dummy, 0 },
2085 { "cfi_escape", dot_cfi_dummy, 0 },
2086 { "cfi_signal_frame", dot_cfi_dummy, 0 },
2087 { "cfi_personality", dot_cfi_dummy, 0 },
2088 { "cfi_lsda", dot_cfi_dummy, 0 },
2089 { "cfi_val_encoded_addr", dot_cfi_dummy, 0 },
2097 #endif /* TARGET_USE_CFIPOP */