1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
95 #include "cfglayout.h"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 #ifndef INCOMING_RETURN_ADDR_RTX
125 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
128 /* Map register numbers held in the call frame info that gcc has
129 collected using DWARF_FRAME_REGNUM to those that should be output in
130 .debug_frame and .eh_frame. */
131 #ifndef DWARF2_FRAME_REG_OUT
132 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
135 /* Save the result of dwarf2out_do_frame across PCH. */
136 static GTY(()) bool saved_do_cfi_asm = 0;
138 /* Decide whether we want to emit frame unwind information for the current
142 dwarf2out_do_frame (void)
144 /* We want to emit correct CFA location expressions or lists, so we
145 have to return true if we're going to output debug info, even if
146 we're not going to output frame or unwind info. */
147 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
150 if (saved_do_cfi_asm)
153 if (targetm.debug_unwind_info () == UI_DWARF2)
156 if ((flag_unwind_tables || flag_exceptions)
157 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
163 /* Decide whether to emit frame unwind via assembler directives. */
166 dwarf2out_do_cfi_asm (void)
170 #ifdef MIPS_DEBUGGING_INFO
173 if (saved_do_cfi_asm)
175 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
177 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
180 /* Make sure the personality encoding is one the assembler can support.
181 In particular, aligned addresses can't be handled. */
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
185 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
186 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
189 /* If we can't get the assembler to emit only .debug_frame, and we don't need
190 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
191 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
192 && !flag_unwind_tables && !flag_exceptions
193 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
196 saved_do_cfi_asm = true;
200 /* The size of the target's pointer type. */
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_str_section;
232 static GTY(()) section *debug_ranges_section;
233 static GTY(()) section *debug_frame_section;
235 /* Personality decl of current unit. Used only when assembler does not support
237 static GTY(()) rtx current_unit_personality;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
244 typedef struct dw_cfi_struct *dw_cfi_ref;
245 typedef struct dw_fde_struct *dw_fde_ref;
246 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
248 /* Call frames are described using a sequence of Call Frame
249 Information instructions. The register number, offset
250 and address fields are provided as possible operands;
251 their use is selected by the opcode field. */
253 enum dw_cfi_oprnd_type {
255 dw_cfi_oprnd_reg_num,
261 typedef union GTY(()) dw_cfi_oprnd_struct {
262 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
263 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
264 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
265 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
269 typedef struct GTY(()) dw_cfi_struct {
270 dw_cfi_ref dw_cfi_next;
271 enum dwarf_call_frame_info dw_cfi_opc;
272 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
279 /* This is how we define the location of the CFA. We use to handle it
280 as REG + OFFSET all the time, but now it can be more complex.
281 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
282 Instead of passing around REG and OFFSET, we pass a copy
283 of this structure. */
284 typedef struct cfa_loc {
285 HOST_WIDE_INT offset;
286 HOST_WIDE_INT base_offset;
288 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
289 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
292 /* All call frame descriptions (FDE's) in the GCC generated DWARF
293 refer to a single Common Information Entry (CIE), defined at
294 the beginning of the .debug_frame section. This use of a single
295 CIE obviates the need to keep track of multiple CIE's
296 in the DWARF generation routines below. */
298 typedef struct GTY(()) dw_fde_struct {
300 const char *dw_fde_begin;
301 const char *dw_fde_current_label;
302 const char *dw_fde_end;
303 const char *dw_fde_vms_end_prologue;
304 const char *dw_fde_vms_begin_epilogue;
305 const char *dw_fde_second_begin;
306 const char *dw_fde_second_end;
307 dw_cfi_ref dw_fde_cfi;
308 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
309 HOST_WIDE_INT stack_realignment;
310 unsigned funcdef_number;
311 /* Dynamic realign argument pointer register. */
312 unsigned int drap_reg;
313 /* Virtual dynamic realign argument pointer register. */
314 unsigned int vdrap_reg;
315 /* These 3 flags are copied from rtl_data in function.h. */
316 unsigned all_throwers_are_sibcalls : 1;
317 unsigned uses_eh_lsda : 1;
318 unsigned nothrow : 1;
319 /* Whether we did stack realign in this call frame. */
320 unsigned stack_realign : 1;
321 /* Whether dynamic realign argument pointer register has been saved. */
322 unsigned drap_reg_saved: 1;
323 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
324 unsigned in_std_section : 1;
325 /* True iff dw_fde_second_begin label is in text_section or
326 cold_text_section. */
327 unsigned second_in_std_section : 1;
331 /* Maximum size (in bytes) of an artificially generated label. */
332 #define MAX_ARTIFICIAL_LABEL_BYTES 30
334 /* The size of addresses as they appear in the Dwarf 2 data.
335 Some architectures use word addresses to refer to code locations,
336 but Dwarf 2 info always uses byte addresses. On such machines,
337 Dwarf 2 addresses need to be larger than the architecture's
339 #ifndef DWARF2_ADDR_SIZE
340 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
343 /* The size in bytes of a DWARF field indicating an offset or length
344 relative to a debug info section, specified to be 4 bytes in the
345 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
348 #ifndef DWARF_OFFSET_SIZE
349 #define DWARF_OFFSET_SIZE 4
352 /* The size in bytes of a DWARF 4 type signature. */
354 #ifndef DWARF_TYPE_SIGNATURE_SIZE
355 #define DWARF_TYPE_SIGNATURE_SIZE 8
358 /* According to the (draft) DWARF 3 specification, the initial length
359 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
360 bytes are 0xffffffff, followed by the length stored in the next 8
363 However, the SGI/MIPS ABI uses an initial length which is equal to
364 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
366 #ifndef DWARF_INITIAL_LENGTH_SIZE
367 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
370 /* Round SIZE up to the nearest BOUNDARY. */
371 #define DWARF_ROUND(SIZE,BOUNDARY) \
372 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
374 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
375 #ifndef DWARF_CIE_DATA_ALIGNMENT
376 #ifdef STACK_GROWS_DOWNWARD
377 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
379 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
383 /* CIE identifier. */
384 #if HOST_BITS_PER_WIDE_INT >= 64
385 #define DWARF_CIE_ID \
386 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
388 #define DWARF_CIE_ID DW_CIE_ID
391 /* A pointer to the base of a table that contains frame description
392 information for each routine. */
393 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
395 /* Number of elements currently allocated for fde_table. */
396 static GTY(()) unsigned fde_table_allocated;
398 /* Number of elements in fde_table currently in use. */
399 static GTY(()) unsigned fde_table_in_use;
401 /* Size (in elements) of increments by which we may expand the
403 #define FDE_TABLE_INCREMENT 256
405 /* Get the current fde_table entry we should use. */
407 static inline dw_fde_ref
410 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
413 /* A list of call frame insns for the CIE. */
414 static GTY(()) dw_cfi_ref cie_cfi_head;
416 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
417 attribute that accelerates the lookup of the FDE associated
418 with the subprogram. This variable holds the table index of the FDE
419 associated with the current function (body) definition. */
420 static unsigned current_funcdef_fde;
422 struct GTY(()) indirect_string_node {
424 unsigned int refcount;
425 enum dwarf_form form;
429 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
431 /* True if the compilation unit has location entries that reference
433 static GTY(()) bool debug_str_hash_forced = false;
435 static GTY(()) int dw2_string_counter;
436 static GTY(()) unsigned long dwarf2out_cfi_label_num;
438 /* True if the compilation unit places functions in more than one section. */
439 static GTY(()) bool have_multiple_function_sections = false;
441 /* Whether the default text and cold text sections have been used at all. */
443 static GTY(()) bool text_section_used = false;
444 static GTY(()) bool cold_text_section_used = false;
446 /* The default cold text section. */
447 static GTY(()) section *cold_text_section;
449 /* Forward declarations for functions defined in this file. */
451 static char *stripattributes (const char *);
452 static const char *dwarf_cfi_name (unsigned);
453 static dw_cfi_ref new_cfi (void);
454 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
455 static void add_fde_cfi (const char *, dw_cfi_ref);
456 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
457 static void lookup_cfa (dw_cfa_location *);
458 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
459 static void initial_return_save (rtx);
460 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
462 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
463 static void output_cfi_directive (dw_cfi_ref);
464 static void output_call_frame_info (int);
465 static void dwarf2out_note_section_used (void);
466 static bool clobbers_queued_reg_save (const_rtx);
467 static void dwarf2out_frame_debug_expr (rtx, const char *);
469 /* Support for complex CFA locations. */
470 static void output_cfa_loc (dw_cfi_ref, int);
471 static void output_cfa_loc_raw (dw_cfi_ref);
472 static void get_cfa_from_loc_descr (dw_cfa_location *,
473 struct dw_loc_descr_struct *);
474 static struct dw_loc_descr_struct *build_cfa_loc
475 (dw_cfa_location *, HOST_WIDE_INT);
476 static struct dw_loc_descr_struct *build_cfa_aligned_loc
477 (HOST_WIDE_INT, HOST_WIDE_INT);
478 static void def_cfa_1 (const char *, dw_cfa_location *);
479 static struct dw_loc_descr_struct *mem_loc_descriptor
480 (rtx, enum machine_mode mode, enum var_init_status);
482 /* How to start an assembler comment. */
483 #ifndef ASM_COMMENT_START
484 #define ASM_COMMENT_START ";#"
487 /* Data and reference forms for relocatable data. */
488 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
489 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
491 #ifndef DEBUG_FRAME_SECTION
492 #define DEBUG_FRAME_SECTION ".debug_frame"
495 #ifndef FUNC_BEGIN_LABEL
496 #define FUNC_BEGIN_LABEL "LFB"
499 #ifndef FUNC_END_LABEL
500 #define FUNC_END_LABEL "LFE"
503 #ifndef PROLOGUE_END_LABEL
504 #define PROLOGUE_END_LABEL "LPE"
507 #ifndef EPILOGUE_BEGIN_LABEL
508 #define EPILOGUE_BEGIN_LABEL "LEB"
511 #ifndef FRAME_BEGIN_LABEL
512 #define FRAME_BEGIN_LABEL "Lframe"
514 #define CIE_AFTER_SIZE_LABEL "LSCIE"
515 #define CIE_END_LABEL "LECIE"
516 #define FDE_LABEL "LSFDE"
517 #define FDE_AFTER_SIZE_LABEL "LASFDE"
518 #define FDE_END_LABEL "LEFDE"
519 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
520 #define LINE_NUMBER_END_LABEL "LELT"
521 #define LN_PROLOG_AS_LABEL "LASLTP"
522 #define LN_PROLOG_END_LABEL "LELTP"
523 #define DIE_LABEL_PREFIX "DW"
525 /* The DWARF 2 CFA column which tracks the return address. Normally this
526 is the column for PC, or the first column after all of the hard
528 #ifndef DWARF_FRAME_RETURN_COLUMN
530 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
532 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
536 /* The mapping from gcc register number to DWARF 2 CFA column number. By
537 default, we just provide columns for all registers. */
538 #ifndef DWARF_FRAME_REGNUM
539 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
542 /* Match the base name of a file to the base name of a compilation unit. */
545 matches_main_base (const char *path)
547 /* Cache the last query. */
548 static const char *last_path = NULL;
549 static int last_match = 0;
550 if (path != last_path)
553 int length = base_of_path (path, &base);
555 last_match = (length == main_input_baselength
556 && memcmp (base, main_input_basename, length) == 0);
561 #ifdef DEBUG_DEBUG_STRUCT
564 dump_struct_debug (tree type, enum debug_info_usage usage,
565 enum debug_struct_file criterion, int generic,
566 int matches, int result)
568 /* Find the type name. */
569 tree type_decl = TYPE_STUB_DECL (type);
571 const char *name = 0;
572 if (TREE_CODE (t) == TYPE_DECL)
575 name = IDENTIFIER_POINTER (t);
577 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
579 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
580 matches ? "bas" : "hdr",
581 generic ? "gen" : "ord",
582 usage == DINFO_USAGE_DFN ? ";" :
583 usage == DINFO_USAGE_DIR_USE ? "." : "*",
585 (void*) type_decl, name);
588 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
589 dump_struct_debug (type, usage, criterion, generic, matches, result)
593 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
599 should_emit_struct_debug (tree type, enum debug_info_usage usage)
601 enum debug_struct_file criterion;
603 bool generic = lang_hooks.types.generic_p (type);
606 criterion = debug_struct_generic[usage];
608 criterion = debug_struct_ordinary[usage];
610 if (criterion == DINFO_STRUCT_FILE_NONE)
611 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
612 if (criterion == DINFO_STRUCT_FILE_ANY)
613 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
615 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
617 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
618 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
620 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
621 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
622 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
625 /* Hook used by __throw. */
628 expand_builtin_dwarf_sp_column (void)
630 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
631 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
634 /* Return a pointer to a copy of the section string name S with all
635 attributes stripped off, and an asterisk prepended (for assemble_name). */
638 stripattributes (const char *s)
640 char *stripped = XNEWVEC (char, strlen (s) + 2);
645 while (*s && *s != ',')
652 /* MEM is a memory reference for the register size table, each element of
653 which has mode MODE. Initialize column C as a return address column. */
656 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
658 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
659 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
660 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
663 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
665 static inline HOST_WIDE_INT
666 div_data_align (HOST_WIDE_INT off)
668 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
669 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
673 /* Return true if we need a signed version of a given opcode
674 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
677 need_data_align_sf_opcode (HOST_WIDE_INT off)
679 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
682 /* Generate code to initialize the register size table. */
685 expand_builtin_init_dwarf_reg_sizes (tree address)
688 enum machine_mode mode = TYPE_MODE (char_type_node);
689 rtx addr = expand_normal (address);
690 rtx mem = gen_rtx_MEM (BLKmode, addr);
691 bool wrote_return_column = false;
693 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
695 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
697 if (rnum < DWARF_FRAME_REGISTERS)
699 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
700 enum machine_mode save_mode = reg_raw_mode[i];
703 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
704 save_mode = choose_hard_reg_mode (i, 1, true);
705 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
707 if (save_mode == VOIDmode)
709 wrote_return_column = true;
711 size = GET_MODE_SIZE (save_mode);
715 emit_move_insn (adjust_address (mem, mode, offset),
716 gen_int_mode (size, mode));
720 if (!wrote_return_column)
721 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
723 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
724 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
727 targetm.init_dwarf_reg_sizes_extra (address);
730 /* Convert a DWARF call frame info. operation to its string name */
733 dwarf_cfi_name (unsigned int cfi_opc)
737 case DW_CFA_advance_loc:
738 return "DW_CFA_advance_loc";
740 return "DW_CFA_offset";
742 return "DW_CFA_restore";
746 return "DW_CFA_set_loc";
747 case DW_CFA_advance_loc1:
748 return "DW_CFA_advance_loc1";
749 case DW_CFA_advance_loc2:
750 return "DW_CFA_advance_loc2";
751 case DW_CFA_advance_loc4:
752 return "DW_CFA_advance_loc4";
753 case DW_CFA_offset_extended:
754 return "DW_CFA_offset_extended";
755 case DW_CFA_restore_extended:
756 return "DW_CFA_restore_extended";
757 case DW_CFA_undefined:
758 return "DW_CFA_undefined";
759 case DW_CFA_same_value:
760 return "DW_CFA_same_value";
761 case DW_CFA_register:
762 return "DW_CFA_register";
763 case DW_CFA_remember_state:
764 return "DW_CFA_remember_state";
765 case DW_CFA_restore_state:
766 return "DW_CFA_restore_state";
768 return "DW_CFA_def_cfa";
769 case DW_CFA_def_cfa_register:
770 return "DW_CFA_def_cfa_register";
771 case DW_CFA_def_cfa_offset:
772 return "DW_CFA_def_cfa_offset";
775 case DW_CFA_def_cfa_expression:
776 return "DW_CFA_def_cfa_expression";
777 case DW_CFA_expression:
778 return "DW_CFA_expression";
779 case DW_CFA_offset_extended_sf:
780 return "DW_CFA_offset_extended_sf";
781 case DW_CFA_def_cfa_sf:
782 return "DW_CFA_def_cfa_sf";
783 case DW_CFA_def_cfa_offset_sf:
784 return "DW_CFA_def_cfa_offset_sf";
786 /* SGI/MIPS specific */
787 case DW_CFA_MIPS_advance_loc8:
788 return "DW_CFA_MIPS_advance_loc8";
791 case DW_CFA_GNU_window_save:
792 return "DW_CFA_GNU_window_save";
793 case DW_CFA_GNU_args_size:
794 return "DW_CFA_GNU_args_size";
795 case DW_CFA_GNU_negative_offset_extended:
796 return "DW_CFA_GNU_negative_offset_extended";
799 return "DW_CFA_<unknown>";
803 /* Return a pointer to a newly allocated Call Frame Instruction. */
805 static inline dw_cfi_ref
808 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
810 cfi->dw_cfi_next = NULL;
811 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
812 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
817 /* Add a Call Frame Instruction to list of instructions. */
820 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
823 dw_fde_ref fde = current_fde ();
825 /* When DRAP is used, CFA is defined with an expression. Redefine
826 CFA may lead to a different CFA value. */
827 /* ??? Of course, this heuristic fails when we're annotating epilogues,
828 because of course we'll always want to redefine the CFA back to the
829 stack pointer on the way out. Where should we move this check? */
830 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
831 switch (cfi->dw_cfi_opc)
833 case DW_CFA_def_cfa_register:
834 case DW_CFA_def_cfa_offset:
835 case DW_CFA_def_cfa_offset_sf:
837 case DW_CFA_def_cfa_sf:
844 /* Find the end of the chain. */
845 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
851 /* Generate a new label for the CFI info to refer to. FORCE is true
852 if a label needs to be output even when using .cfi_* directives. */
855 dwarf2out_cfi_label (bool force)
857 static char label[20];
859 if (!force && dwarf2out_do_cfi_asm ())
861 /* In this case, we will be emitting the asm directive instead of
862 the label, so just return a placeholder to keep the rest of the
864 strcpy (label, "<do not output>");
868 int num = dwarf2out_cfi_label_num++;
869 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
870 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
876 /* True if remember_state should be emitted before following CFI directive. */
877 static bool emit_cfa_remember;
879 /* True if any CFI directives were emitted at the current insn. */
880 static bool any_cfis_emitted;
882 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
883 or to the CIE if LABEL is NULL. */
886 add_fde_cfi (const char *label, dw_cfi_ref cfi)
888 dw_cfi_ref *list_head;
890 if (emit_cfa_remember)
892 dw_cfi_ref cfi_remember;
894 /* Emit the state save. */
895 emit_cfa_remember = false;
896 cfi_remember = new_cfi ();
897 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
898 add_fde_cfi (label, cfi_remember);
901 list_head = &cie_cfi_head;
903 if (dwarf2out_do_cfi_asm ())
907 dw_fde_ref fde = current_fde ();
909 gcc_assert (fde != NULL);
911 /* We still have to add the cfi to the list so that lookup_cfa
912 works later on. When -g2 and above we even need to force
913 emitting of CFI labels and add to list a DW_CFA_set_loc for
914 convert_cfa_to_fb_loc_list purposes. If we're generating
915 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
916 convert_cfa_to_fb_loc_list. */
917 if (dwarf_version == 2
918 && debug_info_level > DINFO_LEVEL_TERSE
919 && (write_symbols == DWARF2_DEBUG
920 || write_symbols == VMS_AND_DWARF2_DEBUG))
922 switch (cfi->dw_cfi_opc)
924 case DW_CFA_def_cfa_offset:
925 case DW_CFA_def_cfa_offset_sf:
926 case DW_CFA_def_cfa_register:
928 case DW_CFA_def_cfa_sf:
929 case DW_CFA_def_cfa_expression:
930 case DW_CFA_restore_state:
931 if (*label == 0 || strcmp (label, "<do not output>") == 0)
932 label = dwarf2out_cfi_label (true);
934 if (fde->dw_fde_current_label == NULL
935 || strcmp (label, fde->dw_fde_current_label) != 0)
939 label = xstrdup (label);
941 /* Set the location counter to the new label. */
943 /* It doesn't metter whether DW_CFA_set_loc
944 or DW_CFA_advance_loc4 is added here, those aren't
945 emitted into assembly, only looked up by
946 convert_cfa_to_fb_loc_list. */
947 xcfi->dw_cfi_opc = DW_CFA_set_loc;
948 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
949 add_cfi (&fde->dw_fde_cfi, xcfi);
950 fde->dw_fde_current_label = label;
958 output_cfi_directive (cfi);
960 list_head = &fde->dw_fde_cfi;
961 any_cfis_emitted = true;
963 /* ??? If this is a CFI for the CIE, we don't emit. This
964 assumes that the standard CIE contents that the assembler
965 uses matches the standard CIE contents that the compiler
966 uses. This is probably a bad assumption. I'm not quite
967 sure how to address this for now. */
971 dw_fde_ref fde = current_fde ();
973 gcc_assert (fde != NULL);
976 label = dwarf2out_cfi_label (false);
978 if (fde->dw_fde_current_label == NULL
979 || strcmp (label, fde->dw_fde_current_label) != 0)
983 label = xstrdup (label);
985 /* Set the location counter to the new label. */
987 /* If we have a current label, advance from there, otherwise
988 set the location directly using set_loc. */
989 xcfi->dw_cfi_opc = fde->dw_fde_current_label
990 ? DW_CFA_advance_loc4
992 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
993 add_cfi (&fde->dw_fde_cfi, xcfi);
995 fde->dw_fde_current_label = label;
998 list_head = &fde->dw_fde_cfi;
999 any_cfis_emitted = true;
1002 add_cfi (list_head, cfi);
1005 /* Subroutine of lookup_cfa. */
1008 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1010 switch (cfi->dw_cfi_opc)
1012 case DW_CFA_def_cfa_offset:
1013 case DW_CFA_def_cfa_offset_sf:
1014 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1016 case DW_CFA_def_cfa_register:
1017 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1019 case DW_CFA_def_cfa:
1020 case DW_CFA_def_cfa_sf:
1021 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1022 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1024 case DW_CFA_def_cfa_expression:
1025 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1028 case DW_CFA_remember_state:
1029 gcc_assert (!remember->in_use);
1031 remember->in_use = 1;
1033 case DW_CFA_restore_state:
1034 gcc_assert (remember->in_use);
1036 remember->in_use = 0;
1044 /* Find the previous value for the CFA. */
1047 lookup_cfa (dw_cfa_location *loc)
1051 dw_cfa_location remember;
1053 memset (loc, 0, sizeof (*loc));
1054 loc->reg = INVALID_REGNUM;
1057 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1058 lookup_cfa_1 (cfi, loc, &remember);
1060 fde = current_fde ();
1062 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1063 lookup_cfa_1 (cfi, loc, &remember);
1066 /* The current rule for calculating the DWARF2 canonical frame address. */
1067 static dw_cfa_location cfa;
1069 /* The register used for saving registers to the stack, and its offset
1071 static dw_cfa_location cfa_store;
1073 /* The current save location around an epilogue. */
1074 static dw_cfa_location cfa_remember;
1076 /* The running total of the size of arguments pushed onto the stack. */
1077 static HOST_WIDE_INT args_size;
1079 /* The last args_size we actually output. */
1080 static HOST_WIDE_INT old_args_size;
1082 /* Entry point to update the canonical frame address (CFA).
1083 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1084 calculated from REG+OFFSET. */
1087 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1089 dw_cfa_location loc;
1091 loc.base_offset = 0;
1093 loc.offset = offset;
1094 def_cfa_1 (label, &loc);
1097 /* Determine if two dw_cfa_location structures define the same data. */
1100 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1102 return (loc1->reg == loc2->reg
1103 && loc1->offset == loc2->offset
1104 && loc1->indirect == loc2->indirect
1105 && (loc1->indirect == 0
1106 || loc1->base_offset == loc2->base_offset));
1109 /* This routine does the actual work. The CFA is now calculated from
1110 the dw_cfa_location structure. */
1113 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1116 dw_cfa_location old_cfa, loc;
1121 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1122 cfa_store.offset = loc.offset;
1124 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1125 lookup_cfa (&old_cfa);
1127 /* If nothing changed, no need to issue any call frame instructions. */
1128 if (cfa_equal_p (&loc, &old_cfa))
1133 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1135 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1136 the CFA register did not change but the offset did. The data
1137 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1138 in the assembler via the .cfi_def_cfa_offset directive. */
1140 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1142 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1143 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1146 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1147 else if (loc.offset == old_cfa.offset
1148 && old_cfa.reg != INVALID_REGNUM
1150 && !old_cfa.indirect)
1152 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1153 indicating the CFA register has changed to <register> but the
1154 offset has not changed. */
1155 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1156 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1160 else if (loc.indirect == 0)
1162 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1163 indicating the CFA register has changed to <register> with
1164 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1165 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1168 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1170 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1171 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1172 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1176 /* Construct a DW_CFA_def_cfa_expression instruction to
1177 calculate the CFA using a full location expression since no
1178 register-offset pair is available. */
1179 struct dw_loc_descr_struct *loc_list;
1181 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1182 loc_list = build_cfa_loc (&loc, 0);
1183 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1186 add_fde_cfi (label, cfi);
1189 /* Add the CFI for saving a register. REG is the CFA column number.
1190 LABEL is passed to add_fde_cfi.
1191 If SREG is -1, the register is saved at OFFSET from the CFA;
1192 otherwise it is saved in SREG. */
1195 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1197 dw_cfi_ref cfi = new_cfi ();
1198 dw_fde_ref fde = current_fde ();
1200 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1202 /* When stack is aligned, store REG using DW_CFA_expression with
1205 && fde->stack_realign
1206 && sreg == INVALID_REGNUM)
1208 cfi->dw_cfi_opc = DW_CFA_expression;
1209 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1210 cfi->dw_cfi_oprnd2.dw_cfi_loc
1211 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1213 else if (sreg == INVALID_REGNUM)
1215 if (need_data_align_sf_opcode (offset))
1216 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1217 else if (reg & ~0x3f)
1218 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1220 cfi->dw_cfi_opc = DW_CFA_offset;
1221 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1223 else if (sreg == reg)
1224 cfi->dw_cfi_opc = DW_CFA_same_value;
1227 cfi->dw_cfi_opc = DW_CFA_register;
1228 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1231 add_fde_cfi (label, cfi);
1234 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1235 This CFI tells the unwinder that it needs to restore the window registers
1236 from the previous frame's window save area.
1238 ??? Perhaps we should note in the CIE where windows are saved (instead of
1239 assuming 0(cfa)) and what registers are in the window. */
1242 dwarf2out_window_save (const char *label)
1244 dw_cfi_ref cfi = new_cfi ();
1246 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1247 add_fde_cfi (label, cfi);
1250 /* Entry point for saving a register to the stack. REG is the GCC register
1251 number. LABEL and OFFSET are passed to reg_save. */
1254 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1256 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1259 /* Entry point for saving the return address in the stack.
1260 LABEL and OFFSET are passed to reg_save. */
1263 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1265 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1268 /* Entry point for saving the return address in a register.
1269 LABEL and SREG are passed to reg_save. */
1272 dwarf2out_return_reg (const char *label, unsigned int sreg)
1274 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1277 /* Record the initial position of the return address. RTL is
1278 INCOMING_RETURN_ADDR_RTX. */
1281 initial_return_save (rtx rtl)
1283 unsigned int reg = INVALID_REGNUM;
1284 HOST_WIDE_INT offset = 0;
1286 switch (GET_CODE (rtl))
1289 /* RA is in a register. */
1290 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1294 /* RA is on the stack. */
1295 rtl = XEXP (rtl, 0);
1296 switch (GET_CODE (rtl))
1299 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1304 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1305 offset = INTVAL (XEXP (rtl, 1));
1309 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1310 offset = -INTVAL (XEXP (rtl, 1));
1320 /* The return address is at some offset from any value we can
1321 actually load. For instance, on the SPARC it is in %i7+8. Just
1322 ignore the offset for now; it doesn't matter for unwinding frames. */
1323 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1324 initial_return_save (XEXP (rtl, 0));
1331 if (reg != DWARF_FRAME_RETURN_COLUMN)
1332 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1335 /* Given a SET, calculate the amount of stack adjustment it
1338 static HOST_WIDE_INT
1339 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1340 HOST_WIDE_INT cur_offset)
1342 const_rtx src = SET_SRC (pattern);
1343 const_rtx dest = SET_DEST (pattern);
1344 HOST_WIDE_INT offset = 0;
1347 if (dest == stack_pointer_rtx)
1349 code = GET_CODE (src);
1351 /* Assume (set (reg sp) (reg whatever)) sets args_size
1353 if (code == REG && src != stack_pointer_rtx)
1355 offset = -cur_args_size;
1356 #ifndef STACK_GROWS_DOWNWARD
1359 return offset - cur_offset;
1362 if (! (code == PLUS || code == MINUS)
1363 || XEXP (src, 0) != stack_pointer_rtx
1364 || !CONST_INT_P (XEXP (src, 1)))
1367 /* (set (reg sp) (plus (reg sp) (const_int))) */
1368 offset = INTVAL (XEXP (src, 1));
1374 if (MEM_P (src) && !MEM_P (dest))
1378 /* (set (mem (pre_dec (reg sp))) (foo)) */
1379 src = XEXP (dest, 0);
1380 code = GET_CODE (src);
1386 if (XEXP (src, 0) == stack_pointer_rtx)
1388 rtx val = XEXP (XEXP (src, 1), 1);
1389 /* We handle only adjustments by constant amount. */
1390 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1391 && CONST_INT_P (val));
1392 offset = -INTVAL (val);
1399 if (XEXP (src, 0) == stack_pointer_rtx)
1401 offset = GET_MODE_SIZE (GET_MODE (dest));
1408 if (XEXP (src, 0) == stack_pointer_rtx)
1410 offset = -GET_MODE_SIZE (GET_MODE (dest));
1425 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1426 indexed by INSN_UID. */
1428 static HOST_WIDE_INT *barrier_args_size;
1430 /* Helper function for compute_barrier_args_size. Handle one insn. */
1432 static HOST_WIDE_INT
1433 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1434 VEC (rtx, heap) **next)
1436 HOST_WIDE_INT offset = 0;
1439 if (! RTX_FRAME_RELATED_P (insn))
1441 if (prologue_epilogue_contains (insn))
1443 else if (GET_CODE (PATTERN (insn)) == SET)
1444 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1445 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1446 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1448 /* There may be stack adjustments inside compound insns. Search
1450 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1451 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1452 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1453 cur_args_size, offset);
1458 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1462 expr = XEXP (expr, 0);
1463 if (GET_CODE (expr) == PARALLEL
1464 || GET_CODE (expr) == SEQUENCE)
1465 for (i = 1; i < XVECLEN (expr, 0); i++)
1467 rtx elem = XVECEXP (expr, 0, i);
1469 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1470 offset += stack_adjust_offset (elem, cur_args_size, offset);
1475 #ifndef STACK_GROWS_DOWNWARD
1479 cur_args_size += offset;
1480 if (cur_args_size < 0)
1485 rtx dest = JUMP_LABEL (insn);
1489 if (barrier_args_size [INSN_UID (dest)] < 0)
1491 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1492 VEC_safe_push (rtx, heap, *next, dest);
1497 return cur_args_size;
1500 /* Walk the whole function and compute args_size on BARRIERs. */
1503 compute_barrier_args_size (void)
1505 int max_uid = get_max_uid (), i;
1507 VEC (rtx, heap) *worklist, *next, *tmp;
1509 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1510 for (i = 0; i < max_uid; i++)
1511 barrier_args_size[i] = -1;
1513 worklist = VEC_alloc (rtx, heap, 20);
1514 next = VEC_alloc (rtx, heap, 20);
1515 insn = get_insns ();
1516 barrier_args_size[INSN_UID (insn)] = 0;
1517 VEC_quick_push (rtx, worklist, insn);
1520 while (!VEC_empty (rtx, worklist))
1522 rtx prev, body, first_insn;
1523 HOST_WIDE_INT cur_args_size;
1525 first_insn = insn = VEC_pop (rtx, worklist);
1526 cur_args_size = barrier_args_size[INSN_UID (insn)];
1527 prev = prev_nonnote_insn (insn);
1528 if (prev && BARRIER_P (prev))
1529 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1531 for (; insn; insn = NEXT_INSN (insn))
1533 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1535 if (BARRIER_P (insn))
1540 if (insn == first_insn)
1542 else if (barrier_args_size[INSN_UID (insn)] < 0)
1544 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1549 /* The insns starting with this label have been
1550 already scanned or are in the worklist. */
1555 body = PATTERN (insn);
1556 if (GET_CODE (body) == SEQUENCE)
1558 HOST_WIDE_INT dest_args_size = cur_args_size;
1559 for (i = 1; i < XVECLEN (body, 0); i++)
1560 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1561 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1563 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1564 dest_args_size, &next);
1567 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1568 cur_args_size, &next);
1570 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1571 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1572 dest_args_size, &next);
1575 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1576 cur_args_size, &next);
1580 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1584 if (VEC_empty (rtx, next))
1587 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1591 VEC_truncate (rtx, next, 0);
1594 VEC_free (rtx, heap, worklist);
1595 VEC_free (rtx, heap, next);
1598 /* Add a CFI to update the running total of the size of arguments
1599 pushed onto the stack. */
1602 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1606 if (size == old_args_size)
1609 old_args_size = size;
1612 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1613 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1614 add_fde_cfi (label, cfi);
1617 /* Record a stack adjustment of OFFSET bytes. */
1620 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1622 if (cfa.reg == STACK_POINTER_REGNUM)
1623 cfa.offset += offset;
1625 if (cfa_store.reg == STACK_POINTER_REGNUM)
1626 cfa_store.offset += offset;
1628 if (ACCUMULATE_OUTGOING_ARGS)
1631 #ifndef STACK_GROWS_DOWNWARD
1635 args_size += offset;
1639 def_cfa_1 (label, &cfa);
1640 if (flag_asynchronous_unwind_tables)
1641 dwarf2out_args_size (label, args_size);
1644 /* Check INSN to see if it looks like a push or a stack adjustment, and
1645 make a note of it if it does. EH uses this information to find out
1646 how much extra space it needs to pop off the stack. */
1649 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1651 HOST_WIDE_INT offset;
1655 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1656 with this function. Proper support would require all frame-related
1657 insns to be marked, and to be able to handle saving state around
1658 epilogues textually in the middle of the function. */
1659 if (prologue_epilogue_contains (insn))
1662 /* If INSN is an instruction from target of an annulled branch, the
1663 effects are for the target only and so current argument size
1664 shouldn't change at all. */
1666 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1667 && INSN_FROM_TARGET_P (insn))
1670 /* If only calls can throw, and we have a frame pointer,
1671 save up adjustments until we see the CALL_INSN. */
1672 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1674 if (CALL_P (insn) && !after_p)
1676 /* Extract the size of the args from the CALL rtx itself. */
1677 insn = PATTERN (insn);
1678 if (GET_CODE (insn) == PARALLEL)
1679 insn = XVECEXP (insn, 0, 0);
1680 if (GET_CODE (insn) == SET)
1681 insn = SET_SRC (insn);
1682 gcc_assert (GET_CODE (insn) == CALL);
1683 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1688 if (CALL_P (insn) && !after_p)
1690 if (!flag_asynchronous_unwind_tables)
1691 dwarf2out_args_size ("", args_size);
1694 else if (BARRIER_P (insn))
1696 /* Don't call compute_barrier_args_size () if the only
1697 BARRIER is at the end of function. */
1698 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1699 compute_barrier_args_size ();
1700 if (barrier_args_size == NULL)
1704 offset = barrier_args_size[INSN_UID (insn)];
1709 offset -= args_size;
1710 #ifndef STACK_GROWS_DOWNWARD
1714 else if (GET_CODE (PATTERN (insn)) == SET)
1715 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1716 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1717 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1719 /* There may be stack adjustments inside compound insns. Search
1721 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1722 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1723 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1732 label = dwarf2out_cfi_label (false);
1733 dwarf2out_stack_adjust (offset, label);
1736 /* We delay emitting a register save until either (a) we reach the end
1737 of the prologue or (b) the register is clobbered. This clusters
1738 register saves so that there are fewer pc advances. */
1740 struct GTY(()) queued_reg_save {
1741 struct queued_reg_save *next;
1743 HOST_WIDE_INT cfa_offset;
1747 static GTY(()) struct queued_reg_save *queued_reg_saves;
1749 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1750 struct GTY(()) reg_saved_in_data {
1755 /* A list of registers saved in other registers.
1756 The list intentionally has a small maximum capacity of 4; if your
1757 port needs more than that, you might consider implementing a
1758 more efficient data structure. */
1759 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1760 static GTY(()) size_t num_regs_saved_in_regs;
1762 static const char *last_reg_save_label;
1764 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1765 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1768 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1770 struct queued_reg_save *q;
1772 /* Duplicates waste space, but it's also necessary to remove them
1773 for correctness, since the queue gets output in reverse
1775 for (q = queued_reg_saves; q != NULL; q = q->next)
1776 if (REGNO (q->reg) == REGNO (reg))
1781 q = ggc_alloc_queued_reg_save ();
1782 q->next = queued_reg_saves;
1783 queued_reg_saves = q;
1787 q->cfa_offset = offset;
1788 q->saved_reg = sreg;
1790 last_reg_save_label = label;
1793 /* Output all the entries in QUEUED_REG_SAVES. */
1796 dwarf2out_flush_queued_reg_saves (void)
1798 struct queued_reg_save *q;
1800 for (q = queued_reg_saves; q; q = q->next)
1803 unsigned int reg, sreg;
1805 for (i = 0; i < num_regs_saved_in_regs; i++)
1806 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1808 if (q->saved_reg && i == num_regs_saved_in_regs)
1810 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1811 num_regs_saved_in_regs++;
1813 if (i != num_regs_saved_in_regs)
1815 regs_saved_in_regs[i].orig_reg = q->reg;
1816 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1819 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1821 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1823 sreg = INVALID_REGNUM;
1824 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1827 queued_reg_saves = NULL;
1828 last_reg_save_label = NULL;
1831 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1832 location for? Or, does it clobber a register which we've previously
1833 said that some other register is saved in, and for which we now
1834 have a new location for? */
1837 clobbers_queued_reg_save (const_rtx insn)
1839 struct queued_reg_save *q;
1841 for (q = queued_reg_saves; q; q = q->next)
1844 if (modified_in_p (q->reg, insn))
1846 for (i = 0; i < num_regs_saved_in_regs; i++)
1847 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1848 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1855 /* Entry point for saving the first register into the second. */
1858 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1861 unsigned int regno, sregno;
1863 for (i = 0; i < num_regs_saved_in_regs; i++)
1864 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1866 if (i == num_regs_saved_in_regs)
1868 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1869 num_regs_saved_in_regs++;
1871 regs_saved_in_regs[i].orig_reg = reg;
1872 regs_saved_in_regs[i].saved_in_reg = sreg;
1874 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1875 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1876 reg_save (label, regno, sregno, 0);
1879 /* What register, if any, is currently saved in REG? */
1882 reg_saved_in (rtx reg)
1884 unsigned int regn = REGNO (reg);
1886 struct queued_reg_save *q;
1888 for (q = queued_reg_saves; q; q = q->next)
1889 if (q->saved_reg && regn == REGNO (q->saved_reg))
1892 for (i = 0; i < num_regs_saved_in_regs; i++)
1893 if (regs_saved_in_regs[i].saved_in_reg
1894 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1895 return regs_saved_in_regs[i].orig_reg;
1901 /* A temporary register holding an integral value used in adjusting SP
1902 or setting up the store_reg. The "offset" field holds the integer
1903 value, not an offset. */
1904 static dw_cfa_location cfa_temp;
1906 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1909 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1911 memset (&cfa, 0, sizeof (cfa));
1913 switch (GET_CODE (pat))
1916 cfa.reg = REGNO (XEXP (pat, 0));
1917 cfa.offset = INTVAL (XEXP (pat, 1));
1921 cfa.reg = REGNO (pat);
1926 pat = XEXP (pat, 0);
1927 if (GET_CODE (pat) == PLUS)
1929 cfa.base_offset = INTVAL (XEXP (pat, 1));
1930 pat = XEXP (pat, 0);
1932 cfa.reg = REGNO (pat);
1936 /* Recurse and define an expression. */
1940 def_cfa_1 (label, &cfa);
1943 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1946 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1950 gcc_assert (GET_CODE (pat) == SET);
1951 dest = XEXP (pat, 0);
1952 src = XEXP (pat, 1);
1954 switch (GET_CODE (src))
1957 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1958 cfa.offset -= INTVAL (XEXP (src, 1));
1968 cfa.reg = REGNO (dest);
1969 gcc_assert (cfa.indirect == 0);
1971 def_cfa_1 (label, &cfa);
1974 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1977 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1979 HOST_WIDE_INT offset;
1980 rtx src, addr, span;
1982 src = XEXP (set, 1);
1983 addr = XEXP (set, 0);
1984 gcc_assert (MEM_P (addr));
1985 addr = XEXP (addr, 0);
1987 /* As documented, only consider extremely simple addresses. */
1988 switch (GET_CODE (addr))
1991 gcc_assert (REGNO (addr) == cfa.reg);
1992 offset = -cfa.offset;
1995 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1996 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2002 span = targetm.dwarf_register_span (src);
2004 /* ??? We'd like to use queue_reg_save, but we need to come up with
2005 a different flushing heuristic for epilogues. */
2007 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2010 /* We have a PARALLEL describing where the contents of SRC live.
2011 Queue register saves for each piece of the PARALLEL. */
2014 HOST_WIDE_INT span_offset = offset;
2016 gcc_assert (GET_CODE (span) == PARALLEL);
2018 limit = XVECLEN (span, 0);
2019 for (par_index = 0; par_index < limit; par_index++)
2021 rtx elem = XVECEXP (span, 0, par_index);
2023 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2024 INVALID_REGNUM, span_offset);
2025 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2030 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2033 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2036 unsigned sregno, dregno;
2038 src = XEXP (set, 1);
2039 dest = XEXP (set, 0);
2042 sregno = DWARF_FRAME_RETURN_COLUMN;
2044 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2046 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2048 /* ??? We'd like to use queue_reg_save, but we need to come up with
2049 a different flushing heuristic for epilogues. */
2050 reg_save (label, sregno, dregno, 0);
2053 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2056 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2058 rtx src, dest, span;
2059 dw_cfi_ref cfi = new_cfi ();
2061 dest = SET_DEST (set);
2062 src = SET_SRC (set);
2064 gcc_assert (REG_P (src));
2065 gcc_assert (MEM_P (dest));
2067 span = targetm.dwarf_register_span (src);
2070 cfi->dw_cfi_opc = DW_CFA_expression;
2071 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2072 cfi->dw_cfi_oprnd2.dw_cfi_loc
2073 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2074 VAR_INIT_STATUS_INITIALIZED);
2076 /* ??? We'd like to use queue_reg_save, were the interface different,
2077 and, as above, we could manage flushing for epilogues. */
2078 add_fde_cfi (label, cfi);
2081 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2084 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2086 dw_cfi_ref cfi = new_cfi ();
2087 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2089 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2090 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2092 add_fde_cfi (label, cfi);
2095 /* Record call frame debugging information for an expression EXPR,
2096 which either sets SP or FP (adjusting how we calculate the frame
2097 address) or saves a register to the stack or another register.
2098 LABEL indicates the address of EXPR.
2100 This function encodes a state machine mapping rtxes to actions on
2101 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2102 users need not read the source code.
2104 The High-Level Picture
2106 Changes in the register we use to calculate the CFA: Currently we
2107 assume that if you copy the CFA register into another register, we
2108 should take the other one as the new CFA register; this seems to
2109 work pretty well. If it's wrong for some target, it's simple
2110 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2112 Changes in the register we use for saving registers to the stack:
2113 This is usually SP, but not always. Again, we deduce that if you
2114 copy SP into another register (and SP is not the CFA register),
2115 then the new register is the one we will be using for register
2116 saves. This also seems to work.
2118 Register saves: There's not much guesswork about this one; if
2119 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2120 register save, and the register used to calculate the destination
2121 had better be the one we think we're using for this purpose.
2122 It's also assumed that a copy from a call-saved register to another
2123 register is saving that register if RTX_FRAME_RELATED_P is set on
2124 that instruction. If the copy is from a call-saved register to
2125 the *same* register, that means that the register is now the same
2126 value as in the caller.
2128 Except: If the register being saved is the CFA register, and the
2129 offset is nonzero, we are saving the CFA, so we assume we have to
2130 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2131 the intent is to save the value of SP from the previous frame.
2133 In addition, if a register has previously been saved to a different
2136 Invariants / Summaries of Rules
2138 cfa current rule for calculating the CFA. It usually
2139 consists of a register and an offset.
2140 cfa_store register used by prologue code to save things to the stack
2141 cfa_store.offset is the offset from the value of
2142 cfa_store.reg to the actual CFA
2143 cfa_temp register holding an integral value. cfa_temp.offset
2144 stores the value, which will be used to adjust the
2145 stack pointer. cfa_temp is also used like cfa_store,
2146 to track stores to the stack via fp or a temp reg.
2148 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2149 with cfa.reg as the first operand changes the cfa.reg and its
2150 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2153 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2154 expression yielding a constant. This sets cfa_temp.reg
2155 and cfa_temp.offset.
2157 Rule 5: Create a new register cfa_store used to save items to the
2160 Rules 10-14: Save a register to the stack. Define offset as the
2161 difference of the original location and cfa_store's
2162 location (or cfa_temp's location if cfa_temp is used).
2164 Rules 16-20: If AND operation happens on sp in prologue, we assume
2165 stack is realigned. We will use a group of DW_OP_XXX
2166 expressions to represent the location of the stored
2167 register instead of CFA+offset.
2171 "{a,b}" indicates a choice of a xor b.
2172 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2175 (set <reg1> <reg2>:cfa.reg)
2176 effects: cfa.reg = <reg1>
2177 cfa.offset unchanged
2178 cfa_temp.reg = <reg1>
2179 cfa_temp.offset = cfa.offset
2182 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2183 {<const_int>,<reg>:cfa_temp.reg}))
2184 effects: cfa.reg = sp if fp used
2185 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2186 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2187 if cfa_store.reg==sp
2190 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2191 effects: cfa.reg = fp
2192 cfa_offset += +/- <const_int>
2195 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2196 constraints: <reg1> != fp
2198 effects: cfa.reg = <reg1>
2199 cfa_temp.reg = <reg1>
2200 cfa_temp.offset = cfa.offset
2203 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2204 constraints: <reg1> != fp
2206 effects: cfa_store.reg = <reg1>
2207 cfa_store.offset = cfa.offset - cfa_temp.offset
2210 (set <reg> <const_int>)
2211 effects: cfa_temp.reg = <reg>
2212 cfa_temp.offset = <const_int>
2215 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2216 effects: cfa_temp.reg = <reg1>
2217 cfa_temp.offset |= <const_int>
2220 (set <reg> (high <exp>))
2224 (set <reg> (lo_sum <exp> <const_int>))
2225 effects: cfa_temp.reg = <reg>
2226 cfa_temp.offset = <const_int>
2229 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2230 effects: cfa_store.offset -= <const_int>
2231 cfa.offset = cfa_store.offset if cfa.reg == sp
2233 cfa.base_offset = -cfa_store.offset
2236 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2237 effects: cfa_store.offset += -/+ mode_size(mem)
2238 cfa.offset = cfa_store.offset if cfa.reg == sp
2240 cfa.base_offset = -cfa_store.offset
2243 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2246 effects: cfa.reg = <reg1>
2247 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2250 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2251 effects: cfa.reg = <reg1>
2252 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2255 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2256 effects: cfa.reg = <reg1>
2257 cfa.base_offset = -cfa_temp.offset
2258 cfa_temp.offset -= mode_size(mem)
2261 (set <reg> {unspec, unspec_volatile})
2262 effects: target-dependent
2265 (set sp (and: sp <const_int>))
2266 constraints: cfa_store.reg == sp
2267 effects: current_fde.stack_realign = 1
2268 cfa_store.offset = 0
2269 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2272 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2273 effects: cfa_store.offset += -/+ mode_size(mem)
2276 (set (mem ({pre_inc, pre_dec} sp)) fp)
2277 constraints: fde->stack_realign == 1
2278 effects: cfa_store.offset = 0
2279 cfa.reg != HARD_FRAME_POINTER_REGNUM
2282 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2283 constraints: fde->stack_realign == 1
2285 && cfa.indirect == 0
2286 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2287 effects: Use DW_CFA_def_cfa_expression to define cfa
2288 cfa.reg == fde->drap_reg */
2291 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2293 rtx src, dest, span;
2294 HOST_WIDE_INT offset;
2297 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2298 the PARALLEL independently. The first element is always processed if
2299 it is a SET. This is for backward compatibility. Other elements
2300 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2301 flag is set in them. */
2302 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2305 int limit = XVECLEN (expr, 0);
2308 /* PARALLELs have strict read-modify-write semantics, so we
2309 ought to evaluate every rvalue before changing any lvalue.
2310 It's cumbersome to do that in general, but there's an
2311 easy approximation that is enough for all current users:
2312 handle register saves before register assignments. */
2313 if (GET_CODE (expr) == PARALLEL)
2314 for (par_index = 0; par_index < limit; par_index++)
2316 elem = XVECEXP (expr, 0, par_index);
2317 if (GET_CODE (elem) == SET
2318 && MEM_P (SET_DEST (elem))
2319 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2320 dwarf2out_frame_debug_expr (elem, label);
2323 for (par_index = 0; par_index < limit; par_index++)
2325 elem = XVECEXP (expr, 0, par_index);
2326 if (GET_CODE (elem) == SET
2327 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2328 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2329 dwarf2out_frame_debug_expr (elem, label);
2330 else if (GET_CODE (elem) == SET
2332 && !RTX_FRAME_RELATED_P (elem))
2334 /* Stack adjustment combining might combine some post-prologue
2335 stack adjustment into a prologue stack adjustment. */
2336 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2339 dwarf2out_stack_adjust (offset, label);
2345 gcc_assert (GET_CODE (expr) == SET);
2347 src = SET_SRC (expr);
2348 dest = SET_DEST (expr);
2352 rtx rsi = reg_saved_in (src);
2357 fde = current_fde ();
2359 switch (GET_CODE (dest))
2362 switch (GET_CODE (src))
2364 /* Setting FP from SP. */
2366 if (cfa.reg == (unsigned) REGNO (src))
2369 /* Update the CFA rule wrt SP or FP. Make sure src is
2370 relative to the current CFA register.
2372 We used to require that dest be either SP or FP, but the
2373 ARM copies SP to a temporary register, and from there to
2374 FP. So we just rely on the backends to only set
2375 RTX_FRAME_RELATED_P on appropriate insns. */
2376 cfa.reg = REGNO (dest);
2377 cfa_temp.reg = cfa.reg;
2378 cfa_temp.offset = cfa.offset;
2382 /* Saving a register in a register. */
2383 gcc_assert (!fixed_regs [REGNO (dest)]
2384 /* For the SPARC and its register window. */
2385 || (DWARF_FRAME_REGNUM (REGNO (src))
2386 == DWARF_FRAME_RETURN_COLUMN));
2388 /* After stack is aligned, we can only save SP in FP
2389 if drap register is used. In this case, we have
2390 to restore stack pointer with the CFA value and we
2391 don't generate this DWARF information. */
2393 && fde->stack_realign
2394 && REGNO (src) == STACK_POINTER_REGNUM)
2395 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2396 && fde->drap_reg != INVALID_REGNUM
2397 && cfa.reg != REGNO (src));
2399 queue_reg_save (label, src, dest, 0);
2406 if (dest == stack_pointer_rtx)
2410 switch (GET_CODE (XEXP (src, 1)))
2413 offset = INTVAL (XEXP (src, 1));
2416 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2418 offset = cfa_temp.offset;
2424 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2426 /* Restoring SP from FP in the epilogue. */
2427 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2428 cfa.reg = STACK_POINTER_REGNUM;
2430 else if (GET_CODE (src) == LO_SUM)
2431 /* Assume we've set the source reg of the LO_SUM from sp. */
2434 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2436 if (GET_CODE (src) != MINUS)
2438 if (cfa.reg == STACK_POINTER_REGNUM)
2439 cfa.offset += offset;
2440 if (cfa_store.reg == STACK_POINTER_REGNUM)
2441 cfa_store.offset += offset;
2443 else if (dest == hard_frame_pointer_rtx)
2446 /* Either setting the FP from an offset of the SP,
2447 or adjusting the FP */
2448 gcc_assert (frame_pointer_needed);
2450 gcc_assert (REG_P (XEXP (src, 0))
2451 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2452 && CONST_INT_P (XEXP (src, 1)));
2453 offset = INTVAL (XEXP (src, 1));
2454 if (GET_CODE (src) != MINUS)
2456 cfa.offset += offset;
2457 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2461 gcc_assert (GET_CODE (src) != MINUS);
2464 if (REG_P (XEXP (src, 0))
2465 && REGNO (XEXP (src, 0)) == cfa.reg
2466 && CONST_INT_P (XEXP (src, 1)))
2468 /* Setting a temporary CFA register that will be copied
2469 into the FP later on. */
2470 offset = - INTVAL (XEXP (src, 1));
2471 cfa.offset += offset;
2472 cfa.reg = REGNO (dest);
2473 /* Or used to save regs to the stack. */
2474 cfa_temp.reg = cfa.reg;
2475 cfa_temp.offset = cfa.offset;
2479 else if (REG_P (XEXP (src, 0))
2480 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2481 && XEXP (src, 1) == stack_pointer_rtx)
2483 /* Setting a scratch register that we will use instead
2484 of SP for saving registers to the stack. */
2485 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2486 cfa_store.reg = REGNO (dest);
2487 cfa_store.offset = cfa.offset - cfa_temp.offset;
2491 else if (GET_CODE (src) == LO_SUM
2492 && CONST_INT_P (XEXP (src, 1)))
2494 cfa_temp.reg = REGNO (dest);
2495 cfa_temp.offset = INTVAL (XEXP (src, 1));
2504 cfa_temp.reg = REGNO (dest);
2505 cfa_temp.offset = INTVAL (src);
2510 gcc_assert (REG_P (XEXP (src, 0))
2511 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2512 && CONST_INT_P (XEXP (src, 1)));
2514 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2515 cfa_temp.reg = REGNO (dest);
2516 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2519 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2520 which will fill in all of the bits. */
2527 case UNSPEC_VOLATILE:
2528 gcc_assert (targetm.dwarf_handle_frame_unspec);
2529 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2534 /* If this AND operation happens on stack pointer in prologue,
2535 we assume the stack is realigned and we extract the
2537 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2539 /* We interpret reg_save differently with stack_realign set.
2540 Thus we must flush whatever we have queued first. */
2541 dwarf2out_flush_queued_reg_saves ();
2543 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2544 fde->stack_realign = 1;
2545 fde->stack_realignment = INTVAL (XEXP (src, 1));
2546 cfa_store.offset = 0;
2548 if (cfa.reg != STACK_POINTER_REGNUM
2549 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2550 fde->drap_reg = cfa.reg;
2558 def_cfa_1 (label, &cfa);
2563 /* Saving a register to the stack. Make sure dest is relative to the
2565 switch (GET_CODE (XEXP (dest, 0)))
2570 /* We can't handle variable size modifications. */
2571 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2573 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2575 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2576 && cfa_store.reg == STACK_POINTER_REGNUM);
2578 cfa_store.offset += offset;
2579 if (cfa.reg == STACK_POINTER_REGNUM)
2580 cfa.offset = cfa_store.offset;
2582 offset = -cfa_store.offset;
2589 offset = GET_MODE_SIZE (GET_MODE (dest));
2590 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2593 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2594 == STACK_POINTER_REGNUM)
2595 && cfa_store.reg == STACK_POINTER_REGNUM);
2597 cfa_store.offset += offset;
2599 /* Rule 18: If stack is aligned, we will use FP as a
2600 reference to represent the address of the stored
2603 && fde->stack_realign
2604 && src == hard_frame_pointer_rtx)
2606 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2607 cfa_store.offset = 0;
2610 if (cfa.reg == STACK_POINTER_REGNUM)
2611 cfa.offset = cfa_store.offset;
2613 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2614 offset += -cfa_store.offset;
2616 offset = -cfa_store.offset;
2620 /* With an offset. */
2627 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2628 && REG_P (XEXP (XEXP (dest, 0), 0)));
2629 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2630 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2633 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2635 if (cfa.reg == (unsigned) regno)
2636 offset -= cfa.offset;
2637 else if (cfa_store.reg == (unsigned) regno)
2638 offset -= cfa_store.offset;
2641 gcc_assert (cfa_temp.reg == (unsigned) regno);
2642 offset -= cfa_temp.offset;
2648 /* Without an offset. */
2651 int regno = REGNO (XEXP (dest, 0));
2653 if (cfa.reg == (unsigned) regno)
2654 offset = -cfa.offset;
2655 else if (cfa_store.reg == (unsigned) regno)
2656 offset = -cfa_store.offset;
2659 gcc_assert (cfa_temp.reg == (unsigned) regno);
2660 offset = -cfa_temp.offset;
2667 gcc_assert (cfa_temp.reg
2668 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2669 offset = -cfa_temp.offset;
2670 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2678 /* If the source operand of this MEM operation is not a
2679 register, basically the source is return address. Here
2680 we only care how much stack grew and we don't save it. */
2684 if (REGNO (src) != STACK_POINTER_REGNUM
2685 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2686 && (unsigned) REGNO (src) == cfa.reg)
2688 /* We're storing the current CFA reg into the stack. */
2690 if (cfa.offset == 0)
2693 /* If stack is aligned, putting CFA reg into stack means
2694 we can no longer use reg + offset to represent CFA.
2695 Here we use DW_CFA_def_cfa_expression instead. The
2696 result of this expression equals to the original CFA
2699 && fde->stack_realign
2700 && cfa.indirect == 0
2701 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2703 dw_cfa_location cfa_exp;
2705 gcc_assert (fde->drap_reg == cfa.reg);
2707 cfa_exp.indirect = 1;
2708 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2709 cfa_exp.base_offset = offset;
2712 fde->drap_reg_saved = 1;
2714 def_cfa_1 (label, &cfa_exp);
2718 /* If the source register is exactly the CFA, assume
2719 we're saving SP like any other register; this happens
2721 def_cfa_1 (label, &cfa);
2722 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2727 /* Otherwise, we'll need to look in the stack to
2728 calculate the CFA. */
2729 rtx x = XEXP (dest, 0);
2733 gcc_assert (REG_P (x));
2735 cfa.reg = REGNO (x);
2736 cfa.base_offset = offset;
2738 def_cfa_1 (label, &cfa);
2743 def_cfa_1 (label, &cfa);
2745 span = targetm.dwarf_register_span (src);
2748 queue_reg_save (label, src, NULL_RTX, offset);
2751 /* We have a PARALLEL describing where the contents of SRC
2752 live. Queue register saves for each piece of the
2756 HOST_WIDE_INT span_offset = offset;
2758 gcc_assert (GET_CODE (span) == PARALLEL);
2760 limit = XVECLEN (span, 0);
2761 for (par_index = 0; par_index < limit; par_index++)
2763 rtx elem = XVECEXP (span, 0, par_index);
2765 queue_reg_save (label, elem, NULL_RTX, span_offset);
2766 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2777 /* Record call frame debugging information for INSN, which either
2778 sets SP or FP (adjusting how we calculate the frame address) or saves a
2779 register to the stack. If INSN is NULL_RTX, initialize our state.
2781 If AFTER_P is false, we're being called before the insn is emitted,
2782 otherwise after. Call instructions get invoked twice. */
2785 dwarf2out_frame_debug (rtx insn, bool after_p)
2789 bool handled_one = false;
2791 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2792 dwarf2out_flush_queued_reg_saves ();
2794 if (!RTX_FRAME_RELATED_P (insn))
2796 /* ??? This should be done unconditionally since stack adjustments
2797 matter if the stack pointer is not the CFA register anymore but
2798 is still used to save registers. */
2799 if (!ACCUMULATE_OUTGOING_ARGS)
2800 dwarf2out_notice_stack_adjust (insn, after_p);
2804 label = dwarf2out_cfi_label (false);
2805 any_cfis_emitted = false;
2807 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2808 switch (REG_NOTE_KIND (note))
2810 case REG_FRAME_RELATED_EXPR:
2811 insn = XEXP (note, 0);
2814 case REG_CFA_DEF_CFA:
2815 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2819 case REG_CFA_ADJUST_CFA:
2824 if (GET_CODE (n) == PARALLEL)
2825 n = XVECEXP (n, 0, 0);
2827 dwarf2out_frame_debug_adjust_cfa (n, label);
2831 case REG_CFA_OFFSET:
2834 n = single_set (insn);
2835 dwarf2out_frame_debug_cfa_offset (n, label);
2839 case REG_CFA_REGISTER:
2844 if (GET_CODE (n) == PARALLEL)
2845 n = XVECEXP (n, 0, 0);
2847 dwarf2out_frame_debug_cfa_register (n, label);
2851 case REG_CFA_EXPRESSION:
2854 n = single_set (insn);
2855 dwarf2out_frame_debug_cfa_expression (n, label);
2859 case REG_CFA_RESTORE:
2864 if (GET_CODE (n) == PARALLEL)
2865 n = XVECEXP (n, 0, 0);
2868 dwarf2out_frame_debug_cfa_restore (n, label);
2872 case REG_CFA_SET_VDRAP:
2876 dw_fde_ref fde = current_fde ();
2879 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2881 fde->vdrap_reg = REGNO (n);
2892 if (any_cfis_emitted)
2893 dwarf2out_flush_queued_reg_saves ();
2897 insn = PATTERN (insn);
2899 dwarf2out_frame_debug_expr (insn, label);
2901 /* Check again. A parallel can save and update the same register.
2902 We could probably check just once, here, but this is safer than
2903 removing the check above. */
2904 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2905 dwarf2out_flush_queued_reg_saves ();
2908 /* Called once at the start of final to initialize some data for the
2909 current function. */
2911 dwarf2out_frame_debug_init (void)
2915 /* Flush any queued register saves. */
2916 dwarf2out_flush_queued_reg_saves ();
2918 /* Set up state for generating call frame debug info. */
2921 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2923 cfa.reg = STACK_POINTER_REGNUM;
2926 cfa_temp.offset = 0;
2928 for (i = 0; i < num_regs_saved_in_regs; i++)
2930 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2931 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2933 num_regs_saved_in_regs = 0;
2935 if (barrier_args_size)
2937 XDELETEVEC (barrier_args_size);
2938 barrier_args_size = NULL;
2942 /* Determine if we need to save and restore CFI information around this
2943 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2944 we do need to save/restore, then emit the save now, and insert a
2945 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2948 dwarf2out_cfi_begin_epilogue (rtx insn)
2950 bool saw_frp = false;
2953 /* Scan forward to the return insn, noticing if there are possible
2954 frame related insns. */
2955 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2960 /* Look for both regular and sibcalls to end the block. */
2961 if (returnjump_p (i))
2963 if (CALL_P (i) && SIBLING_CALL_P (i))
2966 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2969 rtx seq = PATTERN (i);
2971 if (returnjump_p (XVECEXP (seq, 0, 0)))
2973 if (CALL_P (XVECEXP (seq, 0, 0))
2974 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2977 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2978 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2982 if (RTX_FRAME_RELATED_P (i))
2986 /* If the port doesn't emit epilogue unwind info, we don't need a
2987 save/restore pair. */
2991 /* Otherwise, search forward to see if the return insn was the last
2992 basic block of the function. If so, we don't need save/restore. */
2993 gcc_assert (i != NULL);
2994 i = next_real_insn (i);
2998 /* Insert the restore before that next real insn in the stream, and before
2999 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3000 properly nested. This should be after any label or alignment. This
3001 will be pushed into the CFI stream by the function below. */
3004 rtx p = PREV_INSN (i);
3007 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3011 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3013 emit_cfa_remember = true;
3015 /* And emulate the state save. */
3016 gcc_assert (!cfa_remember.in_use);
3018 cfa_remember.in_use = 1;
3021 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3025 dwarf2out_frame_debug_restore_state (void)
3027 dw_cfi_ref cfi = new_cfi ();
3028 const char *label = dwarf2out_cfi_label (false);
3030 cfi->dw_cfi_opc = DW_CFA_restore_state;
3031 add_fde_cfi (label, cfi);
3033 gcc_assert (cfa_remember.in_use);
3035 cfa_remember.in_use = 0;
3038 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3039 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3040 (enum dwarf_call_frame_info cfi);
3042 static enum dw_cfi_oprnd_type
3043 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3048 case DW_CFA_GNU_window_save:
3049 case DW_CFA_remember_state:
3050 case DW_CFA_restore_state:
3051 return dw_cfi_oprnd_unused;
3053 case DW_CFA_set_loc:
3054 case DW_CFA_advance_loc1:
3055 case DW_CFA_advance_loc2:
3056 case DW_CFA_advance_loc4:
3057 case DW_CFA_MIPS_advance_loc8:
3058 return dw_cfi_oprnd_addr;
3061 case DW_CFA_offset_extended:
3062 case DW_CFA_def_cfa:
3063 case DW_CFA_offset_extended_sf:
3064 case DW_CFA_def_cfa_sf:
3065 case DW_CFA_restore:
3066 case DW_CFA_restore_extended:
3067 case DW_CFA_undefined:
3068 case DW_CFA_same_value:
3069 case DW_CFA_def_cfa_register:
3070 case DW_CFA_register:
3071 case DW_CFA_expression:
3072 return dw_cfi_oprnd_reg_num;
3074 case DW_CFA_def_cfa_offset:
3075 case DW_CFA_GNU_args_size:
3076 case DW_CFA_def_cfa_offset_sf:
3077 return dw_cfi_oprnd_offset;
3079 case DW_CFA_def_cfa_expression:
3080 return dw_cfi_oprnd_loc;
3087 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3088 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3089 (enum dwarf_call_frame_info cfi);
3091 static enum dw_cfi_oprnd_type
3092 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3096 case DW_CFA_def_cfa:
3097 case DW_CFA_def_cfa_sf:
3099 case DW_CFA_offset_extended_sf:
3100 case DW_CFA_offset_extended:
3101 return dw_cfi_oprnd_offset;
3103 case DW_CFA_register:
3104 return dw_cfi_oprnd_reg_num;
3106 case DW_CFA_expression:
3107 return dw_cfi_oprnd_loc;
3110 return dw_cfi_oprnd_unused;
3114 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3115 switch to the data section instead, and write out a synthetic start label
3116 for collect2 the first time around. */
3119 switch_to_eh_frame_section (bool back)
3123 #ifdef EH_FRAME_SECTION_NAME
3124 if (eh_frame_section == 0)
3128 if (EH_TABLES_CAN_BE_READ_ONLY)
3134 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3136 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3138 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3140 flags = ((! flag_pic
3141 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3142 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3143 && (per_encoding & 0x70) != DW_EH_PE_absptr
3144 && (per_encoding & 0x70) != DW_EH_PE_aligned
3145 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3146 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3147 ? 0 : SECTION_WRITE);
3150 flags = SECTION_WRITE;
3151 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3153 #endif /* EH_FRAME_SECTION_NAME */
3155 if (eh_frame_section)
3156 switch_to_section (eh_frame_section);
3159 /* We have no special eh_frame section. Put the information in
3160 the data section and emit special labels to guide collect2. */
3161 switch_to_section (data_section);
3165 label = get_file_function_name ("F");
3166 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3167 targetm.asm_out.globalize_label (asm_out_file,
3168 IDENTIFIER_POINTER (label));
3169 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3174 /* Switch [BACK] to the eh or debug frame table section, depending on
3178 switch_to_frame_table_section (int for_eh, bool back)
3181 switch_to_eh_frame_section (back);
3184 if (!debug_frame_section)
3185 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3186 SECTION_DEBUG, NULL);
3187 switch_to_section (debug_frame_section);
3191 /* Output a Call Frame Information opcode and its operand(s). */
3194 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3199 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3200 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3201 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3202 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3203 ((unsigned HOST_WIDE_INT)
3204 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3205 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3208 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3209 "DW_CFA_offset, column %#lx", r);
3210 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3211 dw2_asm_output_data_uleb128 (off, NULL);
3213 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3216 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3217 "DW_CFA_restore, column %#lx", r);
3221 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3222 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3224 switch (cfi->dw_cfi_opc)
3226 case DW_CFA_set_loc:
3228 dw2_asm_output_encoded_addr_rtx (
3229 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3230 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3233 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3234 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3235 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3238 case DW_CFA_advance_loc1:
3239 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3240 fde->dw_fde_current_label, NULL);
3241 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3244 case DW_CFA_advance_loc2:
3245 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3246 fde->dw_fde_current_label, NULL);
3247 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3250 case DW_CFA_advance_loc4:
3251 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3252 fde->dw_fde_current_label, NULL);
3253 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3256 case DW_CFA_MIPS_advance_loc8:
3257 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3258 fde->dw_fde_current_label, NULL);
3259 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3262 case DW_CFA_offset_extended:
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3264 dw2_asm_output_data_uleb128 (r, NULL);
3265 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3266 dw2_asm_output_data_uleb128 (off, NULL);
3269 case DW_CFA_def_cfa:
3270 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3271 dw2_asm_output_data_uleb128 (r, NULL);
3272 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3275 case DW_CFA_offset_extended_sf:
3276 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3277 dw2_asm_output_data_uleb128 (r, NULL);
3278 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3279 dw2_asm_output_data_sleb128 (off, NULL);
3282 case DW_CFA_def_cfa_sf:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3284 dw2_asm_output_data_uleb128 (r, NULL);
3285 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3286 dw2_asm_output_data_sleb128 (off, NULL);
3289 case DW_CFA_restore_extended:
3290 case DW_CFA_undefined:
3291 case DW_CFA_same_value:
3292 case DW_CFA_def_cfa_register:
3293 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3294 dw2_asm_output_data_uleb128 (r, NULL);
3297 case DW_CFA_register:
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3299 dw2_asm_output_data_uleb128 (r, NULL);
3300 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3301 dw2_asm_output_data_uleb128 (r, NULL);
3304 case DW_CFA_def_cfa_offset:
3305 case DW_CFA_GNU_args_size:
3306 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3309 case DW_CFA_def_cfa_offset_sf:
3310 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3311 dw2_asm_output_data_sleb128 (off, NULL);
3314 case DW_CFA_GNU_window_save:
3317 case DW_CFA_def_cfa_expression:
3318 case DW_CFA_expression:
3319 output_cfa_loc (cfi, for_eh);
3322 case DW_CFA_GNU_negative_offset_extended:
3323 /* Obsoleted by DW_CFA_offset_extended_sf. */
3332 /* Similar, but do it via assembler directives instead. */
3335 output_cfi_directive (dw_cfi_ref cfi)
3337 unsigned long r, r2;
3339 switch (cfi->dw_cfi_opc)
3341 case DW_CFA_advance_loc:
3342 case DW_CFA_advance_loc1:
3343 case DW_CFA_advance_loc2:
3344 case DW_CFA_advance_loc4:
3345 case DW_CFA_MIPS_advance_loc8:
3346 case DW_CFA_set_loc:
3347 /* Should only be created by add_fde_cfi in a code path not
3348 followed when emitting via directives. The assembler is
3349 going to take care of this for us. */
3353 case DW_CFA_offset_extended:
3354 case DW_CFA_offset_extended_sf:
3355 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3356 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3357 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3360 case DW_CFA_restore:
3361 case DW_CFA_restore_extended:
3362 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3363 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3366 case DW_CFA_undefined:
3367 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3368 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3371 case DW_CFA_same_value:
3372 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3373 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3376 case DW_CFA_def_cfa:
3377 case DW_CFA_def_cfa_sf:
3378 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3379 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3380 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3383 case DW_CFA_def_cfa_register:
3384 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3385 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3388 case DW_CFA_register:
3389 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3390 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3391 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3394 case DW_CFA_def_cfa_offset:
3395 case DW_CFA_def_cfa_offset_sf:
3396 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3397 HOST_WIDE_INT_PRINT_DEC"\n",
3398 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3401 case DW_CFA_remember_state:
3402 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3404 case DW_CFA_restore_state:
3405 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3408 case DW_CFA_GNU_args_size:
3409 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3410 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3412 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3413 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3414 fputc ('\n', asm_out_file);
3417 case DW_CFA_GNU_window_save:
3418 fprintf (asm_out_file, "\t.cfi_window_save\n");
3421 case DW_CFA_def_cfa_expression:
3422 case DW_CFA_expression:
3423 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3424 output_cfa_loc_raw (cfi);
3425 fputc ('\n', asm_out_file);
3433 DEF_VEC_P (dw_cfi_ref);
3434 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3436 /* Output CFIs to bring current FDE to the same state as after executing
3437 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3438 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3439 other arguments to pass to output_cfi. */
3442 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3444 struct dw_cfi_struct cfi_buf;
3446 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3447 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3448 unsigned int len, idx;
3450 for (;; cfi = cfi->dw_cfi_next)
3451 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3453 case DW_CFA_advance_loc:
3454 case DW_CFA_advance_loc1:
3455 case DW_CFA_advance_loc2:
3456 case DW_CFA_advance_loc4:
3457 case DW_CFA_MIPS_advance_loc8:
3458 case DW_CFA_set_loc:
3459 /* All advances should be ignored. */
3461 case DW_CFA_remember_state:
3463 dw_cfi_ref args_size = cfi_args_size;
3465 /* Skip everything between .cfi_remember_state and
3466 .cfi_restore_state. */
3467 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3468 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3470 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3473 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3480 cfi_args_size = args_size;
3484 case DW_CFA_GNU_args_size:
3485 cfi_args_size = cfi;
3487 case DW_CFA_GNU_window_save:
3490 case DW_CFA_offset_extended:
3491 case DW_CFA_offset_extended_sf:
3492 case DW_CFA_restore:
3493 case DW_CFA_restore_extended:
3494 case DW_CFA_undefined:
3495 case DW_CFA_same_value:
3496 case DW_CFA_register:
3497 case DW_CFA_val_offset:
3498 case DW_CFA_val_offset_sf:
3499 case DW_CFA_expression:
3500 case DW_CFA_val_expression:
3501 case DW_CFA_GNU_negative_offset_extended:
3502 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3503 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3504 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3505 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3507 case DW_CFA_def_cfa:
3508 case DW_CFA_def_cfa_sf:
3509 case DW_CFA_def_cfa_expression:
3511 cfi_cfa_offset = cfi;
3513 case DW_CFA_def_cfa_register:
3516 case DW_CFA_def_cfa_offset:
3517 case DW_CFA_def_cfa_offset_sf:
3518 cfi_cfa_offset = cfi;
3521 gcc_assert (cfi == NULL);
3523 len = VEC_length (dw_cfi_ref, regs);
3524 for (idx = 0; idx < len; idx++)
3526 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3528 && cfi2->dw_cfi_opc != DW_CFA_restore
3529 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3532 output_cfi_directive (cfi2);
3534 output_cfi (cfi2, fde, for_eh);
3537 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3539 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3541 switch (cfi_cfa_offset->dw_cfi_opc)
3543 case DW_CFA_def_cfa_offset:
3544 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3545 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3547 case DW_CFA_def_cfa_offset_sf:
3548 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3549 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3551 case DW_CFA_def_cfa:
3552 case DW_CFA_def_cfa_sf:
3553 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3554 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3561 else if (cfi_cfa_offset)
3562 cfi_cfa = cfi_cfa_offset;
3566 output_cfi_directive (cfi_cfa);
3568 output_cfi (cfi_cfa, fde, for_eh);
3571 cfi_cfa_offset = NULL;
3573 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3576 output_cfi_directive (cfi_args_size);
3578 output_cfi (cfi_args_size, fde, for_eh);
3580 cfi_args_size = NULL;
3583 VEC_free (dw_cfi_ref, heap, regs);
3586 else if (do_cfi_asm)
3587 output_cfi_directive (cfi);
3589 output_cfi (cfi, fde, for_eh);
3596 /* Output one FDE. */
3599 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3600 char *section_start_label, int fde_encoding, char *augmentation,
3601 bool any_lsda_needed, int lsda_encoding)
3603 const char *begin, *end;
3604 static unsigned int j;
3605 char l1[20], l2[20];
3608 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3610 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3612 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3613 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3614 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3615 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3616 " indicating 64-bit DWARF extension");
3617 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3619 ASM_OUTPUT_LABEL (asm_out_file, l1);
3622 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3624 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3625 debug_frame_section, "FDE CIE offset");
3627 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3628 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3632 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3633 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3634 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3635 "FDE initial location");
3636 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3637 end, begin, "FDE address range");
3641 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3642 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3645 if (augmentation[0])
3647 if (any_lsda_needed)
3649 int size = size_of_encoded_value (lsda_encoding);
3651 if (lsda_encoding == DW_EH_PE_aligned)
3653 int offset = ( 4 /* Length */
3654 + 4 /* CIE offset */
3655 + 2 * size_of_encoded_value (fde_encoding)
3656 + 1 /* Augmentation size */ );
3657 int pad = -offset & (PTR_SIZE - 1);
3660 gcc_assert (size_of_uleb128 (size) == 1);
3663 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3665 if (fde->uses_eh_lsda)
3667 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3668 fde->funcdef_number);
3669 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3670 gen_rtx_SYMBOL_REF (Pmode, l1),
3672 "Language Specific Data Area");
3676 if (lsda_encoding == DW_EH_PE_aligned)
3677 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3678 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3679 "Language Specific Data Area (none)");
3683 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3686 /* Loop through the Call Frame Instructions associated with
3688 fde->dw_fde_current_label = begin;
3689 if (fde->dw_fde_second_begin == NULL)
3690 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3691 output_cfi (cfi, fde, for_eh);
3694 if (fde->dw_fde_switch_cfi)
3695 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3697 output_cfi (cfi, fde, for_eh);
3698 if (cfi == fde->dw_fde_switch_cfi)
3704 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3706 if (fde->dw_fde_switch_cfi)
3708 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3709 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3710 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3711 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3713 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3714 output_cfi (cfi, fde, for_eh);
3717 /* If we are to emit a ref/link from function bodies to their frame tables,
3718 do it now. This is typically performed to make sure that tables
3719 associated with functions are dragged with them and not discarded in
3720 garbage collecting links. We need to do this on a per function basis to
3721 cope with -ffunction-sections. */
3723 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3724 /* Switch to the function section, emit the ref to the tables, and
3725 switch *back* into the table section. */
3726 switch_to_section (function_section (fde->decl));
3727 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3728 switch_to_frame_table_section (for_eh, true);
3731 /* Pad the FDE out to an address sized boundary. */
3732 ASM_OUTPUT_ALIGN (asm_out_file,
3733 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3734 ASM_OUTPUT_LABEL (asm_out_file, l2);
3739 /* Return true if frame description entry FDE is needed for EH. */
3742 fde_needed_for_eh_p (dw_fde_ref fde)
3744 if (flag_asynchronous_unwind_tables)
3747 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3750 if (fde->uses_eh_lsda)
3753 /* If exceptions are enabled, we have collected nothrow info. */
3754 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3760 /* Output the call frame information used to record information
3761 that relates to calculating the frame pointer, and records the
3762 location of saved registers. */
3765 output_call_frame_info (int for_eh)
3770 char l1[20], l2[20], section_start_label[20];
3771 bool any_lsda_needed = false;
3772 char augmentation[6];
3773 int augmentation_size;
3774 int fde_encoding = DW_EH_PE_absptr;
3775 int per_encoding = DW_EH_PE_absptr;
3776 int lsda_encoding = DW_EH_PE_absptr;
3778 rtx personality = NULL;
3781 /* Don't emit a CIE if there won't be any FDEs. */
3782 if (fde_table_in_use == 0)
3785 /* Nothing to do if the assembler's doing it all. */
3786 if (dwarf2out_do_cfi_asm ())
3789 /* If we don't have any functions we'll want to unwind out of, don't emit
3790 any EH unwind information. If we make FDEs linkonce, we may have to
3791 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3792 want to avoid having an FDE kept around when the function it refers to
3793 is discarded. Example where this matters: a primary function template
3794 in C++ requires EH information, an explicit specialization doesn't. */
3797 bool any_eh_needed = false;
3799 for (i = 0; i < fde_table_in_use; i++)
3800 if (fde_table[i].uses_eh_lsda)
3801 any_eh_needed = any_lsda_needed = true;
3802 else if (fde_needed_for_eh_p (&fde_table[i]))
3803 any_eh_needed = true;
3804 else if (TARGET_USES_WEAK_UNWIND_INFO)
3805 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3812 /* We're going to be generating comments, so turn on app. */
3816 /* Switch to the proper frame section, first time. */
3817 switch_to_frame_table_section (for_eh, false);
3819 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3820 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3822 /* Output the CIE. */
3823 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3824 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3825 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3826 dw2_asm_output_data (4, 0xffffffff,
3827 "Initial length escape value indicating 64-bit DWARF extension");
3828 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3829 "Length of Common Information Entry");
3830 ASM_OUTPUT_LABEL (asm_out_file, l1);
3832 /* Now that the CIE pointer is PC-relative for EH,
3833 use 0 to identify the CIE. */
3834 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3835 (for_eh ? 0 : DWARF_CIE_ID),
3836 "CIE Identifier Tag");
3838 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3839 use CIE version 1, unless that would produce incorrect results
3840 due to overflowing the return register column. */
3841 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3843 if (return_reg >= 256 || dwarf_version > 2)
3845 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3847 augmentation[0] = 0;
3848 augmentation_size = 0;
3850 personality = current_unit_personality;
3856 z Indicates that a uleb128 is present to size the
3857 augmentation section.
3858 L Indicates the encoding (and thus presence) of
3859 an LSDA pointer in the FDE augmentation.
3860 R Indicates a non-default pointer encoding for
3862 P Indicates the presence of an encoding + language
3863 personality routine in the CIE augmentation. */
3865 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3866 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3867 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3869 p = augmentation + 1;
3873 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3874 assemble_external_libcall (personality);
3876 if (any_lsda_needed)
3879 augmentation_size += 1;
3881 if (fde_encoding != DW_EH_PE_absptr)
3884 augmentation_size += 1;
3886 if (p > augmentation + 1)
3888 augmentation[0] = 'z';
3892 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3893 if (personality && per_encoding == DW_EH_PE_aligned)
3895 int offset = ( 4 /* Length */
3897 + 1 /* CIE version */
3898 + strlen (augmentation) + 1 /* Augmentation */
3899 + size_of_uleb128 (1) /* Code alignment */
3900 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3902 + 1 /* Augmentation size */
3903 + 1 /* Personality encoding */ );
3904 int pad = -offset & (PTR_SIZE - 1);
3906 augmentation_size += pad;
3908 /* Augmentations should be small, so there's scarce need to
3909 iterate for a solution. Die if we exceed one uleb128 byte. */
3910 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3914 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3915 if (dw_cie_version >= 4)
3917 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3918 dw2_asm_output_data (1, 0, "CIE Segment Size");
3920 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3921 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3922 "CIE Data Alignment Factor");
3924 if (dw_cie_version == 1)
3925 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3927 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3929 if (augmentation[0])
3931 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3934 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3935 eh_data_format_name (per_encoding));
3936 dw2_asm_output_encoded_addr_rtx (per_encoding,
3941 if (any_lsda_needed)
3942 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3943 eh_data_format_name (lsda_encoding));
3945 if (fde_encoding != DW_EH_PE_absptr)
3946 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3947 eh_data_format_name (fde_encoding));
3950 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3951 output_cfi (cfi, NULL, for_eh);
3953 /* Pad the CIE out to an address sized boundary. */
3954 ASM_OUTPUT_ALIGN (asm_out_file,
3955 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3956 ASM_OUTPUT_LABEL (asm_out_file, l2);
3958 /* Loop through all of the FDE's. */
3959 for (i = 0; i < fde_table_in_use; i++)
3962 fde = &fde_table[i];
3964 /* Don't emit EH unwind info for leaf functions that don't need it. */
3965 if (for_eh && !fde_needed_for_eh_p (fde))
3968 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3969 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3970 augmentation, any_lsda_needed, lsda_encoding);
3973 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3974 dw2_asm_output_data (4, 0, "End of Table");
3975 #ifdef MIPS_DEBUGGING_INFO
3976 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3977 get a value of 0. Putting .align 0 after the label fixes it. */
3978 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3981 /* Turn off app to make assembly quicker. */
3986 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3989 dwarf2out_do_cfi_startproc (bool second)
3993 rtx personality = get_personality_function (current_function_decl);
3995 fprintf (asm_out_file, "\t.cfi_startproc\n");
3999 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4002 /* ??? The GAS support isn't entirely consistent. We have to
4003 handle indirect support ourselves, but PC-relative is done
4004 in the assembler. Further, the assembler can't handle any
4005 of the weirder relocation types. */
4006 if (enc & DW_EH_PE_indirect)
4007 ref = dw2_force_const_mem (ref, true);
4009 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4010 output_addr_const (asm_out_file, ref);
4011 fputc ('\n', asm_out_file);
4014 if (crtl->uses_eh_lsda)
4018 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4019 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4020 current_function_funcdef_no);
4021 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4022 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4024 if (enc & DW_EH_PE_indirect)
4025 ref = dw2_force_const_mem (ref, true);
4027 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4028 output_addr_const (asm_out_file, ref);
4029 fputc ('\n', asm_out_file);
4033 /* Output a marker (i.e. a label) for the beginning of a function, before
4037 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4038 const char *file ATTRIBUTE_UNUSED)
4040 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4046 current_function_func_begin_label = NULL;
4048 do_frame = dwarf2out_do_frame ();
4050 /* ??? current_function_func_begin_label is also used by except.c for
4051 call-site information. We must emit this label if it might be used. */
4053 && (!flag_exceptions
4054 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4057 fnsec = function_section (current_function_decl);
4058 switch_to_section (fnsec);
4059 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4060 current_function_funcdef_no);
4061 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4062 current_function_funcdef_no);
4063 dup_label = xstrdup (label);
4064 current_function_func_begin_label = dup_label;
4066 /* We can elide the fde allocation if we're not emitting debug info. */
4070 /* Expand the fde table if necessary. */
4071 if (fde_table_in_use == fde_table_allocated)
4073 fde_table_allocated += FDE_TABLE_INCREMENT;
4074 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4075 memset (fde_table + fde_table_in_use, 0,
4076 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4079 /* Record the FDE associated with this function. */
4080 current_funcdef_fde = fde_table_in_use;
4082 /* Add the new FDE at the end of the fde_table. */
4083 fde = &fde_table[fde_table_in_use++];
4084 fde->decl = current_function_decl;
4085 fde->dw_fde_begin = dup_label;
4086 fde->dw_fde_end = NULL;
4087 fde->dw_fde_current_label = dup_label;
4088 fde->dw_fde_second_begin = NULL;
4089 fde->dw_fde_second_end = NULL;
4090 fde->dw_fde_vms_end_prologue = NULL;
4091 fde->dw_fde_vms_begin_epilogue = NULL;
4092 fde->dw_fde_cfi = NULL;
4093 fde->dw_fde_switch_cfi = NULL;
4094 fde->funcdef_number = current_function_funcdef_no;
4095 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4096 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4097 fde->nothrow = crtl->nothrow;
4098 fde->drap_reg = INVALID_REGNUM;
4099 fde->vdrap_reg = INVALID_REGNUM;
4100 fde->in_std_section = (fnsec == text_section
4101 || (cold_text_section && fnsec == cold_text_section));
4102 fde->second_in_std_section = 0;
4104 args_size = old_args_size = 0;
4106 /* We only want to output line number information for the genuine dwarf2
4107 prologue case, not the eh frame case. */
4108 #ifdef DWARF2_DEBUGGING_INFO
4110 dwarf2out_source_line (line, file, 0, true);
4113 if (dwarf2out_do_cfi_asm ())
4114 dwarf2out_do_cfi_startproc (false);
4117 rtx personality = get_personality_function (current_function_decl);
4118 if (!current_unit_personality)
4119 current_unit_personality = personality;
4121 /* We cannot keep a current personality per function as without CFI
4122 asm, at the point where we emit the CFI data, there is no current
4123 function anymore. */
4124 if (personality && current_unit_personality != personality)
4125 sorry ("multiple EH personalities are supported only with assemblers "
4126 "supporting .cfi_personality directive");
4130 /* Output a marker (i.e. a label) for the end of the generated code
4131 for a function prologue. This gets called *after* the prologue code has
4135 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4136 const char *file ATTRIBUTE_UNUSED)
4139 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4141 /* Output a label to mark the endpoint of the code generated for this
4143 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4144 current_function_funcdef_no);
4145 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4146 current_function_funcdef_no);
4147 fde = &fde_table[fde_table_in_use - 1];
4148 fde->dw_fde_vms_end_prologue = xstrdup (label);
4151 /* Output a marker (i.e. a label) for the beginning of the generated code
4152 for a function epilogue. This gets called *before* the prologue code has
4156 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4157 const char *file ATTRIBUTE_UNUSED)
4160 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4162 fde = &fde_table[fde_table_in_use - 1];
4163 if (fde->dw_fde_vms_begin_epilogue)
4166 /* Output a label to mark the endpoint of the code generated for this
4168 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4169 current_function_funcdef_no);
4170 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4171 current_function_funcdef_no);
4172 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4175 /* Output a marker (i.e. a label) for the absolute end of the generated code
4176 for a function definition. This gets called *after* the epilogue code has
4180 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4181 const char *file ATTRIBUTE_UNUSED)
4184 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4186 last_var_location_insn = NULL_RTX;
4188 if (dwarf2out_do_cfi_asm ())
4189 fprintf (asm_out_file, "\t.cfi_endproc\n");
4191 /* Output a label to mark t