1 /* dw2gencfi.c - Support for generating Dwarf2 CFI information.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Michal Ludvig <mludvig@suse.cz>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "dw2gencfi.h"
25 #include "dwarf2dbg.h"
27 #ifdef TARGET_USE_CFIPOP
29 /* By default, use difference expressions if DIFF_EXPR_OK is defined. */
30 #ifndef CFI_DIFF_EXPR_OK
32 # define CFI_DIFF_EXPR_OK 1
34 # define CFI_DIFF_EXPR_OK 0
38 #ifndef CFI_DIFF_LSDA_OK
39 #define CFI_DIFF_LSDA_OK CFI_DIFF_EXPR_OK
42 #if CFI_DIFF_EXPR_OK == 1 && CFI_DIFF_LSDA_OK == 0
43 # error "CFI_DIFF_EXPR_OK should imply CFI_DIFF_LSDA_OK"
46 /* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field
47 of the CIE. Default to 1 if not otherwise specified. */
48 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
49 #define DWARF2_LINE_MIN_INSN_LENGTH 1
52 /* By default, use 32-bit relocations from .eh_frame into .text. */
53 #ifndef DWARF2_FDE_RELOC_SIZE
54 #define DWARF2_FDE_RELOC_SIZE 4
57 /* By default, use a read-only .eh_frame section. */
58 #ifndef DWARF2_EH_FRAME_READ_ONLY
59 #define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY
62 #ifndef EH_FRAME_ALIGNMENT
63 #define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
66 #ifndef tc_cfi_frame_initial_instructions
67 #define tc_cfi_frame_initial_instructions() ((void)0)
70 #ifndef tc_cfi_startproc
71 # define tc_cfi_startproc() ((void)0)
74 #ifndef tc_cfi_endproc
75 # define tc_cfi_endproc(fde) ((void) (fde))
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 CFI insn to label the current position in the CFI segment. */
446 cfi_add_label (const char *name)
448 unsigned int len = strlen (name) + 1;
449 struct cfi_insn_data *insn = alloc_cfi_insn_data ();
451 insn->insn = CFI_label;
452 obstack_grow (¬es, name, len);
453 insn->u.sym_name = (char *) obstack_finish (¬es);
456 /* Add a DW_CFA_offset record to the CFI data. */
459 cfi_add_CFA_offset (unsigned regno, offsetT offset)
461 unsigned int abs_data_align;
463 gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0);
464 cfi_add_CFA_insn_reg_offset (DW_CFA_offset, regno, offset);
466 abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
467 ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
468 if (offset % abs_data_align)
469 as_bad (_("register save offset not a multiple of %u"), abs_data_align);
472 /* Add a DW_CFA_def_cfa record to the CFI data. */
475 cfi_add_CFA_def_cfa (unsigned regno, offsetT offset)
477 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa, regno, offset);
478 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
481 /* Add a DW_CFA_register record to the CFI data. */
484 cfi_add_CFA_register (unsigned reg1, unsigned reg2)
486 cfi_add_CFA_insn_reg_reg (DW_CFA_register, reg1, reg2);
489 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
492 cfi_add_CFA_def_cfa_register (unsigned regno)
494 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register, regno);
497 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
500 cfi_add_CFA_def_cfa_offset (offsetT offset)
502 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset, offset);
503 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
507 cfi_add_CFA_restore (unsigned regno)
509 cfi_add_CFA_insn_reg (DW_CFA_restore, regno);
513 cfi_add_CFA_undefined (unsigned regno)
515 cfi_add_CFA_insn_reg (DW_CFA_undefined, regno);
519 cfi_add_CFA_same_value (unsigned regno)
521 cfi_add_CFA_insn_reg (DW_CFA_same_value, regno);
525 cfi_add_CFA_remember_state (void)
527 struct cfa_save_data *p;
529 cfi_add_CFA_insn (DW_CFA_remember_state);
531 p = (struct cfa_save_data *) xmalloc (sizeof (*p));
532 p->cfa_offset = frchain_now->frch_cfi_data->cur_cfa_offset;
533 p->next = frchain_now->frch_cfi_data->cfa_save_stack;
534 frchain_now->frch_cfi_data->cfa_save_stack = p;
538 cfi_add_CFA_restore_state (void)
540 struct cfa_save_data *p;
542 cfi_add_CFA_insn (DW_CFA_restore_state);
544 p = frchain_now->frch_cfi_data->cfa_save_stack;
547 frchain_now->frch_cfi_data->cur_cfa_offset = p->cfa_offset;
548 frchain_now->frch_cfi_data->cfa_save_stack = p->next;
552 as_bad (_("CFI state restore without previous remember"));
556 /* Parse CFI assembler directives. */
558 static void dot_cfi (int);
559 static void dot_cfi_escape (int);
560 static void dot_cfi_sections (int);
561 static void dot_cfi_startproc (int);
562 static void dot_cfi_endproc (int);
563 static void dot_cfi_personality (int);
564 static void dot_cfi_lsda (int);
565 static void dot_cfi_val_encoded_addr (int);
566 static void dot_cfi_label (int);
568 const pseudo_typeS cfi_pseudo_table[] =
570 { "cfi_sections", dot_cfi_sections, 0 },
571 { "cfi_startproc", dot_cfi_startproc, 0 },
572 { "cfi_endproc", dot_cfi_endproc, 0 },
573 { "cfi_def_cfa", dot_cfi, DW_CFA_def_cfa },
574 { "cfi_def_cfa_register", dot_cfi, DW_CFA_def_cfa_register },
575 { "cfi_def_cfa_offset", dot_cfi, DW_CFA_def_cfa_offset },
576 { "cfi_adjust_cfa_offset", dot_cfi, CFI_adjust_cfa_offset },
577 { "cfi_offset", dot_cfi, DW_CFA_offset },
578 { "cfi_rel_offset", dot_cfi, CFI_rel_offset },
579 { "cfi_register", dot_cfi, DW_CFA_register },
580 { "cfi_return_column", dot_cfi, CFI_return_column },
581 { "cfi_restore", dot_cfi, DW_CFA_restore },
582 { "cfi_undefined", dot_cfi, DW_CFA_undefined },
583 { "cfi_same_value", dot_cfi, DW_CFA_same_value },
584 { "cfi_remember_state", dot_cfi, DW_CFA_remember_state },
585 { "cfi_restore_state", dot_cfi, DW_CFA_restore_state },
586 { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save },
587 { "cfi_escape", dot_cfi_escape, 0 },
588 { "cfi_signal_frame", dot_cfi, CFI_signal_frame },
589 { "cfi_personality", dot_cfi_personality, 0 },
590 { "cfi_lsda", dot_cfi_lsda, 0 },
591 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr, 0 },
592 { "cfi_label", dot_cfi_label, 0 },
597 cfi_parse_separator (void)
600 if (*input_line_pointer == ',')
601 input_line_pointer++;
603 as_bad (_("missing separator"));
606 #ifndef tc_parse_to_dw2regnum
608 tc_parse_to_dw2regnum (expressionS *exp)
610 # ifdef tc_regname_to_dw2regnum
612 if (is_name_beginner (*input_line_pointer)
613 || (*input_line_pointer == '%'
614 && is_name_beginner (*++input_line_pointer)))
618 name = input_line_pointer;
619 c = get_symbol_end ();
621 exp->X_op = O_constant;
622 exp->X_add_number = tc_regname_to_dw2regnum (name);
624 *input_line_pointer = c;
628 expression_and_evaluate (exp);
638 tc_parse_to_dw2regnum (&exp);
643 regno = exp.X_add_number;
653 as_bad (_("bad register expression"));
661 cfi_parse_const (void)
663 return get_absolute_expression ();
672 if (frchain_now->frch_cfi_data == NULL)
674 as_bad (_("CFI instruction used without previous .cfi_startproc"));
675 ignore_rest_of_line ();
679 /* If the last address was not at the current PC, advance to current. */
680 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
681 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
683 cfi_add_advance_loc (symbol_temp_new_now ());
688 reg1 = cfi_parse_reg ();
689 cfi_parse_separator ();
690 offset = cfi_parse_const ();
691 cfi_add_CFA_offset (reg1, offset);
695 reg1 = cfi_parse_reg ();
696 cfi_parse_separator ();
697 offset = cfi_parse_const ();
698 cfi_add_CFA_offset (reg1,
699 offset - frchain_now->frch_cfi_data->cur_cfa_offset);
703 reg1 = cfi_parse_reg ();
704 cfi_parse_separator ();
705 offset = cfi_parse_const ();
706 cfi_add_CFA_def_cfa (reg1, offset);
709 case DW_CFA_register:
710 reg1 = cfi_parse_reg ();
711 cfi_parse_separator ();
712 reg2 = cfi_parse_reg ();
713 cfi_add_CFA_register (reg1, reg2);
716 case DW_CFA_def_cfa_register:
717 reg1 = cfi_parse_reg ();
718 cfi_add_CFA_def_cfa_register (reg1);
721 case DW_CFA_def_cfa_offset:
722 offset = cfi_parse_const ();
723 cfi_add_CFA_def_cfa_offset (offset);
726 case CFI_adjust_cfa_offset:
727 offset = cfi_parse_const ();
728 cfi_add_CFA_def_cfa_offset (frchain_now->frch_cfi_data->cur_cfa_offset
735 reg1 = cfi_parse_reg ();
736 cfi_add_CFA_restore (reg1);
738 if (*input_line_pointer != ',')
740 ++input_line_pointer;
744 case DW_CFA_undefined:
747 reg1 = cfi_parse_reg ();
748 cfi_add_CFA_undefined (reg1);
750 if (*input_line_pointer != ',')
752 ++input_line_pointer;
756 case DW_CFA_same_value:
757 reg1 = cfi_parse_reg ();
758 cfi_add_CFA_same_value (reg1);
761 case CFI_return_column:
762 reg1 = cfi_parse_reg ();
763 cfi_set_return_column (reg1);
766 case DW_CFA_remember_state:
767 cfi_add_CFA_remember_state ();
770 case DW_CFA_restore_state:
771 cfi_add_CFA_restore_state ();
774 case DW_CFA_GNU_window_save:
775 cfi_add_CFA_insn (DW_CFA_GNU_window_save);
778 case CFI_signal_frame:
779 frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1;
786 demand_empty_rest_of_line ();
790 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED)
792 struct cfi_escape_data *head, **tail, *e;
793 struct cfi_insn_data *insn;
795 if (frchain_now->frch_cfi_data == NULL)
797 as_bad (_("CFI instruction used without previous .cfi_startproc"));
798 ignore_rest_of_line ();
802 /* If the last address was not at the current PC, advance to current. */
803 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
804 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
806 cfi_add_advance_loc (symbol_temp_new_now ());
811 e = (struct cfi_escape_data *) xmalloc (sizeof (*e));
812 do_parse_cons_expression (&e->exp, 1);
816 while (*input_line_pointer++ == ',');
819 insn = alloc_cfi_insn_data ();
820 insn->insn = CFI_escape;
823 --input_line_pointer;
824 demand_empty_rest_of_line ();
828 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED)
830 struct fde_entry *fde;
833 if (frchain_now->frch_cfi_data == NULL)
835 as_bad (_("CFI instruction used without previous .cfi_startproc"));
836 ignore_rest_of_line ();
840 fde = frchain_now->frch_cfi_data->cur_fde_data;
841 encoding = cfi_parse_const ();
842 if (encoding == DW_EH_PE_omit)
844 demand_empty_rest_of_line ();
845 fde->per_encoding = encoding;
849 if ((encoding & 0xff) != encoding
850 || ((encoding & 0x70) != 0
851 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
852 && (encoding & 0x70) != DW_EH_PE_pcrel
855 /* leb128 can be handled, but does something actually need it? */
856 || (encoding & 7) == DW_EH_PE_uleb128
857 || (encoding & 7) > DW_EH_PE_udata8)
859 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
860 ignore_rest_of_line ();
864 if (*input_line_pointer++ != ',')
866 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
867 ignore_rest_of_line ();
871 expression_and_evaluate (&fde->personality);
872 switch (fde->personality.X_op)
877 if ((encoding & 0x70) == DW_EH_PE_pcrel)
878 encoding = DW_EH_PE_omit;
881 encoding = DW_EH_PE_omit;
885 fde->per_encoding = encoding;
887 if (encoding == DW_EH_PE_omit)
889 as_bad (_("wrong second argument to .cfi_personality"));
890 ignore_rest_of_line ();
894 demand_empty_rest_of_line ();
898 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED)
900 struct fde_entry *fde;
903 if (frchain_now->frch_cfi_data == NULL)
905 as_bad (_("CFI instruction used without previous .cfi_startproc"));
906 ignore_rest_of_line ();
910 fde = frchain_now->frch_cfi_data->cur_fde_data;
911 encoding = cfi_parse_const ();
912 if (encoding == DW_EH_PE_omit)
914 demand_empty_rest_of_line ();
915 fde->lsda_encoding = encoding;
919 if ((encoding & 0xff) != encoding
920 || ((encoding & 0x70) != 0
921 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
922 && (encoding & 0x70) != DW_EH_PE_pcrel
925 /* leb128 can be handled, but does something actually need it? */
926 || (encoding & 7) == DW_EH_PE_uleb128
927 || (encoding & 7) > DW_EH_PE_udata8)
929 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
930 ignore_rest_of_line ();
934 if (*input_line_pointer++ != ',')
936 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
937 ignore_rest_of_line ();
941 fde->lsda_encoding = encoding;
943 expression_and_evaluate (&fde->lsda);
944 switch (fde->lsda.X_op)
949 if ((encoding & 0x70) == DW_EH_PE_pcrel)
950 encoding = DW_EH_PE_omit;
953 encoding = DW_EH_PE_omit;
957 fde->lsda_encoding = encoding;
959 if (encoding == DW_EH_PE_omit)
961 as_bad (_("wrong second argument to .cfi_lsda"));
962 ignore_rest_of_line ();
966 demand_empty_rest_of_line ();
970 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED)
972 struct cfi_insn_data *insn_ptr;
975 if (frchain_now->frch_cfi_data == NULL)
977 as_bad (_("CFI instruction used without previous .cfi_startproc"));
978 ignore_rest_of_line ();
982 /* If the last address was not at the current PC, advance to current. */
983 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
984 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
986 cfi_add_advance_loc (symbol_temp_new_now ());
988 insn_ptr = alloc_cfi_insn_data ();
989 insn_ptr->insn = CFI_val_encoded_addr;
991 insn_ptr->u.ea.reg = cfi_parse_reg ();
993 cfi_parse_separator ();
994 encoding = cfi_parse_const ();
995 if ((encoding & 0xff) != encoding
996 || ((encoding & 0x70) != 0
997 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
998 && (encoding & 0x70) != DW_EH_PE_pcrel
1001 /* leb128 can be handled, but does something actually need it? */
1002 || (encoding & 7) == DW_EH_PE_uleb128
1003 || (encoding & 7) > DW_EH_PE_udata8)
1005 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1006 encoding = DW_EH_PE_omit;
1009 cfi_parse_separator ();
1010 expression_and_evaluate (&insn_ptr->u.ea.exp);
1011 switch (insn_ptr->u.ea.exp.X_op)
1016 if ((encoding & 0x70) != DW_EH_PE_pcrel)
1019 encoding = DW_EH_PE_omit;
1023 insn_ptr->u.ea.encoding = encoding;
1024 if (encoding == DW_EH_PE_omit)
1026 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1027 ignore_rest_of_line ();
1031 demand_empty_rest_of_line ();
1035 dot_cfi_label (int ignored ATTRIBUTE_UNUSED)
1037 char *name = read_symbol_name ();
1042 /* If the last address was not at the current PC, advance to current. */
1043 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
1044 || S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
1046 cfi_add_advance_loc (symbol_temp_new_now ());
1048 cfi_add_label (name);
1050 demand_empty_rest_of_line ();
1053 /* By default emit .eh_frame only, not .debug_frame. */
1054 #define CFI_EMIT_eh_frame (1 << 0)
1055 #define CFI_EMIT_debug_frame (1 << 1)
1056 #define CFI_EMIT_target (1 << 2)
1057 static int cfi_sections = CFI_EMIT_eh_frame;
1060 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
1065 if (is_name_beginner (*input_line_pointer))
1070 name = input_line_pointer;
1071 c = get_symbol_end ();
1073 if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0
1075 sections |= CFI_EMIT_eh_frame;
1076 else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0)
1077 sections |= CFI_EMIT_debug_frame;
1078 #ifdef tc_cfi_section_name
1079 else if (strcmp (name, tc_cfi_section_name) == 0)
1080 sections |= CFI_EMIT_target;
1084 *input_line_pointer = c;
1085 input_line_pointer = name;
1089 *input_line_pointer = c;
1091 if (*input_line_pointer == ',')
1093 name = input_line_pointer++;
1095 if (!is_name_beginner (*input_line_pointer))
1097 input_line_pointer = name;
1101 else if (is_name_beginner (*input_line_pointer))
1105 demand_empty_rest_of_line ();
1106 cfi_sections = sections;
1110 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
1114 if (frchain_now->frch_cfi_data != NULL)
1116 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1117 ignore_rest_of_line ();
1121 cfi_new_fde (symbol_temp_new_now ());
1124 if (is_name_beginner (*input_line_pointer))
1128 name = input_line_pointer;
1129 c = get_symbol_end ();
1131 if (strcmp (name, "simple") == 0)
1134 *input_line_pointer = c;
1137 input_line_pointer = name;
1139 demand_empty_rest_of_line ();
1141 frchain_now->frch_cfi_data->cur_cfa_offset = 0;
1143 tc_cfi_frame_initial_instructions ();
1145 if ((cfi_sections & CFI_EMIT_target) != 0)
1146 tc_cfi_startproc ();
1150 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED)
1152 struct fde_entry *fde;
1154 if (frchain_now->frch_cfi_data == NULL)
1156 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1157 ignore_rest_of_line ();
1161 fde = frchain_now->frch_cfi_data->cur_fde_data;
1163 cfi_end_fde (symbol_temp_new_now ());
1165 demand_empty_rest_of_line ();
1167 if ((cfi_sections & CFI_EMIT_target) != 0)
1168 tc_cfi_endproc (fde);
1172 /* Emit a single byte into the current segment. */
1177 FRAG_APPEND_1_CHAR (byte);
1180 /* Emit a two-byte word into the current segment. */
1185 md_number_to_chars (frag_more (2), data, 2);
1188 /* Emit a four byte word into the current segment. */
1193 md_number_to_chars (frag_more (4), data, 4);
1196 /* Emit an unsigned "little-endian base 128" number. */
1199 out_uleb128 (addressT value)
1201 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
1204 /* Emit an unsigned "little-endian base 128" number. */
1207 out_sleb128 (offsetT value)
1209 output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
1213 output_cfi_insn (struct cfi_insn_data *insn)
1220 case DW_CFA_advance_loc:
1222 symbolS *from = insn->u.ll.lab1;
1223 symbolS *to = insn->u.ll.lab2;
1225 if (symbol_get_frag (to) == symbol_get_frag (from))
1227 addressT delta = S_GET_VALUE (to) - S_GET_VALUE (from);
1228 addressT scaled = delta / DWARF2_LINE_MIN_INSN_LENGTH;
1231 out_one (DW_CFA_advance_loc + scaled);
1232 else if (scaled <= 0xFF)
1234 out_one (DW_CFA_advance_loc1);
1237 else if (scaled <= 0xFFFF)
1239 out_one (DW_CFA_advance_loc2);
1244 out_one (DW_CFA_advance_loc4);
1252 exp.X_op = O_subtract;
1253 exp.X_add_symbol = to;
1254 exp.X_op_symbol = from;
1255 exp.X_add_number = 0;
1257 /* The code in ehopt.c expects that one byte of the encoding
1258 is already allocated to the frag. This comes from the way
1259 that it scans the .eh_frame section looking first for the
1260 .byte DW_CFA_advance_loc4. */
1261 *frag_more (1) = DW_CFA_advance_loc4;
1263 frag_var (rs_cfa, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH << 3,
1264 make_expr_symbol (&exp), frag_now_fix () - 1,
1270 case DW_CFA_def_cfa:
1271 offset = insn->u.ri.offset;
1274 out_one (DW_CFA_def_cfa_sf);
1275 out_uleb128 (insn->u.ri.reg);
1276 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1280 out_one (DW_CFA_def_cfa);
1281 out_uleb128 (insn->u.ri.reg);
1282 out_uleb128 (offset);
1286 case DW_CFA_def_cfa_register:
1287 case DW_CFA_undefined:
1288 case DW_CFA_same_value:
1289 out_one (insn->insn);
1290 out_uleb128 (insn->u.r);
1293 case DW_CFA_def_cfa_offset:
1297 out_one (DW_CFA_def_cfa_offset_sf);
1298 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1302 out_one (DW_CFA_def_cfa_offset);
1303 out_uleb128 (offset);
1307 case DW_CFA_restore:
1311 out_one (DW_CFA_restore + regno);
1315 out_one (DW_CFA_restore_extended);
1316 out_uleb128 (regno);
1321 regno = insn->u.ri.reg;
1322 offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT;
1325 out_one (DW_CFA_offset_extended_sf);
1326 out_uleb128 (regno);
1327 out_sleb128 (offset);
1329 else if (regno <= 0x3F)
1331 out_one (DW_CFA_offset + regno);
1332 out_uleb128 (offset);
1336 out_one (DW_CFA_offset_extended);
1337 out_uleb128 (regno);
1338 out_uleb128 (offset);
1342 case DW_CFA_register:
1343 out_one (DW_CFA_register);
1344 out_uleb128 (insn->u.rr.reg1);
1345 out_uleb128 (insn->u.rr.reg2);
1348 case DW_CFA_remember_state:
1349 case DW_CFA_restore_state:
1350 out_one (insn->insn);
1353 case DW_CFA_GNU_window_save:
1354 out_one (DW_CFA_GNU_window_save);
1359 struct cfi_escape_data *e;
1360 for (e = insn->u.esc; e ; e = e->next)
1361 emit_expr (&e->exp, 1);
1365 case CFI_val_encoded_addr:
1367 unsigned encoding = insn->u.ea.encoding;
1368 offsetT encoding_size;
1370 if (encoding == DW_EH_PE_omit)
1372 out_one (DW_CFA_val_expression);
1373 out_uleb128 (insn->u.ea.reg);
1375 switch (encoding & 0x7)
1377 case DW_EH_PE_absptr:
1378 encoding_size = DWARF2_ADDR_SIZE (stdoutput);
1380 case DW_EH_PE_udata2:
1383 case DW_EH_PE_udata4:
1386 case DW_EH_PE_udata8:
1393 /* If the user has requested absolute encoding,
1394 then use the smaller DW_OP_addr encoding. */
1395 if (insn->u.ea.encoding == DW_EH_PE_absptr)
1397 out_uleb128 (1 + encoding_size);
1398 out_one (DW_OP_addr);
1402 out_uleb128 (1 + 1 + encoding_size);
1403 out_one (DW_OP_GNU_encoded_addr);
1406 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1408 #if CFI_DIFF_EXPR_OK
1409 insn->u.ea.exp.X_op = O_subtract;
1410 insn->u.ea.exp.X_op_symbol = symbol_temp_new_now ();
1411 #elif defined (tc_cfi_emit_pcrel_expr)
1412 tc_cfi_emit_pcrel_expr (&insn->u.ea.exp, encoding_size);
1419 emit_expr (&insn->u.ea.exp, encoding_size);
1424 colon (insn->u.sym_name);
1433 encoding_size (unsigned char encoding)
1435 if (encoding == DW_EH_PE_omit)
1437 switch (encoding & 0x7)
1440 return bfd_get_arch_size (stdoutput) == 64 ? 8 : 4;
1441 case DW_EH_PE_udata2:
1443 case DW_EH_PE_udata4:
1445 case DW_EH_PE_udata8:
1453 output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
1455 symbolS *after_size_address, *end_address;
1457 struct cfi_insn_data *i;
1458 offsetT augmentation_size;
1460 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1462 cie->start_address = symbol_temp_new_now ();
1463 after_size_address = symbol_temp_make ();
1464 end_address = symbol_temp_make ();
1466 exp.X_op = O_subtract;
1467 exp.X_add_symbol = end_address;
1468 exp.X_op_symbol = after_size_address;
1469 exp.X_add_number = 0;
1471 if (eh_frame || fmt == dwarf2_format_32bit)
1472 emit_expr (&exp, 4); /* Length. */
1475 if (fmt == dwarf2_format_64bit)
1477 emit_expr (&exp, 8); /* Length. */
1479 symbol_set_value_now (after_size_address);
1481 out_four (0); /* CIE id. */
1484 out_four (-1); /* CIE id. */
1485 if (fmt != dwarf2_format_32bit)
1488 out_one (DW_CIE_VERSION); /* Version. */
1491 out_one ('z'); /* Augmentation. */
1492 if (cie->per_encoding != DW_EH_PE_omit)
1494 if (cie->lsda_encoding != DW_EH_PE_omit)
1498 if (cie->signal_frame)
1501 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment. */
1502 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment. */
1503 if (DW_CIE_VERSION == 1) /* Return column. */
1504 out_one (cie->return_column);
1506 out_uleb128 (cie->return_column);
1509 augmentation_size = 1 + (cie->lsda_encoding != DW_EH_PE_omit);
1510 if (cie->per_encoding != DW_EH_PE_omit)
1511 augmentation_size += 1 + encoding_size (cie->per_encoding);
1512 out_uleb128 (augmentation_size); /* Augmentation size. */
1514 if (cie->per_encoding != DW_EH_PE_omit)
1516 offsetT size = encoding_size (cie->per_encoding);
1517 out_one (cie->per_encoding);
1518 exp = cie->personality;
1519 if ((cie->per_encoding & 0x70) == DW_EH_PE_pcrel)
1521 #if CFI_DIFF_EXPR_OK
1522 exp.X_op = O_subtract;
1523 exp.X_op_symbol = symbol_temp_new_now ();
1524 emit_expr (&exp, size);
1525 #elif defined (tc_cfi_emit_pcrel_expr)
1526 tc_cfi_emit_pcrel_expr (&exp, size);
1532 emit_expr (&exp, size);
1535 if (cie->lsda_encoding != DW_EH_PE_omit)
1536 out_one (cie->lsda_encoding);
1539 switch (DWARF2_FDE_RELOC_SIZE)
1542 enc = DW_EH_PE_sdata2;
1545 enc = DW_EH_PE_sdata4;
1548 enc = DW_EH_PE_sdata8;
1553 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1554 enc |= DW_EH_PE_pcrel;
1561 for (i = cie->first; i != cie->last; i = i->next)
1563 if (CUR_SEG (i) != CUR_SEG (cie))
1565 output_cfi_insn (i);
1569 frag_align (align, DW_CFA_nop, 0);
1570 symbol_set_value_now (end_address);
1574 output_fde (struct fde_entry *fde, struct cie_entry *cie,
1575 bfd_boolean eh_frame, struct cfi_insn_data *first,
1578 symbolS *after_size_address, *end_address;
1580 offsetT augmentation_size;
1581 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1585 after_size_address = symbol_temp_make ();
1586 end_address = symbol_temp_make ();
1588 exp.X_op = O_subtract;
1589 exp.X_add_symbol = end_address;
1590 exp.X_op_symbol = after_size_address;
1591 exp.X_add_number = 0;
1592 if (eh_frame || fmt == dwarf2_format_32bit)
1596 if (fmt == dwarf2_format_64bit)
1600 emit_expr (&exp, offset_size); /* Length. */
1601 symbol_set_value_now (after_size_address);
1605 exp.X_op = O_subtract;
1606 exp.X_add_symbol = after_size_address;
1607 exp.X_op_symbol = cie->start_address;
1608 exp.X_add_number = 0;
1609 emit_expr (&exp, offset_size); /* CIE offset. */
1613 TC_DWARF2_EMIT_OFFSET (cie->start_address, offset_size);
1618 exp.X_op = O_subtract;
1619 exp.X_add_number = 0;
1620 #if CFI_DIFF_EXPR_OK
1621 exp.X_add_symbol = fde->start_address;
1622 exp.X_op_symbol = symbol_temp_new_now ();
1623 emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1625 exp.X_op = O_symbol;
1626 exp.X_add_symbol = fde->start_address;
1627 #ifdef tc_cfi_emit_pcrel_expr
1628 tc_cfi_emit_pcrel_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1630 emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
1633 addr_size = DWARF2_FDE_RELOC_SIZE;
1637 exp.X_op = O_symbol;
1638 exp.X_add_symbol = fde->start_address;
1639 exp.X_add_number = 0;
1640 addr_size = DWARF2_ADDR_SIZE (stdoutput);
1641 emit_expr (&exp, addr_size);
1644 exp.X_op = O_subtract;
1645 exp.X_add_symbol = fde->end_address;
1646 exp.X_op_symbol = fde->start_address; /* Code length. */
1647 exp.X_add_number = 0;
1648 emit_expr (&exp, addr_size);
1650 augmentation_size = encoding_size (fde->lsda_encoding);
1652 out_uleb128 (augmentation_size); /* Augmentation size. */
1654 if (fde->lsda_encoding != DW_EH_PE_omit)
1657 if ((fde->lsda_encoding & 0x70) == DW_EH_PE_pcrel)
1659 #if CFI_DIFF_LSDA_OK
1660 exp.X_op = O_subtract;
1661 exp.X_op_symbol = symbol_temp_new_now ();
1662 emit_expr (&exp, augmentation_size);
1663 #elif defined (tc_cfi_emit_pcrel_expr)
1664 tc_cfi_emit_pcrel_expr (&exp, augmentation_size);
1670 emit_expr (&exp, augmentation_size);
1673 for (; first; first = first->next)
1674 if (CUR_SEG (first) == CUR_SEG (fde))
1675 output_cfi_insn (first);
1677 frag_align (align, DW_CFA_nop, 0);
1678 symbol_set_value_now (end_address);
1681 static struct cie_entry *
1682 select_cie_for_fde (struct fde_entry *fde, bfd_boolean eh_frame,
1683 struct cfi_insn_data **pfirst, int align)
1685 struct cfi_insn_data *i, *j;
1686 struct cie_entry *cie;
1688 for (cie = cie_root; cie; cie = cie->next)
1690 if (CUR_SEG (cie) != CUR_SEG (fde))
1692 if (cie->return_column != fde->return_column
1693 || cie->signal_frame != fde->signal_frame
1694 || cie->per_encoding != fde->per_encoding
1695 || cie->lsda_encoding != fde->lsda_encoding)
1697 if (cie->per_encoding != DW_EH_PE_omit)
1699 if (cie->personality.X_op != fde->personality.X_op
1700 || cie->personality.X_add_number
1701 != fde->personality.X_add_number)
1703 switch (cie->personality.X_op)
1706 if (cie->personality.X_unsigned != fde->personality.X_unsigned)
1710 if (cie->personality.X_add_symbol
1711 != fde->personality.X_add_symbol)
1718 for (i = cie->first, j = fde->data;
1719 i != cie->last && j != NULL;
1720 i = i->next, j = j->next)
1722 if (i->insn != j->insn)
1726 case DW_CFA_advance_loc:
1727 case DW_CFA_remember_state:
1728 /* We reached the first advance/remember in the FDE,
1729 but did not reach the end of the CIE list. */
1733 case DW_CFA_def_cfa:
1734 if (i->u.ri.reg != j->u.ri.reg)
1736 if (i->u.ri.offset != j->u.ri.offset)
1740 case DW_CFA_register:
1741 if (i->u.rr.reg1 != j->u.rr.reg1)
1743 if (i->u.rr.reg2 != j->u.rr.reg2)
1747 case DW_CFA_def_cfa_register:
1748 case DW_CFA_restore:
1749 case DW_CFA_undefined:
1750 case DW_CFA_same_value:
1751 if (i->u.r != j->u.r)
1755 case DW_CFA_def_cfa_offset:
1756 if (i->u.i != j->u.i)
1761 case CFI_val_encoded_addr:
1763 /* Don't bother matching these for now. */
1771 /* Success if we reached the end of the CIE list, and we've either
1772 run out of FDE entries or we've encountered an advance,
1773 remember, or escape. */
1776 || j->insn == DW_CFA_advance_loc
1777 || j->insn == DW_CFA_remember_state
1778 || j->insn == CFI_escape
1779 || j->insn == CFI_val_encoded_addr
1780 || j->insn == CFI_label))
1789 cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
1790 cie->next = cie_root;
1792 SET_CUR_SEG (cie, CUR_SEG (fde));
1793 cie->return_column = fde->return_column;
1794 cie->signal_frame = fde->signal_frame;
1795 cie->per_encoding = fde->per_encoding;
1796 cie->lsda_encoding = fde->lsda_encoding;
1797 cie->personality = fde->personality;
1798 cie->first = fde->data;
1800 for (i = cie->first; i ; i = i->next)
1801 if (i->insn == DW_CFA_advance_loc
1802 || i->insn == DW_CFA_remember_state
1803 || i->insn == CFI_escape
1804 || i->insn == CFI_val_encoded_addr
1805 || i->insn == CFI_label)
1811 output_cie (cie, eh_frame, align);
1816 #ifdef md_reg_eh_frame_to_debug_frame
1818 cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
1820 for (; insn; insn = insn->next)
1822 if (CUR_SEG (insn) != ccseg)
1826 case DW_CFA_advance_loc:
1827 case DW_CFA_def_cfa_offset:
1828 case DW_CFA_remember_state:
1829 case DW_CFA_restore_state:
1830 case DW_CFA_GNU_window_save:
1835 case DW_CFA_def_cfa:
1837 insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
1840 case DW_CFA_def_cfa_register:
1841 case DW_CFA_undefined:
1842 case DW_CFA_same_value:
1843 case DW_CFA_restore:
1844 insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
1847 case DW_CFA_register:
1848 insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
1849 insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
1852 case CFI_val_encoded_addr:
1853 insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
1862 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
1866 get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
1868 if (SUPPORT_FRAME_LINKONCE)
1870 struct dwcfi_seg_list *l;
1872 l = dwcfi_hash_find_or_make (cseg, base, flags);
1875 subseg_set (cseg, l->subseg);
1879 cseg = subseg_new (base, 0);
1880 bfd_set_section_flags (stdoutput, cseg, flags);
1882 record_alignment (cseg, align);
1889 struct cie_entry *cie, *cie_next;
1890 segT cfi_seg, ccseg;
1891 struct fde_entry *fde;
1892 struct cfi_insn_data *first;
1893 int save_flag_traditional_format, seek_next_seg;
1895 if (all_fde_data == 0)
1898 if ((cfi_sections & CFI_EMIT_eh_frame) != 0)
1900 /* Make sure check_eh_frame doesn't do anything with our output. */
1901 save_flag_traditional_format = flag_traditional_format;
1902 flag_traditional_format = 1;
1904 if (!SUPPORT_FRAME_LINKONCE)
1906 /* Open .eh_frame section. */
1907 cfi_seg = get_cfi_seg (NULL, ".eh_frame",
1908 (SEC_ALLOC | SEC_LOAD | SEC_DATA
1909 | DWARF2_EH_FRAME_READ_ONLY),
1910 EH_FRAME_ALIGNMENT);
1911 #ifdef md_fix_up_eh_frame
1912 md_fix_up_eh_frame (cfi_seg);
1923 for (cie = cie_root; cie; cie = cie_next)
1925 cie_next = cie->next;
1926 free ((void *) cie);
1930 for (fde = all_fde_data; fde ; fde = fde->next)
1932 if (SUPPORT_FRAME_LINKONCE)
1936 if (seek_next_seg && CUR_SEG (fde) != ccseg)
1943 ccseg = CUR_SEG (fde);
1944 /* Open .eh_frame section. */
1945 cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
1946 (SEC_ALLOC | SEC_LOAD | SEC_DATA
1947 | DWARF2_EH_FRAME_READ_ONLY),
1948 EH_FRAME_ALIGNMENT);
1949 #ifdef md_fix_up_eh_frame
1950 md_fix_up_eh_frame (cfi_seg);
1956 SET_HANDLED (fde, 1);
1959 if (fde->end_address == NULL)
1961 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
1962 fde->end_address = fde->start_address;
1965 cie = select_cie_for_fde (fde, TRUE, &first, 2);
1966 output_fde (fde, cie, TRUE, first,
1967 fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
1970 while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
1972 if (SUPPORT_FRAME_LINKONCE)
1973 for (fde = all_fde_data; fde ; fde = fde->next)
1974 SET_HANDLED (fde, 0);
1976 flag_traditional_format = save_flag_traditional_format;
1979 if ((cfi_sections & CFI_EMIT_debug_frame) != 0)
1981 int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
1983 if (!SUPPORT_FRAME_LINKONCE)
1984 get_cfi_seg (NULL, ".debug_frame",
1985 SEC_READONLY | SEC_DEBUGGING,
1993 for (cie = cie_root; cie; cie = cie_next)
1995 cie_next = cie->next;
1996 free ((void *) cie);
2000 for (fde = all_fde_data; fde ; fde = fde->next)
2002 if (SUPPORT_FRAME_LINKONCE)
2006 if (seek_next_seg && CUR_SEG (fde) != ccseg)
2013 ccseg = CUR_SEG (fde);
2014 /* Open .debug_frame section. */
2015 get_cfi_seg (ccseg, ".debug_frame",
2016 SEC_READONLY | SEC_DEBUGGING,
2020 SET_HANDLED (fde, 1);
2022 if (fde->end_address == NULL)
2024 as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
2025 fde->end_address = fde->start_address;
2028 fde->per_encoding = DW_EH_PE_omit;
2029 fde->lsda_encoding = DW_EH_PE_omit;
2030 cfi_change_reg_numbers (fde->data, ccseg);
2031 cie = select_cie_for_fde (fde, FALSE, &first, alignment);
2032 output_fde (fde, cie, FALSE, first, alignment);
2035 while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
2037 if (SUPPORT_FRAME_LINKONCE)
2038 for (fde = all_fde_data; fde ; fde = fde->next)
2039 SET_HANDLED (fde, 0);
2043 #else /* TARGET_USE_CFIPOP */
2045 /* Emit an intelligible error message for missing support. */
2048 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED)
2050 as_bad (_("CFI is not supported for this target"));
2051 ignore_rest_of_line ();
2054 const pseudo_typeS cfi_pseudo_table[] =
2056 { "cfi_sections", dot_cfi_dummy, 0 },
2057 { "cfi_startproc", dot_cfi_dummy, 0 },
2058 { "cfi_endproc", dot_cfi_dummy, 0 },
2059 { "cfi_def_cfa", dot_cfi_dummy, 0 },
2060 { "cfi_def_cfa_register", dot_cfi_dummy, 0 },
2061 { "cfi_def_cfa_offset", dot_cfi_dummy, 0 },
2062 { "cfi_adjust_cfa_offset", dot_cfi_dummy, 0 },
2063 { "cfi_offset", dot_cfi_dummy, 0 },
2064 { "cfi_rel_offset", dot_cfi_dummy, 0 },
2065 { "cfi_register", dot_cfi_dummy, 0 },
2066 { "cfi_return_column", dot_cfi_dummy, 0 },
2067 { "cfi_restore", dot_cfi_dummy, 0 },
2068 { "cfi_undefined", dot_cfi_dummy, 0 },
2069 { "cfi_same_value", dot_cfi_dummy, 0 },
2070 { "cfi_remember_state", dot_cfi_dummy, 0 },
2071 { "cfi_restore_state", dot_cfi_dummy, 0 },
2072 { "cfi_window_save", dot_cfi_dummy, 0 },
2073 { "cfi_escape", dot_cfi_dummy, 0 },
2074 { "cfi_signal_frame", dot_cfi_dummy, 0 },
2075 { "cfi_personality", dot_cfi_dummy, 0 },
2076 { "cfi_lsda", dot_cfi_dummy, 0 },
2077 { "cfi_val_encoded_addr", dot_cfi_dummy, 0 },
2078 { "cfi_label", dot_cfi_dummy, 0 },
2086 #endif /* TARGET_USE_CFIPOP */