1 /* dw2gencfi.c - Support for generating Dwarf2 CFI information.
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 Contributed by Michal Ludvig <mludvig@suse.cz>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "dw2gencfi.h"
25 #include "dwarf2dbg.h"
27 #ifdef TARGET_USE_CFIPOP
29 /* By default, use difference expressions if DIFF_EXPR_OK is defined. */
30 #ifndef CFI_DIFF_EXPR_OK
32 # define CFI_DIFF_EXPR_OK 1
34 # define CFI_DIFF_EXPR_OK 0
38 #ifndef CFI_DIFF_LSDA_OK
39 #define CFI_DIFF_LSDA_OK CFI_DIFF_EXPR_OK
42 #if CFI_DIFF_EXPR_OK == 1 && CFI_DIFF_LSDA_OK == 0
43 # error "CFI_DIFF_EXPR_OK should imply CFI_DIFF_LSDA_OK"
46 /* We re-use DWARF2_LINE_MIN_INSN_LENGTH for the code alignment field
47 of the CIE. Default to 1 if not otherwise specified. */
48 #ifndef DWARF2_LINE_MIN_INSN_LENGTH
49 #define DWARF2_LINE_MIN_INSN_LENGTH 1
52 /* By default, use 32-bit relocations from .eh_frame into .text. */
53 #ifndef DWARF2_FDE_RELOC_SIZE
54 #define DWARF2_FDE_RELOC_SIZE 4
57 /* By default, use a read-only .eh_frame section. */
58 #ifndef DWARF2_EH_FRAME_READ_ONLY
59 #define DWARF2_EH_FRAME_READ_ONLY SEC_READONLY
62 #ifndef EH_FRAME_ALIGNMENT
63 #define EH_FRAME_ALIGNMENT (bfd_get_arch_size (stdoutput) == 64 ? 3 : 2)
66 #ifndef tc_cfi_frame_initial_instructions
67 #define tc_cfi_frame_initial_instructions() ((void)0)
70 #ifndef tc_cfi_startproc
71 # define tc_cfi_startproc() ((void)0)
74 #ifndef tc_cfi_endproc
75 # define tc_cfi_endproc(fde) ((void) (fde))
78 #define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh)
81 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
84 #ifndef DWARF2_ADDR_SIZE
85 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
88 #if MULTIPLE_FRAME_SECTIONS
89 #define CUR_SEG(structp) structp->cur_seg
90 #define SET_CUR_SEG(structp, seg) structp->cur_seg = seg
91 #define HANDLED(structp) structp->handled
92 #define SET_HANDLED(structp, val) structp->handled = val
94 #define CUR_SEG(structp) NULL
95 #define SET_CUR_SEG(structp, seg) (void) (0 && seg)
96 #define HANDLED(structp) 0
97 #define SET_HANDLED(structp, val) (void) (0 && val)
100 #ifndef tc_cfi_reloc_for_encoding
101 #define tc_cfi_reloc_for_encoding(e) BFD_RELOC_NONE
104 /* Private segment collection list. */
105 struct dwcfi_seg_list
112 #ifdef SUPPORT_COMPACT_EH
113 static bfd_boolean compact_eh;
118 static struct hash_control *dwcfi_hash;
120 /* Emit a single byte into the current segment. */
125 FRAG_APPEND_1_CHAR (byte);
128 /* Emit a two-byte word into the current segment. */
133 md_number_to_chars (frag_more (2), data, 2);
136 /* Emit a four byte word into the current segment. */
141 md_number_to_chars (frag_more (4), data, 4);
144 /* Emit an unsigned "little-endian base 128" number. */
147 out_uleb128 (addressT value)
149 output_leb128 (frag_more (sizeof_leb128 (value, 0)), value, 0);
152 /* Emit an unsigned "little-endian base 128" number. */
155 out_sleb128 (offsetT value)
157 output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
161 encoding_size (unsigned char encoding)
163 if (encoding == DW_EH_PE_omit)
165 switch (encoding & 0x7)
168 return bfd_get_arch_size (stdoutput) == 64 ? 8 : 4;
169 case DW_EH_PE_udata2:
171 case DW_EH_PE_udata4:
173 case DW_EH_PE_udata8:
180 /* Emit expression EXP in ENCODING. If EMIT_ENCODING is true, first
181 emit a byte containing ENCODING. */
184 emit_expr_encoded (expressionS *exp, int encoding, bfd_boolean emit_encoding)
186 unsigned int size = encoding_size (encoding);
187 bfd_reloc_code_real_type code;
189 if (encoding == DW_EH_PE_omit)
195 code = tc_cfi_reloc_for_encoding (encoding);
196 if (code != BFD_RELOC_NONE)
198 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
199 char *p = frag_more (size);
200 gas_assert (size == (unsigned) howto->bitsize / 8);
201 md_number_to_chars (p, 0, size);
202 fix_new (frag_now, p - frag_now->fr_literal, size, exp->X_add_symbol,
203 exp->X_add_number, howto->pc_relative, code);
205 else if ((encoding & 0x70) == DW_EH_PE_pcrel)
208 expressionS tmp = *exp;
209 tmp.X_op = O_subtract;
210 tmp.X_op_symbol = symbol_temp_new_now ();
211 emit_expr (&tmp, size);
212 #elif defined (tc_cfi_emit_pcrel_expr)
213 tc_cfi_emit_pcrel_expr (exp, size);
219 emit_expr (exp, size);
222 /* Build based on segment the derived .debug_...
223 segment name containing origin segment's postfix name part. */
226 get_debugseg_name (segT seg, const char *base_name)
237 name = bfd_get_section_name (stdoutput, seg);
239 dollar = strchr (name, '$');
240 dot = strchr (name + 1, '.');
244 if (!strcmp (base_name, ".eh_frame_entry")
245 && strcmp (name, ".text") != 0)
246 return concat (base_name, ".", name, NULL);
254 else if (dot < dollar)
260 return concat (base_name, name, NULL);
263 /* Allocate a dwcfi_seg_list structure. */
265 static struct dwcfi_seg_list *
266 alloc_debugseg_item (segT seg, int subseg, char *name)
268 struct dwcfi_seg_list *r;
270 r = (struct dwcfi_seg_list *)
271 xmalloc (sizeof (struct dwcfi_seg_list) + strlen (name));
279 is_now_linkonce_segment (void)
284 if ((bfd_get_section_flags (stdoutput, now_seg)
285 & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
286 | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
287 | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0)
292 /* Generate debug... segment with same linkonce properties
296 make_debug_seg (segT cseg, char *name, int sflags)
298 segT save_seg = now_seg;
299 int save_subseg = now_subseg;
303 r = subseg_new (name, 0);
305 /* Check if code segment is marked as linked once. */
309 flags = bfd_get_section_flags (stdoutput, cseg)
310 & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
311 | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
312 | SEC_LINK_DUPLICATES_SAME_CONTENTS);
314 /* Add standard section flags. */
317 /* Apply possibly linked once flags to new generated segment, too. */
318 if (!bfd_set_section_flags (stdoutput, r, flags))
319 as_bad (_("bfd_set_section_flags: %s"),
320 bfd_errmsg (bfd_get_error ()));
322 /* Restore to previous segment. */
323 if (save_seg != NULL)
324 subseg_set (save_seg, save_subseg);
329 dwcfi_hash_insert (const char *name, struct dwcfi_seg_list *item)
331 const char *error_string;
333 if ((error_string = hash_jam (dwcfi_hash, name, (char *) item)))
334 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
338 static struct dwcfi_seg_list *
339 dwcfi_hash_find (char *name)
341 return (struct dwcfi_seg_list *) hash_find (dwcfi_hash, name);
344 static struct dwcfi_seg_list *
345 dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags)
347 struct dwcfi_seg_list *item;
350 /* Initialize dwcfi_hash once. */
352 dwcfi_hash = hash_new ();
354 name = get_debugseg_name (cseg, base_name);
356 item = dwcfi_hash_find (name);
359 item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name);
361 dwcfi_hash_insert (item->seg_name, item);
369 /* ??? Share this with dwarf2cfg.c. */
370 #ifndef TC_DWARF2_EMIT_OFFSET
371 #define TC_DWARF2_EMIT_OFFSET generic_dwarf2_emit_offset
373 /* Create an offset to .dwarf2_*. */
376 generic_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
381 exp.X_add_symbol = symbol;
382 exp.X_add_number = 0;
383 emit_expr (&exp, size);
387 struct cfi_escape_data
389 struct cfi_escape_data *next;
395 struct cie_entry *next;
396 #if MULTIPLE_FRAME_SECTIONS
399 symbolS *start_address;
400 unsigned int return_column;
401 unsigned int signal_frame;
402 unsigned char fde_encoding;
403 unsigned char per_encoding;
404 unsigned char lsda_encoding;
405 expressionS personality;
406 enum pointer_auth_key pauth_key;
407 struct cfi_insn_data *first, *last;
410 /* List of FDE entries. */
412 struct fde_entry *all_fde_data;
413 static struct fde_entry **last_fde_data = &all_fde_data;
415 /* List of CIEs so that they could be reused. */
416 static struct cie_entry *cie_root;
418 /* Construct a new FDE structure and add it to the end of the fde list. */
420 static struct fde_entry *
421 alloc_fde_entry (void)
423 struct fde_entry *fde = XCNEW (struct fde_entry);
425 frchain_now->frch_cfi_data = XCNEW (struct frch_cfi_data);
426 frchain_now->frch_cfi_data->cur_fde_data = fde;
427 *last_fde_data = fde;
428 last_fde_data = &fde->next;
429 SET_CUR_SEG (fde, is_now_linkonce_segment ());
430 SET_HANDLED (fde, 0);
431 fde->last = &fde->data;
432 fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
433 fde->per_encoding = DW_EH_PE_omit;
434 fde->lsda_encoding = DW_EH_PE_omit;
435 fde->eh_header_type = EH_COMPACT_UNKNOWN;
436 fde->pauth_key = AARCH64_PAUTH_KEY_A;
441 /* The following functions are available for a backend to construct its
442 own unwind information, usually from legacy unwind directives. */
444 /* Construct a new INSN structure and add it to the end of the insn list
445 for the currently active FDE. */
447 static bfd_boolean cfi_sections_set = FALSE;
448 static int cfi_sections = CFI_EMIT_eh_frame;
449 int all_cfi_sections = 0;
450 static struct fde_entry *last_fde;
452 static struct cfi_insn_data *
453 alloc_cfi_insn_data (void)
455 struct cfi_insn_data *insn = XCNEW (struct cfi_insn_data);
456 struct fde_entry *cur_fde_data = frchain_now->frch_cfi_data->cur_fde_data;
458 *cur_fde_data->last = insn;
459 cur_fde_data->last = &insn->next;
460 SET_CUR_SEG (insn, is_now_linkonce_segment ());
464 /* Construct a new FDE structure that begins at LABEL. */
467 cfi_new_fde (symbolS *label)
469 struct fde_entry *fde = alloc_fde_entry ();
470 fde->start_address = label;
471 frchain_now->frch_cfi_data->last_address = label;
474 /* End the currently open FDE. */
477 cfi_end_fde (symbolS *label)
479 frchain_now->frch_cfi_data->cur_fde_data->end_address = label;
480 free (frchain_now->frch_cfi_data);
481 frchain_now->frch_cfi_data = NULL;
484 /* Set the return column for the current FDE. */
487 cfi_set_return_column (unsigned regno)
489 frchain_now->frch_cfi_data->cur_fde_data->return_column = regno;
493 cfi_set_sections (void)
495 frchain_now->frch_cfi_data->cur_fde_data->sections = all_cfi_sections;
496 cfi_sections_set = TRUE;
499 /* Universal functions to store new instructions. */
502 cfi_add_CFA_insn (int insn)
504 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
506 insn_ptr->insn = insn;
510 cfi_add_CFA_insn_reg (int insn, unsigned regno)
512 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
514 insn_ptr->insn = insn;
515 insn_ptr->u.r = regno;
519 cfi_add_CFA_insn_offset (int insn, offsetT offset)
521 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
523 insn_ptr->insn = insn;
524 insn_ptr->u.i = offset;
528 cfi_add_CFA_insn_reg_reg (int insn, unsigned reg1, unsigned reg2)
530 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
532 insn_ptr->insn = insn;
533 insn_ptr->u.rr.reg1 = reg1;
534 insn_ptr->u.rr.reg2 = reg2;
538 cfi_add_CFA_insn_reg_offset (int insn, unsigned regno, offsetT offset)
540 struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
542 insn_ptr->insn = insn;
543 insn_ptr->u.ri.reg = regno;
544 insn_ptr->u.ri.offset = offset;
547 /* Add a CFI insn to advance the PC from the last address to LABEL. */
550 cfi_add_advance_loc (symbolS *label)
552 struct cfi_insn_data *insn = alloc_cfi_insn_data ();
554 insn->insn = DW_CFA_advance_loc;
555 insn->u.ll.lab1 = frchain_now->frch_cfi_data->last_address;
556 insn->u.ll.lab2 = label;
558 frchain_now->frch_cfi_data->last_address = label;
561 /* Add a CFI insn to label the current position in the CFI segment. */
564 cfi_add_label (const char *name)
566 unsigned int len = strlen (name) + 1;
567 struct cfi_insn_data *insn = alloc_cfi_insn_data ();
569 insn->insn = CFI_label;
570 obstack_grow (¬es, name, len);
571 insn->u.sym_name = (char *) obstack_finish (¬es);
574 /* Add a DW_CFA_offset record to the CFI data. */
577 cfi_add_CFA_offset (unsigned regno, offsetT offset)
579 unsigned int abs_data_align;
581 gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0);
582 cfi_add_CFA_insn_reg_offset (DW_CFA_offset, regno, offset);
584 abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
585 ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
586 if (offset % abs_data_align)
587 as_bad (_("register save offset not a multiple of %u"), abs_data_align);
590 /* Add a DW_CFA_val_offset record to the CFI data. */
593 cfi_add_CFA_val_offset (unsigned regno, offsetT offset)
595 unsigned int abs_data_align;
597 gas_assert (DWARF2_CIE_DATA_ALIGNMENT != 0);
598 cfi_add_CFA_insn_reg_offset (DW_CFA_val_offset, regno, offset);
600 abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
601 ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
602 if (offset % abs_data_align)
603 as_bad (_("register save offset not a multiple of %u"), abs_data_align);
606 /* Add a DW_CFA_def_cfa record to the CFI data. */
609 cfi_add_CFA_def_cfa (unsigned regno, offsetT offset)
611 cfi_add_CFA_insn_reg_offset (DW_CFA_def_cfa, regno, offset);
612 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
615 /* Add a DW_CFA_register record to the CFI data. */
618 cfi_add_CFA_register (unsigned reg1, unsigned reg2)
620 cfi_add_CFA_insn_reg_reg (DW_CFA_register, reg1, reg2);
623 /* Add a DW_CFA_def_cfa_register record to the CFI data. */
626 cfi_add_CFA_def_cfa_register (unsigned regno)
628 cfi_add_CFA_insn_reg (DW_CFA_def_cfa_register, regno);
631 /* Add a DW_CFA_def_cfa_offset record to the CFI data. */
634 cfi_add_CFA_def_cfa_offset (offsetT offset)
636 cfi_add_CFA_insn_offset (DW_CFA_def_cfa_offset, offset);
637 frchain_now->frch_cfi_data->cur_cfa_offset = offset;
641 cfi_add_CFA_restore (unsigned regno)
643 cfi_add_CFA_insn_reg (DW_CFA_restore, regno);
647 cfi_add_CFA_undefined (unsigned regno)
649 cfi_add_CFA_insn_reg (DW_CFA_undefined, regno);
653 cfi_add_CFA_same_value (unsigned regno)
655 cfi_add_CFA_insn_reg (DW_CFA_same_value, regno);
659 cfi_add_CFA_remember_state (void)
661 struct cfa_save_data *p;
663 cfi_add_CFA_insn (DW_CFA_remember_state);
665 p = XNEW (struct cfa_save_data);
666 p->cfa_offset = frchain_now->frch_cfi_data->cur_cfa_offset;
667 p->next = frchain_now->frch_cfi_data->cfa_save_stack;
668 frchain_now->frch_cfi_data->cfa_save_stack = p;
672 cfi_add_CFA_restore_state (void)
674 struct cfa_save_data *p;
676 cfi_add_CFA_insn (DW_CFA_restore_state);
678 p = frchain_now->frch_cfi_data->cfa_save_stack;
681 frchain_now->frch_cfi_data->cur_cfa_offset = p->cfa_offset;
682 frchain_now->frch_cfi_data->cfa_save_stack = p->next;
686 as_bad (_("CFI state restore without previous remember"));
690 /* Parse CFI assembler directives. */
692 static void dot_cfi (int);
693 static void dot_cfi_escape (int);
694 static void dot_cfi_sections (int);
695 static void dot_cfi_startproc (int);
696 static void dot_cfi_endproc (int);
697 static void dot_cfi_fde_data (int);
698 static void dot_cfi_personality (int);
699 static void dot_cfi_personality_id (int);
700 static void dot_cfi_lsda (int);
701 static void dot_cfi_val_encoded_addr (int);
702 static void dot_cfi_inline_lsda (int);
703 static void dot_cfi_label (int);
705 const pseudo_typeS cfi_pseudo_table[] =
707 { "cfi_sections", dot_cfi_sections, 0 },
708 { "cfi_startproc", dot_cfi_startproc, 0 },
709 { "cfi_endproc", dot_cfi_endproc, 0 },
710 { "cfi_fde_data", dot_cfi_fde_data, 0 },
711 { "cfi_def_cfa", dot_cfi, DW_CFA_def_cfa },
712 { "cfi_def_cfa_register", dot_cfi, DW_CFA_def_cfa_register },
713 { "cfi_def_cfa_offset", dot_cfi, DW_CFA_def_cfa_offset },
714 { "cfi_adjust_cfa_offset", dot_cfi, CFI_adjust_cfa_offset },
715 { "cfi_offset", dot_cfi, DW_CFA_offset },
716 { "cfi_rel_offset", dot_cfi, CFI_rel_offset },
717 { "cfi_register", dot_cfi, DW_CFA_register },
718 { "cfi_return_column", dot_cfi, CFI_return_column },
719 { "cfi_restore", dot_cfi, DW_CFA_restore },
720 { "cfi_undefined", dot_cfi, DW_CFA_undefined },
721 { "cfi_same_value", dot_cfi, DW_CFA_same_value },
722 { "cfi_remember_state", dot_cfi, DW_CFA_remember_state },
723 { "cfi_restore_state", dot_cfi, DW_CFA_restore_state },
724 { "cfi_window_save", dot_cfi, DW_CFA_GNU_window_save },
725 { "cfi_escape", dot_cfi_escape, 0 },
726 { "cfi_signal_frame", dot_cfi, CFI_signal_frame },
727 { "cfi_personality", dot_cfi_personality, 0 },
728 { "cfi_personality_id", dot_cfi_personality_id, 0 },
729 { "cfi_lsda", dot_cfi_lsda, 0 },
730 { "cfi_val_encoded_addr", dot_cfi_val_encoded_addr, 0 },
731 { "cfi_inline_lsda", dot_cfi_inline_lsda, 0 },
732 { "cfi_label", dot_cfi_label, 0 },
733 { "cfi_val_offset", dot_cfi, DW_CFA_val_offset },
738 cfi_parse_separator (void)
741 if (*input_line_pointer == ',')
742 input_line_pointer++;
744 as_bad (_("missing separator"));
747 #ifndef tc_parse_to_dw2regnum
749 tc_parse_to_dw2regnum (expressionS *exp)
751 # ifdef tc_regname_to_dw2regnum
753 if (is_name_beginner (*input_line_pointer)
754 || (*input_line_pointer == '%'
755 && is_name_beginner (*++input_line_pointer)))
759 c = get_symbol_name (& name);
761 exp->X_op = O_constant;
762 exp->X_add_number = tc_regname_to_dw2regnum (name);
764 restore_line_pointer (c);
768 expression_and_evaluate (exp);
778 tc_parse_to_dw2regnum (&exp);
783 regno = exp.X_add_number;
793 as_bad (_("bad register expression"));
801 cfi_parse_const (void)
803 return get_absolute_expression ();
812 if (frchain_now->frch_cfi_data == NULL)
814 as_bad (_("CFI instruction used without previous .cfi_startproc"));
815 ignore_rest_of_line ();
819 /* If the last address was not at the current PC, advance to current. */
820 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
821 || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
823 cfi_add_advance_loc (symbol_temp_new_now ());
828 reg1 = cfi_parse_reg ();
829 cfi_parse_separator ();
830 offset = cfi_parse_const ();
831 cfi_add_CFA_offset (reg1, offset);
834 case DW_CFA_val_offset:
835 reg1 = cfi_parse_reg ();
836 cfi_parse_separator ();
837 offset = cfi_parse_const ();
838 cfi_add_CFA_val_offset (reg1, offset);
842 reg1 = cfi_parse_reg ();
843 cfi_parse_separator ();
844 offset = cfi_parse_const ();
845 cfi_add_CFA_offset (reg1,
846 offset - frchain_now->frch_cfi_data->cur_cfa_offset);
850 reg1 = cfi_parse_reg ();
851 cfi_parse_separator ();
852 offset = cfi_parse_const ();
853 cfi_add_CFA_def_cfa (reg1, offset);
856 case DW_CFA_register:
857 reg1 = cfi_parse_reg ();
858 cfi_parse_separator ();
859 reg2 = cfi_parse_reg ();
860 cfi_add_CFA_register (reg1, reg2);
863 case DW_CFA_def_cfa_register:
864 reg1 = cfi_parse_reg ();
865 cfi_add_CFA_def_cfa_register (reg1);
868 case DW_CFA_def_cfa_offset:
869 offset = cfi_parse_const ();
870 cfi_add_CFA_def_cfa_offset (offset);
873 case CFI_adjust_cfa_offset:
874 offset = cfi_parse_const ();
875 cfi_add_CFA_def_cfa_offset (frchain_now->frch_cfi_data->cur_cfa_offset
882 reg1 = cfi_parse_reg ();
883 cfi_add_CFA_restore (reg1);
885 if (*input_line_pointer != ',')
887 ++input_line_pointer;
891 case DW_CFA_undefined:
894 reg1 = cfi_parse_reg ();
895 cfi_add_CFA_undefined (reg1);
897 if (*input_line_pointer != ',')
899 ++input_line_pointer;
903 case DW_CFA_same_value:
904 reg1 = cfi_parse_reg ();
905 cfi_add_CFA_same_value (reg1);
908 case CFI_return_column:
909 reg1 = cfi_parse_reg ();
910 cfi_set_return_column (reg1);
913 case DW_CFA_remember_state:
914 cfi_add_CFA_remember_state ();
917 case DW_CFA_restore_state:
918 cfi_add_CFA_restore_state ();
921 case DW_CFA_GNU_window_save:
922 cfi_add_CFA_insn (DW_CFA_GNU_window_save);
925 case CFI_signal_frame:
926 frchain_now->frch_cfi_data->cur_fde_data->signal_frame = 1;
933 demand_empty_rest_of_line ();
937 dot_cfi_escape (int ignored ATTRIBUTE_UNUSED)
939 struct cfi_escape_data *head, **tail, *e;
940 struct cfi_insn_data *insn;
942 if (frchain_now->frch_cfi_data == NULL)
944 as_bad (_("CFI instruction used without previous .cfi_startproc"));
945 ignore_rest_of_line ();
949 /* If the last address was not at the current PC, advance to current. */
950 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
951 || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
953 cfi_add_advance_loc (symbol_temp_new_now ());
958 e = XNEW (struct cfi_escape_data);
959 do_parse_cons_expression (&e->exp, 1);
963 while (*input_line_pointer++ == ',');
966 insn = alloc_cfi_insn_data ();
967 insn->insn = CFI_escape;
970 --input_line_pointer;
971 demand_empty_rest_of_line ();
975 dot_cfi_personality (int ignored ATTRIBUTE_UNUSED)
977 struct fde_entry *fde;
980 if (frchain_now->frch_cfi_data == NULL)
982 as_bad (_("CFI instruction used without previous .cfi_startproc"));
983 ignore_rest_of_line ();
987 fde = frchain_now->frch_cfi_data->cur_fde_data;
988 encoding = cfi_parse_const ();
989 if (encoding == DW_EH_PE_omit)
991 demand_empty_rest_of_line ();
992 fde->per_encoding = encoding;
996 if ((encoding & 0xff) != encoding
997 || ((((encoding & 0x70) != 0
998 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
999 && (encoding & 0x70) != DW_EH_PE_pcrel
1002 /* leb128 can be handled, but does something actually need it? */
1003 || (encoding & 7) == DW_EH_PE_uleb128
1004 || (encoding & 7) > DW_EH_PE_udata8)
1005 && tc_cfi_reloc_for_encoding (encoding) == BFD_RELOC_NONE))
1007 as_bad (_("invalid or unsupported encoding in .cfi_personality"));
1008 ignore_rest_of_line ();
1012 if (*input_line_pointer++ != ',')
1014 as_bad (_(".cfi_personality requires encoding and symbol arguments"));
1015 ignore_rest_of_line ();
1019 expression_and_evaluate (&fde->personality);
1020 switch (fde->personality.X_op)
1025 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1026 encoding = DW_EH_PE_omit;
1029 encoding = DW_EH_PE_omit;
1033 fde->per_encoding = encoding;
1035 if (encoding == DW_EH_PE_omit)
1037 as_bad (_("wrong second argument to .cfi_personality"));
1038 ignore_rest_of_line ();
1042 demand_empty_rest_of_line ();
1046 dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED)
1048 struct fde_entry *fde;
1051 if (frchain_now->frch_cfi_data == NULL)
1053 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1054 ignore_rest_of_line ();
1058 fde = frchain_now->frch_cfi_data->cur_fde_data;
1059 encoding = cfi_parse_const ();
1060 if (encoding == DW_EH_PE_omit)
1062 demand_empty_rest_of_line ();
1063 fde->lsda_encoding = encoding;
1067 if ((encoding & 0xff) != encoding
1068 || ((((encoding & 0x70) != 0
1069 #if CFI_DIFF_LSDA_OK || defined tc_cfi_emit_pcrel_expr
1070 && (encoding & 0x70) != DW_EH_PE_pcrel
1073 /* leb128 can be handled, but does something actually need it? */
1074 || (encoding & 7) == DW_EH_PE_uleb128
1075 || (encoding & 7) > DW_EH_PE_udata8)
1076 && tc_cfi_reloc_for_encoding (encoding) == BFD_RELOC_NONE))
1078 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1079 ignore_rest_of_line ();
1083 if (*input_line_pointer++ != ',')
1085 as_bad (_(".cfi_lsda requires encoding and symbol arguments"));
1086 ignore_rest_of_line ();
1090 fde->lsda_encoding = encoding;
1092 expression_and_evaluate (&fde->lsda);
1093 switch (fde->lsda.X_op)
1098 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1099 encoding = DW_EH_PE_omit;
1102 encoding = DW_EH_PE_omit;
1106 fde->lsda_encoding = encoding;
1108 if (encoding == DW_EH_PE_omit)
1110 as_bad (_("wrong second argument to .cfi_lsda"));
1111 ignore_rest_of_line ();
1115 demand_empty_rest_of_line ();
1119 dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED)
1121 struct cfi_insn_data *insn_ptr;
1124 if (frchain_now->frch_cfi_data == NULL)
1126 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1127 ignore_rest_of_line ();
1131 /* If the last address was not at the current PC, advance to current. */
1132 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
1133 || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
1134 != frag_now_fix ()))
1135 cfi_add_advance_loc (symbol_temp_new_now ());
1137 insn_ptr = alloc_cfi_insn_data ();
1138 insn_ptr->insn = CFI_val_encoded_addr;
1140 insn_ptr->u.ea.reg = cfi_parse_reg ();
1142 cfi_parse_separator ();
1143 encoding = cfi_parse_const ();
1144 if ((encoding & 0xff) != encoding
1145 || ((encoding & 0x70) != 0
1146 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1147 && (encoding & 0x70) != DW_EH_PE_pcrel
1150 /* leb128 can be handled, but does something actually need it? */
1151 || (encoding & 7) == DW_EH_PE_uleb128
1152 || (encoding & 7) > DW_EH_PE_udata8)
1154 as_bad (_("invalid or unsupported encoding in .cfi_lsda"));
1155 encoding = DW_EH_PE_omit;
1158 cfi_parse_separator ();
1159 expression_and_evaluate (&insn_ptr->u.ea.exp);
1160 switch (insn_ptr->u.ea.exp.X_op)
1165 if ((encoding & 0x70) != DW_EH_PE_pcrel)
1169 encoding = DW_EH_PE_omit;
1173 insn_ptr->u.ea.encoding = encoding;
1174 if (encoding == DW_EH_PE_omit)
1176 as_bad (_("wrong third argument to .cfi_val_encoded_addr"));
1177 ignore_rest_of_line ();
1181 demand_empty_rest_of_line ();
1185 dot_cfi_label (int ignored ATTRIBUTE_UNUSED)
1189 if (frchain_now->frch_cfi_data == NULL)
1191 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1192 ignore_rest_of_line ();
1196 name = read_symbol_name ();
1200 /* If the last address was not at the current PC, advance to current. */
1201 if (symbol_get_frag (frchain_now->frch_cfi_data->last_address) != frag_now
1202 || (S_GET_VALUE (frchain_now->frch_cfi_data->last_address)
1203 != frag_now_fix ()))
1204 cfi_add_advance_loc (symbol_temp_new_now ());
1206 cfi_add_label (name);
1209 demand_empty_rest_of_line ();
1213 dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
1218 if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"')
1224 saved_ilp = input_line_pointer;
1225 c = get_symbol_name (& name);
1227 if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0
1229 sections |= CFI_EMIT_eh_frame;
1230 else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0)
1231 sections |= CFI_EMIT_debug_frame;
1232 #if SUPPORT_COMPACT_EH
1233 else if (strncmp (name, ".eh_frame_entry",
1234 sizeof ".eh_frame_entry") == 0)
1237 sections |= CFI_EMIT_eh_frame_compact;
1240 #ifdef tc_cfi_section_name
1241 else if (strcmp (name, tc_cfi_section_name) == 0)
1242 sections |= CFI_EMIT_target;
1246 *input_line_pointer = c;
1247 input_line_pointer = saved_ilp;
1251 *input_line_pointer = c;
1252 SKIP_WHITESPACE_AFTER_NAME ();
1253 if (*input_line_pointer == ',')
1255 name = input_line_pointer++;
1257 if (!is_name_beginner (*input_line_pointer)
1258 && *input_line_pointer != '"')
1260 input_line_pointer = name;
1264 else if (is_name_beginner (*input_line_pointer)
1265 || *input_line_pointer == '"')
1269 demand_empty_rest_of_line ();
1270 if (cfi_sections_set
1271 && (sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact))
1272 && ((cfi_sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact))
1273 != (sections & (CFI_EMIT_eh_frame | CFI_EMIT_eh_frame_compact))))
1274 as_bad (_("inconsistent uses of .cfi_sections"));
1275 cfi_sections = sections;
1279 dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
1283 if (frchain_now->frch_cfi_data != NULL)
1285 as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
1286 ignore_rest_of_line ();
1290 cfi_new_fde (symbol_temp_new_now ());
1293 if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"')
1295 char * saved_ilp = input_line_pointer;
1298 c = get_symbol_name (& name);
1300 if (strcmp (name, "simple") == 0)
1303 restore_line_pointer (c);
1306 input_line_pointer = saved_ilp;
1308 demand_empty_rest_of_line ();
1310 cfi_sections_set = TRUE;
1311 all_cfi_sections |= cfi_sections;
1312 cfi_set_sections ();
1313 frchain_now->frch_cfi_data->cur_cfa_offset = 0;
1315 tc_cfi_frame_initial_instructions ();
1317 if ((cfi_sections & CFI_EMIT_target) != 0)
1318 tc_cfi_startproc ();
1322 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED)
1324 if (frchain_now->frch_cfi_data == NULL)
1326 as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
1327 ignore_rest_of_line ();
1331 last_fde = frchain_now->frch_cfi_data->cur_fde_data;
1333 cfi_end_fde (symbol_temp_new_now ());
1335 demand_empty_rest_of_line ();
1337 cfi_sections_set = TRUE;
1338 if ((cfi_sections & CFI_EMIT_target) != 0)
1339 tc_cfi_endproc (last_fde);
1343 get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
1345 /* Exclude .debug_frame sections for Compact EH. */
1346 if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh))
1348 struct dwcfi_seg_list *l;
1350 l = dwcfi_hash_find_or_make (cseg, base, flags);
1353 subseg_set (cseg, l->subseg);
1357 cseg = subseg_new (base, 0);
1358 bfd_set_section_flags (stdoutput, cseg, flags);
1360 record_alignment (cseg, align);
1364 #if SUPPORT_COMPACT_EH
1366 dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED)
1368 struct fde_entry *fde;
1370 if (frchain_now->frch_cfi_data == NULL)
1372 as_bad (_("CFI instruction used without previous .cfi_startproc"));
1373 ignore_rest_of_line ();
1377 fde = frchain_now->frch_cfi_data->cur_fde_data;
1378 fde->personality_id = cfi_parse_const ();
1379 demand_empty_rest_of_line ();
1381 if (fde->personality_id == 0 || fde->personality_id > 3)
1383 as_bad (_("wrong argument to .cfi_personality_id"));
1389 dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED)
1391 if (frchain_now->frch_cfi_data == NULL)
1393 as_bad (_(".cfi_fde_data without corresponding .cfi_startproc"));
1394 ignore_rest_of_line ();
1398 last_fde = frchain_now->frch_cfi_data->cur_fde_data;
1400 cfi_sections_set = TRUE;
1401 if ((cfi_sections & CFI_EMIT_target) != 0
1402 || (cfi_sections & CFI_EMIT_eh_frame_compact) != 0)
1404 struct cfi_escape_data *head, **tail, *e;
1408 if (!is_it_end_of_statement ())
1413 e = XNEW (struct cfi_escape_data);
1414 do_parse_cons_expression (&e->exp, 1);
1419 while (*input_line_pointer++ == ',');
1420 --input_line_pointer;
1424 if (last_fde->lsda_encoding != DW_EH_PE_omit)
1425 last_fde->eh_header_type = EH_COMPACT_HAS_LSDA;
1426 else if (num_ops <= 3 && last_fde->per_encoding == DW_EH_PE_omit)
1427 last_fde->eh_header_type = EH_COMPACT_INLINE;
1429 last_fde->eh_header_type = EH_COMPACT_OUTLINE;
1431 if (last_fde->eh_header_type == EH_COMPACT_INLINE)
1434 last_fde->eh_data_size = num_ops;
1435 last_fde->eh_data = XNEWVEC (bfd_byte, num_ops);
1441 last_fde->eh_data[num_ops++] = e->exp.X_add_number;
1444 if (last_fde->eh_header_type == EH_COMPACT_INLINE)
1446 last_fde->eh_data[num_ops++] = tc_compact_eh_opcode_stop;
1449 demand_empty_rest_of_line ();
1452 /* Function to emit the compact unwinding opcodes stored in the
1453 fde's eh_data field. The end of the opcode data will be
1454 padded to the value in align. */
1457 output_compact_unwind_data (struct fde_entry *fde, int align)
1459 int data_size = fde->eh_data_size + 2;
1464 fde->eh_loc = symbol_temp_new_now ();
1467 if (fde->personality_id != 0)
1468 *p = fde->personality_id;
1469 else if (fde->per_encoding != DW_EH_PE_omit)
1472 emit_expr_encoded (&fde->personality, fde->per_encoding, FALSE);
1473 data_size += encoding_size (fde->per_encoding);
1478 amask = (1 << align) - 1;
1479 align_padding = ((data_size + amask) & ~amask) - data_size;
1481 p = frag_more (fde->eh_data_size + 1 + align_padding);
1482 memcpy (p, fde->eh_data, fde->eh_data_size);
1483 p += fde->eh_data_size;
1485 while (align_padding-- > 0)
1486 *(p++) = tc_compact_eh_opcode_pad;
1488 *(p++) = tc_compact_eh_opcode_stop;
1489 fde->eh_header_type = EH_COMPACT_OUTLINE_DONE;
1492 /* Handle the .cfi_inline_lsda directive. */
1494 dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED)
1498 long max_alignment = 28;
1502 as_bad (_("unexpected .cfi_inline_lsda"));
1503 ignore_rest_of_line ();
1507 if ((last_fde->sections & CFI_EMIT_eh_frame_compact) == 0)
1509 as_bad (_(".cfi_inline_lsda not valid for this frame"));
1510 ignore_rest_of_line ();
1514 if (last_fde->eh_header_type != EH_COMPACT_UNKNOWN
1515 && last_fde->eh_header_type != EH_COMPACT_HAS_LSDA)
1517 as_bad (_(".cfi_inline_lsda seen for frame without .cfi_lsda"));
1518 ignore_rest_of_line ();
1522 #ifdef md_flush_pending_output
1523 md_flush_pending_output ();
1526 align = get_absolute_expression ();
1527 if (align > max_alignment)
1529 align = max_alignment;
1530 as_bad (_("Alignment too large: %d. assumed."), align);
1534 as_warn (_("Alignment negative: 0 assumed."));
1538 demand_empty_rest_of_line ();
1539 ccseg = CUR_SEG (last_fde);
1541 /* Open .gnu_extab section. */
1542 get_cfi_seg (ccseg, ".gnu_extab",
1543 (SEC_ALLOC | SEC_LOAD | SEC_DATA
1544 | DWARF2_EH_FRAME_READ_ONLY),
1547 frag_align (align, 0, 0);
1548 record_alignment (now_seg, align);
1549 if (last_fde->eh_header_type == EH_COMPACT_HAS_LSDA)
1550 output_compact_unwind_data (last_fde, align);
1556 #else /* !SUPPORT_COMPACT_EH */
1558 dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED)
1560 as_bad (_(".cfi_inline_lsda is not supported for this target"));
1561 ignore_rest_of_line ();
1565 dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED)
1567 as_bad (_(".cfi_fde_data is not supported for this target"));
1568 ignore_rest_of_line ();
1572 dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED)
1574 as_bad (_(".cfi_personality_id is not supported for this target"));
1575 ignore_rest_of_line ();
1580 output_cfi_insn (struct cfi_insn_data *insn)
1587 case DW_CFA_advance_loc:
1589 symbolS *from = insn->u.ll.lab1;
1590 symbolS *to = insn->u.ll.lab2;
1592 if (symbol_get_frag (to) == symbol_get_frag (from))
1594 addressT delta = S_GET_VALUE (to) - S_GET_VALUE (from);
1595 addressT scaled = delta / DWARF2_LINE_MIN_INSN_LENGTH;
1598 out_one (DW_CFA_advance_loc + scaled);
1599 else if (scaled <= 0xFF)
1601 out_one (DW_CFA_advance_loc1);
1604 else if (scaled <= 0xFFFF)
1606 out_one (DW_CFA_advance_loc2);
1611 out_one (DW_CFA_advance_loc4);
1619 exp.X_op = O_subtract;
1620 exp.X_add_symbol = to;
1621 exp.X_op_symbol = from;
1622 exp.X_add_number = 0;
1624 /* The code in ehopt.c expects that one byte of the encoding
1625 is already allocated to the frag. This comes from the way
1626 that it scans the .eh_frame section looking first for the
1627 .byte DW_CFA_advance_loc4. */
1628 *frag_more (1) = DW_CFA_advance_loc4;
1630 frag_var (rs_cfa, 4, 0, DWARF2_LINE_MIN_INSN_LENGTH << 3,
1631 make_expr_symbol (&exp), frag_now_fix () - 1,
1637 case DW_CFA_def_cfa:
1638 offset = insn->u.ri.offset;
1641 out_one (DW_CFA_def_cfa_sf);
1642 out_uleb128 (insn->u.ri.reg);
1643 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1647 out_one (DW_CFA_def_cfa);
1648 out_uleb128 (insn->u.ri.reg);
1649 out_uleb128 (offset);
1653 case DW_CFA_def_cfa_register:
1654 case DW_CFA_undefined:
1655 case DW_CFA_same_value:
1656 out_one (insn->insn);
1657 out_uleb128 (insn->u.r);
1660 case DW_CFA_def_cfa_offset:
1664 out_one (DW_CFA_def_cfa_offset_sf);
1665 out_sleb128 (offset / DWARF2_CIE_DATA_ALIGNMENT);
1669 out_one (DW_CFA_def_cfa_offset);
1670 out_uleb128 (offset);
1674 case DW_CFA_restore:
1678 out_one (DW_CFA_restore + regno);
1682 out_one (DW_CFA_restore_extended);
1683 out_uleb128 (regno);
1688 regno = insn->u.ri.reg;
1689 offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT;
1692 out_one (DW_CFA_offset_extended_sf);
1693 out_uleb128 (regno);
1694 out_sleb128 (offset);
1696 else if (regno <= 0x3F)
1698 out_one (DW_CFA_offset + regno);
1699 out_uleb128 (offset);
1703 out_one (DW_CFA_offset_extended);
1704 out_uleb128 (regno);
1705 out_uleb128 (offset);
1709 case DW_CFA_val_offset:
1710 regno = insn->u.ri.reg;
1711 offset = insn->u.ri.offset / DWARF2_CIE_DATA_ALIGNMENT;
1714 out_one (DW_CFA_val_offset_sf);
1715 out_uleb128 (regno);
1716 out_sleb128 (offset);
1720 out_one (DW_CFA_val_offset);
1721 out_uleb128 (regno);
1722 out_uleb128 (offset);
1726 case DW_CFA_register:
1727 out_one (DW_CFA_register);
1728 out_uleb128 (insn->u.rr.reg1);
1729 out_uleb128 (insn->u.rr.reg2);
1732 case DW_CFA_remember_state:
1733 case DW_CFA_restore_state:
1734 out_one (insn->insn);
1737 case DW_CFA_GNU_window_save:
1738 out_one (DW_CFA_GNU_window_save);
1743 struct cfi_escape_data *e;
1744 for (e = insn->u.esc; e ; e = e->next)
1745 emit_expr (&e->exp, 1);
1749 case CFI_val_encoded_addr:
1751 unsigned encoding = insn->u.ea.encoding;
1754 if (encoding == DW_EH_PE_omit)
1756 out_one (DW_CFA_val_expression);
1757 out_uleb128 (insn->u.ea.reg);
1759 switch (encoding & 0x7)
1761 case DW_EH_PE_absptr:
1762 enc_size = DWARF2_ADDR_SIZE (stdoutput);
1764 case DW_EH_PE_udata2:
1767 case DW_EH_PE_udata4:
1770 case DW_EH_PE_udata8:
1777 /* If the user has requested absolute encoding,
1778 then use the smaller DW_OP_addr encoding. */
1779 if (insn->u.ea.encoding == DW_EH_PE_absptr)
1781 out_uleb128 (1 + enc_size);
1782 out_one (DW_OP_addr);
1786 out_uleb128 (1 + 1 + enc_size);
1787 out_one (DW_OP_GNU_encoded_addr);
1790 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1792 #if CFI_DIFF_EXPR_OK
1793 insn->u.ea.exp.X_op = O_subtract;
1794 insn->u.ea.exp.X_op_symbol = symbol_temp_new_now ();
1795 #elif defined (tc_cfi_emit_pcrel_expr)
1796 tc_cfi_emit_pcrel_expr (&insn->u.ea.exp, enc_size);
1803 emit_expr (&insn->u.ea.exp, enc_size);
1808 colon (insn->u.sym_name);
1817 output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
1819 symbolS *after_size_address, *end_address;
1821 struct cfi_insn_data *i;
1822 offsetT augmentation_size;
1824 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1826 cie->start_address = symbol_temp_new_now ();
1827 after_size_address = symbol_temp_make ();
1828 end_address = symbol_temp_make ();
1830 exp.X_op = O_subtract;
1831 exp.X_add_symbol = end_address;
1832 exp.X_op_symbol = after_size_address;
1833 exp.X_add_number = 0;
1835 if (eh_frame || fmt == dwarf2_format_32bit)
1836 emit_expr (&exp, 4); /* Length. */
1839 if (fmt == dwarf2_format_64bit)
1841 emit_expr (&exp, 8); /* Length. */
1843 symbol_set_value_now (after_size_address);
1845 out_four (0); /* CIE id. */
1848 out_four (-1); /* CIE id. */
1849 if (fmt != dwarf2_format_32bit)
1852 out_one (DW_CIE_VERSION); /* Version. */
1855 out_one ('z'); /* Augmentation. */
1856 if (cie->per_encoding != DW_EH_PE_omit)
1858 if (cie->lsda_encoding != DW_EH_PE_omit)
1861 if (cie->pauth_key == AARCH64_PAUTH_KEY_B)
1864 if (cie->signal_frame)
1867 out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH); /* Code alignment. */
1868 out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT); /* Data alignment. */
1869 if (DW_CIE_VERSION == 1) /* Return column. */
1870 out_one (cie->return_column);
1872 out_uleb128 (cie->return_column);
1875 augmentation_size = 1 + (cie->lsda_encoding != DW_EH_PE_omit);
1876 if (cie->per_encoding != DW_EH_PE_omit)
1877 augmentation_size += 1 + encoding_size (cie->per_encoding);
1878 out_uleb128 (augmentation_size); /* Augmentation size. */
1880 emit_expr_encoded (&cie->personality, cie->per_encoding, TRUE);
1882 if (cie->lsda_encoding != DW_EH_PE_omit)
1883 out_one (cie->lsda_encoding);
1886 switch (DWARF2_FDE_RELOC_SIZE)
1889 enc = DW_EH_PE_sdata2;
1892 enc = DW_EH_PE_sdata4;
1895 enc = DW_EH_PE_sdata8;
1900 #if CFI_DIFF_EXPR_OK || defined tc_cfi_emit_pcrel_expr
1901 enc |= DW_EH_PE_pcrel;
1903 #ifdef DWARF2_FDE_RELOC_ENCODING
1904 /* Allow target to override encoding. */
1905 enc = DWARF2_FDE_RELOC_ENCODING (enc);
1907 cie->fde_encoding = enc;
1913 for (i = cie->first; i != cie->last; i = i->next)
1915 if (CUR_SEG (i) != CUR_SEG (cie))
1917 output_cfi_insn (i);
1921 frag_align (align, DW_CFA_nop, 0);
1922 symbol_set_value_now (end_address);
1926 output_fde (struct fde_entry *fde, struct cie_entry *cie,
1927 bfd_boolean eh_frame, struct cfi_insn_data *first,
1930 symbolS *after_size_address, *end_address;
1932 offsetT augmentation_size;
1933 enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
1934 unsigned int offset_size;
1935 unsigned int addr_size;
1937 after_size_address = symbol_temp_make ();
1938 end_address = symbol_temp_make ();
1940 exp.X_op = O_subtract;
1941 exp.X_add_symbol = end_address;
1942 exp.X_op_symbol = after_size_address;
1943 exp.X_add_number = 0;
1944 if (eh_frame || fmt == dwarf2_format_32bit)
1948 if (fmt == dwarf2_format_64bit)
1952 emit_expr (&exp, offset_size); /* Length. */
1953 symbol_set_value_now (after_size_address);
1957 exp.X_op = O_subtract;
1958 exp.X_add_symbol = after_size_address;
1959 exp.X_op_symbol = cie->start_address;
1960 exp.X_add_number = 0;
1961 emit_expr (&exp, offset_size); /* CIE offset. */
1965 TC_DWARF2_EMIT_OFFSET (cie->start_address, offset_size);
1968 exp.X_op = O_symbol;
1971 bfd_reloc_code_real_type code
1972 = tc_cfi_reloc_for_encoding (cie->fde_encoding);
1973 addr_size = DWARF2_FDE_RELOC_SIZE;
1974 if (code != BFD_RELOC_NONE)
1976 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
1977 char *p = frag_more (addr_size);
1978 gas_assert (addr_size == (unsigned) howto->bitsize / 8);
1979 md_number_to_chars (p, 0, addr_size);
1980 fix_new (frag_now, p - frag_now->fr_literal, addr_size,
1981 fde->start_address, 0, howto->pc_relative, code);
1985 exp.X_op = O_subtract;
1986 exp.X_add_number = 0;
1987 #if CFI_DIFF_EXPR_OK
1988 exp.X_add_symbol = fde->start_address;
1989 exp.X_op_symbol = symbol_temp_new_now ();
1990 emit_expr (&exp, addr_size); /* Code offset. */
1992 exp.X_op = O_symbol;
1993 exp.X_add_symbol = fde->start_address;
1995 #if defined(tc_cfi_emit_pcrel_expr)
1996 tc_cfi_emit_pcrel_expr (&exp, addr_size); /* Code offset. */
1998 emit_expr (&exp, addr_size); /* Code offset. */
2005 exp.X_add_number = 0;
2006 exp.X_add_symbol = fde->start_address;
2007 addr_size = DWARF2_ADDR_SIZE (stdoutput);
2008 emit_expr (&exp, addr_size);
2011 exp.X_op = O_subtract;
2012 exp.X_add_symbol = fde->end_address;
2013 exp.X_op_symbol = fde->start_address; /* Code length. */
2014 exp.X_add_number = 0;
2015 emit_expr (&exp, addr_size);
2017 augmentation_size = encoding_size (fde->lsda_encoding);
2019 out_uleb128 (augmentation_size); /* Augmentation size. */
2021 emit_expr_encoded (&fde->lsda, cie->lsda_encoding, FALSE);
2023 for (; first; first = first->next)
2024 if (CUR_SEG (first) == CUR_SEG (fde))
2025 output_cfi_insn (first);
2027 frag_align (align, DW_CFA_nop, 0);
2028 symbol_set_value_now (end_address);
2031 static struct cie_entry *
2032 select_cie_for_fde (struct fde_entry *fde, bfd_boolean eh_frame,
2033 struct cfi_insn_data **pfirst, int align)
2035 struct cfi_insn_data *i, *j;
2036 struct cie_entry *cie;
2038 for (cie = cie_root; cie; cie = cie->next)
2040 if (CUR_SEG (cie) != CUR_SEG (fde))
2042 if (cie->return_column != fde->return_column
2043 || cie->pauth_key != fde->pauth_key
2044 || cie->signal_frame != fde->signal_frame
2045 || cie->per_encoding != fde->per_encoding
2046 || cie->lsda_encoding != fde->lsda_encoding)
2048 if (cie->per_encoding != DW_EH_PE_omit)
2050 if (cie->personality.X_op != fde->personality.X_op
2051 || (cie->personality.X_add_number
2052 != fde->personality.X_add_number))
2054 switch (cie->personality.X_op)
2057 if (cie->personality.X_unsigned != fde->personality.X_unsigned)
2061 if (cie->personality.X_add_symbol
2062 != fde->personality.X_add_symbol)
2069 for (i = cie->first, j = fde->data;
2070 i != cie->last && j != NULL;
2071 i = i->next, j = j->next)
2073 if (i->insn != j->insn)
2077 case DW_CFA_advance_loc:
2078 case DW_CFA_remember_state:
2079 /* We reached the first advance/remember in the FDE,
2080 but did not reach the end of the CIE list. */
2084 case DW_CFA_def_cfa:
2085 if (i->u.ri.reg != j->u.ri.reg)
2087 if (i->u.ri.offset != j->u.ri.offset)
2091 case DW_CFA_register:
2092 if (i->u.rr.reg1 != j->u.rr.reg1)
2094 if (i->u.rr.reg2 != j->u.rr.reg2)
2098 case DW_CFA_def_cfa_register:
2099 case DW_CFA_restore:
2100 case DW_CFA_undefined:
2101 case DW_CFA_same_value:
2102 if (i->u.r != j->u.r)
2106 case DW_CFA_def_cfa_offset:
2107 if (i->u.i != j->u.i)
2112 case CFI_val_encoded_addr:
2114 /* Don't bother matching these for now. */
2122 /* Success if we reached the end of the CIE list, and we've either
2123 run out of FDE entries or we've encountered an advance,
2124 remember, or escape. */
2127 || j->insn == DW_CFA_advance_loc
2128 || j->insn == DW_CFA_remember_state
2129 || j->insn == CFI_escape
2130 || j->insn == CFI_val_encoded_addr
2131 || j->insn == CFI_label))
2140 cie = XNEW (struct cie_entry);
2141 cie->next = cie_root;
2143 SET_CUR_SEG (cie, CUR_SEG (fde));
2144 cie->return_column = fde->return_column;
2145 cie->signal_frame = fde->signal_frame;
2146 cie->per_encoding = fde->per_encoding;
2147 cie->lsda_encoding = fde->lsda_encoding;
2148 cie->personality = fde->personality;
2149 cie->first = fde->data;
2150 cie->pauth_key = fde->pauth_key;
2152 for (i = cie->first; i ; i = i->next)
2153 if (i->insn == DW_CFA_advance_loc
2154 || i->insn == DW_CFA_remember_state
2155 || i->insn == CFI_escape
2156 || i->insn == CFI_val_encoded_addr
2157 || i->insn == CFI_label)
2163 output_cie (cie, eh_frame, align);
2168 #ifdef md_reg_eh_frame_to_debug_frame
2170 cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
2172 for (; insn; insn = insn->next)
2174 if (CUR_SEG (insn) != ccseg)
2178 case DW_CFA_advance_loc:
2179 case DW_CFA_def_cfa_offset:
2180 case DW_CFA_remember_state:
2181 case DW_CFA_restore_state:
2182 case DW_CFA_GNU_window_save:
2187 case DW_CFA_def_cfa:
2189 insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
2192 case DW_CFA_def_cfa_register:
2193 case DW_CFA_undefined:
2194 case DW_CFA_same_value:
2195 case DW_CFA_restore:
2196 insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
2199 case DW_CFA_register:
2200 insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
2201 insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
2204 case CFI_val_encoded_addr:
2205 insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
2214 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
2217 #if SUPPORT_COMPACT_EH
2219 cfi_emit_eh_header (symbolS *sym, bfd_vma addend)
2223 exp.X_add_number = addend;
2224 exp.X_add_symbol = sym;
2225 emit_expr_encoded (&exp, DW_EH_PE_sdata4 | DW_EH_PE_pcrel, FALSE);
2229 output_eh_header (struct fde_entry *fde)
2234 if (fde->eh_header_type == EH_COMPACT_INLINE)
2239 cfi_emit_eh_header (fde->start_address, addend);
2241 if (fde->eh_header_type == EH_COMPACT_INLINE)
2244 /* Inline entries always use PR1. */
2246 memcpy(p, fde->eh_data, 3);
2250 if (fde->eh_header_type == EH_COMPACT_LEGACY)
2252 else if (fde->eh_header_type == EH_COMPACT_OUTLINE
2253 || fde->eh_header_type == EH_COMPACT_OUTLINE_DONE)
2257 cfi_emit_eh_header (fde->eh_loc, addend);
2265 struct cie_entry *cie, *cie_next;
2266 segT cfi_seg, ccseg;
2267 struct fde_entry *fde;
2268 struct cfi_insn_data *first;
2269 int save_flag_traditional_format, seek_next_seg;
2271 if (all_fde_data == 0)
2274 cfi_sections_set = TRUE;
2275 if ((all_cfi_sections & CFI_EMIT_eh_frame) != 0
2276 || (all_cfi_sections & CFI_EMIT_eh_frame_compact) != 0)
2278 /* Make sure check_eh_frame doesn't do anything with our output. */
2279 save_flag_traditional_format = flag_traditional_format;
2280 flag_traditional_format = 1;
2282 if (!EH_FRAME_LINKONCE)
2284 /* Open .eh_frame section. */
2285 cfi_seg = get_cfi_seg (NULL, ".eh_frame",
2286 (SEC_ALLOC | SEC_LOAD | SEC_DATA
2287 | DWARF2_EH_FRAME_READ_ONLY),
2288 EH_FRAME_ALIGNMENT);
2289 #ifdef md_fix_up_eh_frame
2290 md_fix_up_eh_frame (cfi_seg);
2301 for (cie = cie_root; cie; cie = cie_next)
2303 cie_next = cie->next;
2304 free ((void *) cie);
2308 for (fde = all_fde_data; fde ; fde = fde->next)
2310 if ((fde->sections & CFI_EMIT_eh_frame) == 0
2311 && (fde->sections & CFI_EMIT_eh_frame_compact) == 0)
2314 #if SUPPORT_COMPACT_EH
2315 /* Emit a LEGACY format header if we have processed all
2316 of the .cfi directives without encountering either inline or
2317 out-of-line compact unwinding opcodes. */
2318 if (fde->eh_header_type == EH_COMPACT_HAS_LSDA
2319 || fde->eh_header_type == EH_COMPACT_UNKNOWN)
2320 fde->eh_header_type = EH_COMPACT_LEGACY;
2322 if (fde->eh_header_type != EH_COMPACT_LEGACY)
2325 if (EH_FRAME_LINKONCE)
2329 if (seek_next_seg && CUR_SEG (fde) != ccseg)
2336 ccseg = CUR_SEG (fde);
2337 /* Open .eh_frame section. */
2338 cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
2339 (SEC_ALLOC | SEC_LOAD | SEC_DATA
2340 | DWARF2_EH_FRAME_READ_ONLY),
2341 EH_FRAME_ALIGNMENT);
2342 #ifdef md_fix_up_eh_frame
2343 md_fix_up_eh_frame (cfi_seg);
2349 SET_HANDLED (fde, 1);
2352 if (fde->end_address == NULL)
2354 as_bad (_("open CFI at the end of file; "
2355 "missing .cfi_endproc directive"));
2356 fde->end_address = fde->start_address;
2359 cie = select_cie_for_fde (fde, TRUE, &first, 2);
2360 fde->eh_loc = symbol_temp_new_now ();
2361 output_fde (fde, cie, TRUE, first,
2362 fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
2365 while (EH_FRAME_LINKONCE && seek_next_seg == 2);
2367 if (EH_FRAME_LINKONCE)
2368 for (fde = all_fde_data; fde ; fde = fde->next)
2369 SET_HANDLED (fde, 0);
2371 #if SUPPORT_COMPACT_EH
2374 /* Create remaining out of line table entries. */
2380 for (fde = all_fde_data; fde ; fde = fde->next)
2382 if ((fde->sections & CFI_EMIT_eh_frame) == 0
2383 && (fde->sections & CFI_EMIT_eh_frame_compact) == 0)
2386 if (fde->eh_header_type != EH_COMPACT_OUTLINE)
2390 if (seek_next_seg && CUR_SEG (fde) != ccseg)
2397 ccseg = CUR_SEG (fde);
2398 /* Open .gnu_extab section. */
2399 get_cfi_seg (ccseg, ".gnu_extab",
2400 (SEC_ALLOC | SEC_LOAD | SEC_DATA
2401 | DWARF2_EH_FRAME_READ_ONLY),
2405 SET_HANDLED (fde, 1);
2407 frag_align (1, 0, 0);
2408 record_alignment (now_seg, 1);
2409 output_compact_unwind_data (fde, 1);
2412 while (EH_FRAME_LINKONCE && seek_next_seg == 2);
2414 for (fde = all_fde_data; fde ; fde = fde->next)
2415 SET_HANDLED (fde, 0);
2417 /* Create index table fragments. */
2423 for (fde = all_fde_data; fde ; fde = fde->next)
2425 if ((fde->sections & CFI_EMIT_eh_frame) == 0
2426 && (fde->sections & CFI_EMIT_eh_frame_compact) == 0)
2431 if (seek_next_seg && CUR_SEG (fde) != ccseg)
2438 ccseg = CUR_SEG (fde);
2439 /* Open .eh_frame_entry section. */
2440 cfi_seg = get_cfi_seg (ccseg, ".eh_frame_entry",
2441 (SEC_ALLOC | SEC_LOAD | SEC_DATA
2442 | DWARF2_EH_FRAME_READ_ONLY),
2446 SET_HANDLED (fde, 1);
2448 output_eh_header (fde);
2451 while (seek_next_seg == 2);
2453 for (fde = all_fde_data; fde ; fde = fde->next)
2454 SET_HANDLED (fde, 0);
2456 #endif /* SUPPORT_COMPACT_EH */
2458 flag_traditional_format = save_flag_traditional_format;
2461 cfi_sections_set = TRUE;
2462 if ((all_cfi_sections & CFI_EMIT_debug_frame) != 0)
2464 int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
2466 if (!SUPPORT_FRAME_LINKONCE)
2467 get_cfi_seg (NULL, ".debug_frame",
2468 SEC_READONLY | SEC_DEBUGGING,
2476 for (cie = cie_root; cie; cie = cie_next)
2478 cie_next = cie->next;
2479 free ((void *) cie);
2483 for (fde = all_fde_data; fde ; fde = fde->next)
2485 if ((fde->sections & CFI_EMIT_debug_frame) == 0)
2488 if (SUPPORT_FRAME_LINKONCE)
2492 if (seek_next_seg && CUR_SEG (fde) != ccseg)
2499 ccseg = CUR_SEG (fde);
2500 /* Open .debug_frame section. */
2501 get_cfi_seg (ccseg, ".debug_frame",
2502 SEC_READONLY | SEC_DEBUGGING,
2506 SET_HANDLED (fde, 1);
2508 if (fde->end_address == NULL)
2510 as_bad (_("open CFI at the end of file; "
2511 "missing .cfi_endproc directive"));
2512 fde->end_address = fde->start_address;
2515 fde->per_encoding = DW_EH_PE_omit;
2516 fde->lsda_encoding = DW_EH_PE_omit;
2517 cfi_change_reg_numbers (fde->data, ccseg);
2518 cie = select_cie_for_fde (fde, FALSE, &first, alignment);
2519 output_fde (fde, cie, FALSE, first, alignment);
2522 while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
2524 if (SUPPORT_FRAME_LINKONCE)
2525 for (fde = all_fde_data; fde ; fde = fde->next)
2526 SET_HANDLED (fde, 0);
2530 #else /* TARGET_USE_CFIPOP */
2532 /* Emit an intelligible error message for missing support. */
2535 dot_cfi_dummy (int ignored ATTRIBUTE_UNUSED)
2537 as_bad (_("CFI is not supported for this target"));
2538 ignore_rest_of_line ();
2541 const pseudo_typeS cfi_pseudo_table[] =
2543 { "cfi_sections", dot_cfi_dummy, 0 },
2544 { "cfi_startproc", dot_cfi_dummy, 0 },
2545 { "cfi_endproc", dot_cfi_dummy, 0 },
2546 { "cfi_fde_data", dot_cfi_dummy, 0 },
2547 { "cfi_def_cfa", dot_cfi_dummy, 0 },
2548 { "cfi_def_cfa_register", dot_cfi_dummy, 0 },
2549 { "cfi_def_cfa_offset", dot_cfi_dummy, 0 },
2550 { "cfi_adjust_cfa_offset", dot_cfi_dummy, 0 },
2551 { "cfi_offset", dot_cfi_dummy, 0 },
2552 { "cfi_rel_offset", dot_cfi_dummy, 0 },
2553 { "cfi_register", dot_cfi_dummy, 0 },
2554 { "cfi_return_column", dot_cfi_dummy, 0 },
2555 { "cfi_restore", dot_cfi_dummy, 0 },
2556 { "cfi_undefined", dot_cfi_dummy, 0 },
2557 { "cfi_same_value", dot_cfi_dummy, 0 },
2558 { "cfi_remember_state", dot_cfi_dummy, 0 },
2559 { "cfi_restore_state", dot_cfi_dummy, 0 },
2560 { "cfi_window_save", dot_cfi_dummy, 0 },
2561 { "cfi_escape", dot_cfi_dummy, 0 },
2562 { "cfi_signal_frame", dot_cfi_dummy, 0 },
2563 { "cfi_personality", dot_cfi_dummy, 0 },
2564 { "cfi_personality_id", dot_cfi_dummy, 0 },
2565 { "cfi_lsda", dot_cfi_dummy, 0 },
2566 { "cfi_val_encoded_addr", dot_cfi_dummy, 0 },
2567 { "cfi_label", dot_cfi_dummy, 0 },
2568 { "cfi_inline_lsda", dot_cfi_dummy, 0 },
2569 { "cfi_val_offset", dot_cfi_dummy, 0 },
2577 #endif /* TARGET_USE_CFIPOP */