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
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"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 /* ??? Poison these here until it can be done generically. They've been
116 totally replaced in this file; make sure it stays that way. */
117 #undef DWARF2_UNWIND_INFO
118 #undef DWARF2_FRAME_INFO
119 #if (GCC_VERSION >= 3000)
120 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
123 #ifndef INCOMING_RETURN_ADDR_RTX
124 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm = 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
149 if (saved_do_cfi_asm)
152 if (targetm.debug_unwind_info () == UI_DWARF2)
155 if ((flag_unwind_tables || flag_exceptions)
156 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
162 /* Decide whether to emit frame unwind via assembler directives. */
165 dwarf2out_do_cfi_asm (void)
169 #ifdef MIPS_DEBUGGING_INFO
172 if (saved_do_cfi_asm)
174 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
176 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
179 /* Make sure the personality encoding is one the assembler can support.
180 In particular, aligned addresses can't be handled. */
181 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
182 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
184 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
185 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
188 /* If we can't get the assembler to emit only .debug_frame, and we don't need
189 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
190 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
191 && !flag_unwind_tables && !flag_exceptions
192 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
195 saved_do_cfi_asm = true;
199 /* The size of the target's pointer type. */
201 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
204 /* Array of RTXes referenced by the debugging information, which therefore
205 must be kept around forever. */
206 static GTY(()) VEC(rtx,gc) *used_rtx_array;
208 /* A pointer to the base of a list of incomplete types which might be
209 completed at some later time. incomplete_types_list needs to be a
210 VEC(tree,gc) because we want to tell the garbage collector about
212 static GTY(()) VEC(tree,gc) *incomplete_types;
214 /* A pointer to the base of a table of references to declaration
215 scopes. This table is a display which tracks the nesting
216 of declaration scopes at the current scope and containing
217 scopes. This table is used to find the proper place to
218 define type declaration DIE's. */
219 static GTY(()) VEC(tree,gc) *decl_scope_table;
221 /* Pointers to various DWARF2 sections. */
222 static GTY(()) section *debug_info_section;
223 static GTY(()) section *debug_abbrev_section;
224 static GTY(()) section *debug_aranges_section;
225 static GTY(()) section *debug_macinfo_section;
226 static GTY(()) section *debug_line_section;
227 static GTY(()) section *debug_loc_section;
228 static GTY(()) section *debug_pubnames_section;
229 static GTY(()) section *debug_pubtypes_section;
230 static GTY(()) section *debug_dcall_section;
231 static GTY(()) section *debug_vcall_section;
232 static GTY(()) section *debug_str_section;
233 static GTY(()) section *debug_ranges_section;
234 static GTY(()) section *debug_frame_section;
236 /* Personality decl of current unit. Used only when assembler does not support
238 static GTY(()) rtx current_unit_personality;
240 /* How to start an assembler comment. */
241 #ifndef ASM_COMMENT_START
242 #define ASM_COMMENT_START ";#"
245 typedef struct dw_cfi_struct *dw_cfi_ref;
246 typedef struct dw_fde_struct *dw_fde_ref;
247 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
249 /* Call frames are described using a sequence of Call Frame
250 Information instructions. The register number, offset
251 and address fields are provided as possible operands;
252 their use is selected by the opcode field. */
254 enum dw_cfi_oprnd_type {
256 dw_cfi_oprnd_reg_num,
262 typedef union GTY(()) dw_cfi_oprnd_struct {
263 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
264 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
265 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
266 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
270 typedef struct GTY(()) dw_cfi_struct {
271 dw_cfi_ref dw_cfi_next;
272 enum dwarf_call_frame_info dw_cfi_opc;
273 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
275 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
280 /* This is how we define the location of the CFA. We use to handle it
281 as REG + OFFSET all the time, but now it can be more complex.
282 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
283 Instead of passing around REG and OFFSET, we pass a copy
284 of this structure. */
285 typedef struct cfa_loc {
286 HOST_WIDE_INT offset;
287 HOST_WIDE_INT base_offset;
289 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
290 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
293 /* All call frame descriptions (FDE's) in the GCC generated DWARF
294 refer to a single Common Information Entry (CIE), defined at
295 the beginning of the .debug_frame section. This use of a single
296 CIE obviates the need to keep track of multiple CIE's
297 in the DWARF generation routines below. */
299 typedef struct GTY(()) dw_fde_struct {
301 const char *dw_fde_begin;
302 const char *dw_fde_current_label;
303 const char *dw_fde_end;
304 const char *dw_fde_vms_end_prologue;
305 const char *dw_fde_vms_begin_epilogue;
306 const char *dw_fde_hot_section_label;
307 const char *dw_fde_hot_section_end_label;
308 const char *dw_fde_unlikely_section_label;
309 const char *dw_fde_unlikely_section_end_label;
310 dw_cfi_ref dw_fde_cfi;
311 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
312 HOST_WIDE_INT stack_realignment;
313 unsigned funcdef_number;
314 /* Dynamic realign argument pointer register. */
315 unsigned int drap_reg;
316 /* Virtual dynamic realign argument pointer register. */
317 unsigned int vdrap_reg;
318 /* These 3 flags are copied from rtl_data in function.h. */
319 unsigned all_throwers_are_sibcalls : 1;
320 unsigned uses_eh_lsda : 1;
321 unsigned nothrow : 1;
322 /* Whether we did stack realign in this call frame. */
323 unsigned stack_realign : 1;
324 /* Whether dynamic realign argument pointer register has been saved. */
325 unsigned drap_reg_saved: 1;
326 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
327 unsigned in_std_section : 1;
328 /* True iff dw_fde_unlikely_section_label is in text_section or
329 cold_text_section. */
330 unsigned cold_in_std_section : 1;
331 /* True iff switched sections. */
332 unsigned dw_fde_switched_sections : 1;
333 /* True iff switching from cold to hot section. */
334 unsigned dw_fde_switched_cold_to_hot : 1;
338 /* Maximum size (in bytes) of an artificially generated label. */
339 #define MAX_ARTIFICIAL_LABEL_BYTES 30
341 /* The size of addresses as they appear in the Dwarf 2 data.
342 Some architectures use word addresses to refer to code locations,
343 but Dwarf 2 info always uses byte addresses. On such machines,
344 Dwarf 2 addresses need to be larger than the architecture's
346 #ifndef DWARF2_ADDR_SIZE
347 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
350 /* The size in bytes of a DWARF field indicating an offset or length
351 relative to a debug info section, specified to be 4 bytes in the
352 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
355 #ifndef DWARF_OFFSET_SIZE
356 #define DWARF_OFFSET_SIZE 4
359 /* The size in bytes of a DWARF 4 type signature. */
361 #ifndef DWARF_TYPE_SIGNATURE_SIZE
362 #define DWARF_TYPE_SIGNATURE_SIZE 8
365 /* According to the (draft) DWARF 3 specification, the initial length
366 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
367 bytes are 0xffffffff, followed by the length stored in the next 8
370 However, the SGI/MIPS ABI uses an initial length which is equal to
371 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
373 #ifndef DWARF_INITIAL_LENGTH_SIZE
374 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
377 /* Round SIZE up to the nearest BOUNDARY. */
378 #define DWARF_ROUND(SIZE,BOUNDARY) \
379 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
381 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
382 #ifndef DWARF_CIE_DATA_ALIGNMENT
383 #ifdef STACK_GROWS_DOWNWARD
384 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
386 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
390 /* CIE identifier. */
391 #if HOST_BITS_PER_WIDE_INT >= 64
392 #define DWARF_CIE_ID \
393 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
395 #define DWARF_CIE_ID DW_CIE_ID
398 /* A pointer to the base of a table that contains frame description
399 information for each routine. */
400 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
402 /* Number of elements currently allocated for fde_table. */
403 static GTY(()) unsigned fde_table_allocated;
405 /* Number of elements in fde_table currently in use. */
406 static GTY(()) unsigned fde_table_in_use;
408 /* Size (in elements) of increments by which we may expand the
410 #define FDE_TABLE_INCREMENT 256
412 /* Get the current fde_table entry we should use. */
414 static inline dw_fde_ref
417 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
420 /* A list of call frame insns for the CIE. */
421 static GTY(()) dw_cfi_ref cie_cfi_head;
423 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
424 attribute that accelerates the lookup of the FDE associated
425 with the subprogram. This variable holds the table index of the FDE
426 associated with the current function (body) definition. */
427 static unsigned current_funcdef_fde;
429 struct GTY(()) indirect_string_node {
431 unsigned int refcount;
432 enum dwarf_form form;
436 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
438 /* True if the compilation unit has location entries that reference
440 static GTY(()) bool debug_str_hash_forced = false;
442 static GTY(()) int dw2_string_counter;
443 static GTY(()) unsigned long dwarf2out_cfi_label_num;
445 /* True if the compilation unit places functions in more than one section. */
446 static GTY(()) bool have_multiple_function_sections = false;
448 /* Whether the default text and cold text sections have been used at all. */
450 static GTY(()) bool text_section_used = false;
451 static GTY(()) bool cold_text_section_used = false;
453 /* The default cold text section. */
454 static GTY(()) section *cold_text_section;
456 /* Forward declarations for functions defined in this file. */
458 static char *stripattributes (const char *);
459 static const char *dwarf_cfi_name (unsigned);
460 static dw_cfi_ref new_cfi (void);
461 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
462 static void add_fde_cfi (const char *, dw_cfi_ref);
463 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
464 static void lookup_cfa (dw_cfa_location *);
465 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
466 static void initial_return_save (rtx);
467 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
469 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
470 static void output_cfi_directive (dw_cfi_ref);
471 static void output_call_frame_info (int);
472 static void dwarf2out_note_section_used (void);
473 static bool clobbers_queued_reg_save (const_rtx);
474 static void dwarf2out_frame_debug_expr (rtx, const char *);
476 /* Support for complex CFA locations. */
477 static void output_cfa_loc (dw_cfi_ref, int);
478 static void output_cfa_loc_raw (dw_cfi_ref);
479 static void get_cfa_from_loc_descr (dw_cfa_location *,
480 struct dw_loc_descr_struct *);
481 static struct dw_loc_descr_struct *build_cfa_loc
482 (dw_cfa_location *, HOST_WIDE_INT);
483 static struct dw_loc_descr_struct *build_cfa_aligned_loc
484 (HOST_WIDE_INT, HOST_WIDE_INT);
485 static void def_cfa_1 (const char *, dw_cfa_location *);
486 static struct dw_loc_descr_struct *mem_loc_descriptor
487 (rtx, enum machine_mode mode, enum var_init_status);
489 /* How to start an assembler comment. */
490 #ifndef ASM_COMMENT_START
491 #define ASM_COMMENT_START ";#"
494 /* Data and reference forms for relocatable data. */
495 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
496 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
498 #ifndef DEBUG_FRAME_SECTION
499 #define DEBUG_FRAME_SECTION ".debug_frame"
502 #ifndef FUNC_BEGIN_LABEL
503 #define FUNC_BEGIN_LABEL "LFB"
506 #ifndef FUNC_END_LABEL
507 #define FUNC_END_LABEL "LFE"
510 #ifndef PROLOGUE_END_LABEL
511 #define PROLOGUE_END_LABEL "LPE"
514 #ifndef EPILOGUE_BEGIN_LABEL
515 #define EPILOGUE_BEGIN_LABEL "LEB"
518 #ifndef FRAME_BEGIN_LABEL
519 #define FRAME_BEGIN_LABEL "Lframe"
521 #define CIE_AFTER_SIZE_LABEL "LSCIE"
522 #define CIE_END_LABEL "LECIE"
523 #define FDE_LABEL "LSFDE"
524 #define FDE_AFTER_SIZE_LABEL "LASFDE"
525 #define FDE_END_LABEL "LEFDE"
526 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
527 #define LINE_NUMBER_END_LABEL "LELT"
528 #define LN_PROLOG_AS_LABEL "LASLTP"
529 #define LN_PROLOG_END_LABEL "LELTP"
530 #define DIE_LABEL_PREFIX "DW"
532 /* The DWARF 2 CFA column which tracks the return address. Normally this
533 is the column for PC, or the first column after all of the hard
535 #ifndef DWARF_FRAME_RETURN_COLUMN
537 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
539 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
543 /* The mapping from gcc register number to DWARF 2 CFA column number. By
544 default, we just provide columns for all registers. */
545 #ifndef DWARF_FRAME_REGNUM
546 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
549 /* Match the base name of a file to the base name of a compilation unit. */
552 matches_main_base (const char *path)
554 /* Cache the last query. */
555 static const char *last_path = NULL;
556 static int last_match = 0;
557 if (path != last_path)
560 int length = base_of_path (path, &base);
562 last_match = (length == main_input_baselength
563 && memcmp (base, main_input_basename, length) == 0);
568 #ifdef DEBUG_DEBUG_STRUCT
571 dump_struct_debug (tree type, enum debug_info_usage usage,
572 enum debug_struct_file criterion, int generic,
573 int matches, int result)
575 /* Find the type name. */
576 tree type_decl = TYPE_STUB_DECL (type);
578 const char *name = 0;
579 if (TREE_CODE (t) == TYPE_DECL)
582 name = IDENTIFIER_POINTER (t);
584 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
586 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
587 matches ? "bas" : "hdr",
588 generic ? "gen" : "ord",
589 usage == DINFO_USAGE_DFN ? ";" :
590 usage == DINFO_USAGE_DIR_USE ? "." : "*",
592 (void*) type_decl, name);
595 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
596 dump_struct_debug (type, usage, criterion, generic, matches, result)
600 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
606 should_emit_struct_debug (tree type, enum debug_info_usage usage)
608 enum debug_struct_file criterion;
610 bool generic = lang_hooks.types.generic_p (type);
613 criterion = debug_struct_generic[usage];
615 criterion = debug_struct_ordinary[usage];
617 if (criterion == DINFO_STRUCT_FILE_NONE)
618 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
619 if (criterion == DINFO_STRUCT_FILE_ANY)
620 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
622 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
624 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
625 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
627 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
628 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
629 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
632 /* Hook used by __throw. */
635 expand_builtin_dwarf_sp_column (void)
637 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
638 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
641 /* Return a pointer to a copy of the section string name S with all
642 attributes stripped off, and an asterisk prepended (for assemble_name). */
645 stripattributes (const char *s)
647 char *stripped = XNEWVEC (char, strlen (s) + 2);
652 while (*s && *s != ',')
659 /* MEM is a memory reference for the register size table, each element of
660 which has mode MODE. Initialize column C as a return address column. */
663 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
665 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
666 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
667 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
670 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
672 static inline HOST_WIDE_INT
673 div_data_align (HOST_WIDE_INT off)
675 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
676 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
680 /* Return true if we need a signed version of a given opcode
681 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
684 need_data_align_sf_opcode (HOST_WIDE_INT off)
686 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
689 /* Generate code to initialize the register size table. */
692 expand_builtin_init_dwarf_reg_sizes (tree address)
695 enum machine_mode mode = TYPE_MODE (char_type_node);
696 rtx addr = expand_normal (address);
697 rtx mem = gen_rtx_MEM (BLKmode, addr);
698 bool wrote_return_column = false;
700 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
702 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
704 if (rnum < DWARF_FRAME_REGISTERS)
706 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
707 enum machine_mode save_mode = reg_raw_mode[i];
710 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
711 save_mode = choose_hard_reg_mode (i, 1, true);
712 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
714 if (save_mode == VOIDmode)
716 wrote_return_column = true;
718 size = GET_MODE_SIZE (save_mode);
722 emit_move_insn (adjust_address (mem, mode, offset),
723 gen_int_mode (size, mode));
727 if (!wrote_return_column)
728 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
730 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
731 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
734 targetm.init_dwarf_reg_sizes_extra (address);
737 /* Convert a DWARF call frame info. operation to its string name */
740 dwarf_cfi_name (unsigned int cfi_opc)
744 case DW_CFA_advance_loc:
745 return "DW_CFA_advance_loc";
747 return "DW_CFA_offset";
749 return "DW_CFA_restore";
753 return "DW_CFA_set_loc";
754 case DW_CFA_advance_loc1:
755 return "DW_CFA_advance_loc1";
756 case DW_CFA_advance_loc2:
757 return "DW_CFA_advance_loc2";
758 case DW_CFA_advance_loc4:
759 return "DW_CFA_advance_loc4";
760 case DW_CFA_offset_extended:
761 return "DW_CFA_offset_extended";
762 case DW_CFA_restore_extended:
763 return "DW_CFA_restore_extended";
764 case DW_CFA_undefined:
765 return "DW_CFA_undefined";
766 case DW_CFA_same_value:
767 return "DW_CFA_same_value";
768 case DW_CFA_register:
769 return "DW_CFA_register";
770 case DW_CFA_remember_state:
771 return "DW_CFA_remember_state";
772 case DW_CFA_restore_state:
773 return "DW_CFA_restore_state";
775 return "DW_CFA_def_cfa";
776 case DW_CFA_def_cfa_register:
777 return "DW_CFA_def_cfa_register";
778 case DW_CFA_def_cfa_offset:
779 return "DW_CFA_def_cfa_offset";
782 case DW_CFA_def_cfa_expression:
783 return "DW_CFA_def_cfa_expression";
784 case DW_CFA_expression:
785 return "DW_CFA_expression";
786 case DW_CFA_offset_extended_sf:
787 return "DW_CFA_offset_extended_sf";
788 case DW_CFA_def_cfa_sf:
789 return "DW_CFA_def_cfa_sf";
790 case DW_CFA_def_cfa_offset_sf:
791 return "DW_CFA_def_cfa_offset_sf";
793 /* SGI/MIPS specific */
794 case DW_CFA_MIPS_advance_loc8:
795 return "DW_CFA_MIPS_advance_loc8";
798 case DW_CFA_GNU_window_save:
799 return "DW_CFA_GNU_window_save";
800 case DW_CFA_GNU_args_size:
801 return "DW_CFA_GNU_args_size";
802 case DW_CFA_GNU_negative_offset_extended:
803 return "DW_CFA_GNU_negative_offset_extended";
806 return "DW_CFA_<unknown>";
810 /* Return a pointer to a newly allocated Call Frame Instruction. */
812 static inline dw_cfi_ref
815 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
817 cfi->dw_cfi_next = NULL;
818 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
819 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
824 /* Add a Call Frame Instruction to list of instructions. */
827 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
830 dw_fde_ref fde = current_fde ();
832 /* When DRAP is used, CFA is defined with an expression. Redefine
833 CFA may lead to a different CFA value. */
834 /* ??? Of course, this heuristic fails when we're annotating epilogues,
835 because of course we'll always want to redefine the CFA back to the
836 stack pointer on the way out. Where should we move this check? */
837 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
838 switch (cfi->dw_cfi_opc)
840 case DW_CFA_def_cfa_register:
841 case DW_CFA_def_cfa_offset:
842 case DW_CFA_def_cfa_offset_sf:
844 case DW_CFA_def_cfa_sf:
851 /* Find the end of the chain. */
852 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
858 /* Generate a new label for the CFI info to refer to. FORCE is true
859 if a label needs to be output even when using .cfi_* directives. */
862 dwarf2out_cfi_label (bool force)
864 static char label[20];
866 if (!force && dwarf2out_do_cfi_asm ())
868 /* In this case, we will be emitting the asm directive instead of
869 the label, so just return a placeholder to keep the rest of the
871 strcpy (label, "<do not output>");
875 int num = dwarf2out_cfi_label_num++;
876 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
877 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
883 /* True if remember_state should be emitted before following CFI directive. */
884 static bool emit_cfa_remember;
886 /* True if any CFI directives were emitted at the current insn. */
887 static bool any_cfis_emitted;
889 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
890 or to the CIE if LABEL is NULL. */
893 add_fde_cfi (const char *label, dw_cfi_ref cfi)
895 dw_cfi_ref *list_head;
897 if (emit_cfa_remember)
899 dw_cfi_ref cfi_remember;
901 /* Emit the state save. */
902 emit_cfa_remember = false;
903 cfi_remember = new_cfi ();
904 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
905 add_fde_cfi (label, cfi_remember);
908 list_head = &cie_cfi_head;
910 if (dwarf2out_do_cfi_asm ())
914 dw_fde_ref fde = current_fde ();
916 gcc_assert (fde != NULL);
918 /* We still have to add the cfi to the list so that lookup_cfa
919 works later on. When -g2 and above we even need to force
920 emitting of CFI labels and add to list a DW_CFA_set_loc for
921 convert_cfa_to_fb_loc_list purposes. If we're generating
922 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
923 convert_cfa_to_fb_loc_list. */
924 if (dwarf_version == 2
925 && debug_info_level > DINFO_LEVEL_TERSE
926 && (write_symbols == DWARF2_DEBUG
927 || write_symbols == VMS_AND_DWARF2_DEBUG))
929 switch (cfi->dw_cfi_opc)
931 case DW_CFA_def_cfa_offset:
932 case DW_CFA_def_cfa_offset_sf:
933 case DW_CFA_def_cfa_register:
935 case DW_CFA_def_cfa_sf:
936 case DW_CFA_def_cfa_expression:
937 case DW_CFA_restore_state:
938 if (*label == 0 || strcmp (label, "<do not output>") == 0)
939 label = dwarf2out_cfi_label (true);
941 if (fde->dw_fde_current_label == NULL
942 || strcmp (label, fde->dw_fde_current_label) != 0)
946 label = xstrdup (label);
948 /* Set the location counter to the new label. */
950 /* It doesn't metter whether DW_CFA_set_loc
951 or DW_CFA_advance_loc4 is added here, those aren't
952 emitted into assembly, only looked up by
953 convert_cfa_to_fb_loc_list. */
954 xcfi->dw_cfi_opc = DW_CFA_set_loc;
955 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
956 add_cfi (&fde->dw_fde_cfi, xcfi);
957 fde->dw_fde_current_label = label;
965 output_cfi_directive (cfi);
967 list_head = &fde->dw_fde_cfi;
968 any_cfis_emitted = true;
970 /* ??? If this is a CFI for the CIE, we don't emit. This
971 assumes that the standard CIE contents that the assembler
972 uses matches the standard CIE contents that the compiler
973 uses. This is probably a bad assumption. I'm not quite
974 sure how to address this for now. */
978 dw_fde_ref fde = current_fde ();
980 gcc_assert (fde != NULL);
983 label = dwarf2out_cfi_label (false);
985 if (fde->dw_fde_current_label == NULL
986 || strcmp (label, fde->dw_fde_current_label) != 0)
990 label = xstrdup (label);
992 /* Set the location counter to the new label. */
994 /* If we have a current label, advance from there, otherwise
995 set the location directly using set_loc. */
996 xcfi->dw_cfi_opc = fde->dw_fde_current_label
997 ? DW_CFA_advance_loc4
999 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
1000 add_cfi (&fde->dw_fde_cfi, xcfi);
1002 fde->dw_fde_current_label = label;
1005 list_head = &fde->dw_fde_cfi;
1006 any_cfis_emitted = true;
1009 add_cfi (list_head, cfi);
1012 /* Subroutine of lookup_cfa. */
1015 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1017 switch (cfi->dw_cfi_opc)
1019 case DW_CFA_def_cfa_offset:
1020 case DW_CFA_def_cfa_offset_sf:
1021 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1023 case DW_CFA_def_cfa_register:
1024 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1026 case DW_CFA_def_cfa:
1027 case DW_CFA_def_cfa_sf:
1028 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1029 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1031 case DW_CFA_def_cfa_expression:
1032 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1035 case DW_CFA_remember_state:
1036 gcc_assert (!remember->in_use);
1038 remember->in_use = 1;
1040 case DW_CFA_restore_state:
1041 gcc_assert (remember->in_use);
1043 remember->in_use = 0;
1051 /* Find the previous value for the CFA. */
1054 lookup_cfa (dw_cfa_location *loc)
1058 dw_cfa_location remember;
1060 memset (loc, 0, sizeof (*loc));
1061 loc->reg = INVALID_REGNUM;
1064 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1065 lookup_cfa_1 (cfi, loc, &remember);
1067 fde = current_fde ();
1069 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1070 lookup_cfa_1 (cfi, loc, &remember);
1073 /* The current rule for calculating the DWARF2 canonical frame address. */
1074 static dw_cfa_location cfa;
1076 /* The register used for saving registers to the stack, and its offset
1078 static dw_cfa_location cfa_store;
1080 /* The current save location around an epilogue. */
1081 static dw_cfa_location cfa_remember;
1083 /* The running total of the size of arguments pushed onto the stack. */
1084 static HOST_WIDE_INT args_size;
1086 /* The last args_size we actually output. */
1087 static HOST_WIDE_INT old_args_size;
1089 /* Entry point to update the canonical frame address (CFA).
1090 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1091 calculated from REG+OFFSET. */
1094 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1096 dw_cfa_location loc;
1098 loc.base_offset = 0;
1100 loc.offset = offset;
1101 def_cfa_1 (label, &loc);
1104 /* Determine if two dw_cfa_location structures define the same data. */
1107 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1109 return (loc1->reg == loc2->reg
1110 && loc1->offset == loc2->offset
1111 && loc1->indirect == loc2->indirect
1112 && (loc1->indirect == 0
1113 || loc1->base_offset == loc2->base_offset));
1116 /* This routine does the actual work. The CFA is now calculated from
1117 the dw_cfa_location structure. */
1120 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1123 dw_cfa_location old_cfa, loc;
1128 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1129 cfa_store.offset = loc.offset;
1131 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1132 lookup_cfa (&old_cfa);
1134 /* If nothing changed, no need to issue any call frame instructions. */
1135 if (cfa_equal_p (&loc, &old_cfa))
1140 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1142 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1143 the CFA register did not change but the offset did. The data
1144 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1145 in the assembler via the .cfi_def_cfa_offset directive. */
1147 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1149 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1150 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1153 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1154 else if (loc.offset == old_cfa.offset
1155 && old_cfa.reg != INVALID_REGNUM
1157 && !old_cfa.indirect)
1159 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1160 indicating the CFA register has changed to <register> but the
1161 offset has not changed. */
1162 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1163 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1167 else if (loc.indirect == 0)
1169 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1170 indicating the CFA register has changed to <register> with
1171 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1172 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1175 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1177 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1178 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1179 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1183 /* Construct a DW_CFA_def_cfa_expression instruction to
1184 calculate the CFA using a full location expression since no
1185 register-offset pair is available. */
1186 struct dw_loc_descr_struct *loc_list;
1188 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1189 loc_list = build_cfa_loc (&loc, 0);
1190 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1193 add_fde_cfi (label, cfi);
1196 /* Add the CFI for saving a register. REG is the CFA column number.
1197 LABEL is passed to add_fde_cfi.
1198 If SREG is -1, the register is saved at OFFSET from the CFA;
1199 otherwise it is saved in SREG. */
1202 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1204 dw_cfi_ref cfi = new_cfi ();
1205 dw_fde_ref fde = current_fde ();
1207 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1209 /* When stack is aligned, store REG using DW_CFA_expression with
1212 && fde->stack_realign
1213 && sreg == INVALID_REGNUM)
1215 cfi->dw_cfi_opc = DW_CFA_expression;
1216 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1217 cfi->dw_cfi_oprnd2.dw_cfi_loc
1218 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1220 else if (sreg == INVALID_REGNUM)
1222 if (need_data_align_sf_opcode (offset))
1223 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1224 else if (reg & ~0x3f)
1225 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1227 cfi->dw_cfi_opc = DW_CFA_offset;
1228 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1230 else if (sreg == reg)
1231 cfi->dw_cfi_opc = DW_CFA_same_value;
1234 cfi->dw_cfi_opc = DW_CFA_register;
1235 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1238 add_fde_cfi (label, cfi);
1241 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1242 This CFI tells the unwinder that it needs to restore the window registers
1243 from the previous frame's window save area.
1245 ??? Perhaps we should note in the CIE where windows are saved (instead of
1246 assuming 0(cfa)) and what registers are in the window. */
1249 dwarf2out_window_save (const char *label)
1251 dw_cfi_ref cfi = new_cfi ();
1253 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1254 add_fde_cfi (label, cfi);
1257 /* Entry point for saving a register to the stack. REG is the GCC register
1258 number. LABEL and OFFSET are passed to reg_save. */
1261 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1263 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1266 /* Entry point for saving the return address in the stack.
1267 LABEL and OFFSET are passed to reg_save. */
1270 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1272 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1275 /* Entry point for saving the return address in a register.
1276 LABEL and SREG are passed to reg_save. */
1279 dwarf2out_return_reg (const char *label, unsigned int sreg)
1281 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1284 /* Record the initial position of the return address. RTL is
1285 INCOMING_RETURN_ADDR_RTX. */
1288 initial_return_save (rtx rtl)
1290 unsigned int reg = INVALID_REGNUM;
1291 HOST_WIDE_INT offset = 0;
1293 switch (GET_CODE (rtl))
1296 /* RA is in a register. */
1297 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1301 /* RA is on the stack. */
1302 rtl = XEXP (rtl, 0);
1303 switch (GET_CODE (rtl))
1306 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1311 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1312 offset = INTVAL (XEXP (rtl, 1));
1316 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1317 offset = -INTVAL (XEXP (rtl, 1));
1327 /* The return address is at some offset from any value we can
1328 actually load. For instance, on the SPARC it is in %i7+8. Just
1329 ignore the offset for now; it doesn't matter for unwinding frames. */
1330 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1331 initial_return_save (XEXP (rtl, 0));
1338 if (reg != DWARF_FRAME_RETURN_COLUMN)
1339 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1342 /* Given a SET, calculate the amount of stack adjustment it
1345 static HOST_WIDE_INT
1346 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1347 HOST_WIDE_INT cur_offset)
1349 const_rtx src = SET_SRC (pattern);
1350 const_rtx dest = SET_DEST (pattern);
1351 HOST_WIDE_INT offset = 0;
1354 if (dest == stack_pointer_rtx)
1356 code = GET_CODE (src);
1358 /* Assume (set (reg sp) (reg whatever)) sets args_size
1360 if (code == REG && src != stack_pointer_rtx)
1362 offset = -cur_args_size;
1363 #ifndef STACK_GROWS_DOWNWARD
1366 return offset - cur_offset;
1369 if (! (code == PLUS || code == MINUS)
1370 || XEXP (src, 0) != stack_pointer_rtx
1371 || !CONST_INT_P (XEXP (src, 1)))
1374 /* (set (reg sp) (plus (reg sp) (const_int))) */
1375 offset = INTVAL (XEXP (src, 1));
1381 if (MEM_P (src) && !MEM_P (dest))
1385 /* (set (mem (pre_dec (reg sp))) (foo)) */
1386 src = XEXP (dest, 0);
1387 code = GET_CODE (src);
1393 if (XEXP (src, 0) == stack_pointer_rtx)
1395 rtx val = XEXP (XEXP (src, 1), 1);
1396 /* We handle only adjustments by constant amount. */
1397 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1398 && CONST_INT_P (val));
1399 offset = -INTVAL (val);
1406 if (XEXP (src, 0) == stack_pointer_rtx)
1408 offset = GET_MODE_SIZE (GET_MODE (dest));
1415 if (XEXP (src, 0) == stack_pointer_rtx)
1417 offset = -GET_MODE_SIZE (GET_MODE (dest));
1432 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1433 indexed by INSN_UID. */
1435 static HOST_WIDE_INT *barrier_args_size;
1437 /* Helper function for compute_barrier_args_size. Handle one insn. */
1439 static HOST_WIDE_INT
1440 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1441 VEC (rtx, heap) **next)
1443 HOST_WIDE_INT offset = 0;
1446 if (! RTX_FRAME_RELATED_P (insn))
1448 if (prologue_epilogue_contains (insn))
1450 else if (GET_CODE (PATTERN (insn)) == SET)
1451 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1452 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1453 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1455 /* There may be stack adjustments inside compound insns. Search
1457 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1458 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1459 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1460 cur_args_size, offset);
1465 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1469 expr = XEXP (expr, 0);
1470 if (GET_CODE (expr) == PARALLEL
1471 || GET_CODE (expr) == SEQUENCE)
1472 for (i = 1; i < XVECLEN (expr, 0); i++)
1474 rtx elem = XVECEXP (expr, 0, i);
1476 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1477 offset += stack_adjust_offset (elem, cur_args_size, offset);
1482 #ifndef STACK_GROWS_DOWNWARD
1486 cur_args_size += offset;
1487 if (cur_args_size < 0)
1492 rtx dest = JUMP_LABEL (insn);
1496 if (barrier_args_size [INSN_UID (dest)] < 0)
1498 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1499 VEC_safe_push (rtx, heap, *next, dest);
1504 return cur_args_size;
1507 /* Walk the whole function and compute args_size on BARRIERs. */
1510 compute_barrier_args_size (void)
1512 int max_uid = get_max_uid (), i;
1514 VEC (rtx, heap) *worklist, *next, *tmp;
1516 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1517 for (i = 0; i < max_uid; i++)
1518 barrier_args_size[i] = -1;
1520 worklist = VEC_alloc (rtx, heap, 20);
1521 next = VEC_alloc (rtx, heap, 20);
1522 insn = get_insns ();
1523 barrier_args_size[INSN_UID (insn)] = 0;
1524 VEC_quick_push (rtx, worklist, insn);
1527 while (!VEC_empty (rtx, worklist))
1529 rtx prev, body, first_insn;
1530 HOST_WIDE_INT cur_args_size;
1532 first_insn = insn = VEC_pop (rtx, worklist);
1533 cur_args_size = barrier_args_size[INSN_UID (insn)];
1534 prev = prev_nonnote_insn (insn);
1535 if (prev && BARRIER_P (prev))
1536 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1538 for (; insn; insn = NEXT_INSN (insn))
1540 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1542 if (BARRIER_P (insn))
1547 if (insn == first_insn)
1549 else if (barrier_args_size[INSN_UID (insn)] < 0)
1551 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1556 /* The insns starting with this label have been
1557 already scanned or are in the worklist. */
1562 body = PATTERN (insn);
1563 if (GET_CODE (body) == SEQUENCE)
1565 HOST_WIDE_INT dest_args_size = cur_args_size;
1566 for (i = 1; i < XVECLEN (body, 0); i++)
1567 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1568 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1570 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1571 dest_args_size, &next);
1574 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1575 cur_args_size, &next);
1577 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1578 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1579 dest_args_size, &next);
1582 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1583 cur_args_size, &next);
1587 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1591 if (VEC_empty (rtx, next))
1594 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1598 VEC_truncate (rtx, next, 0);
1601 VEC_free (rtx, heap, worklist);
1602 VEC_free (rtx, heap, next);
1605 /* Add a CFI to update the running total of the size of arguments
1606 pushed onto the stack. */
1609 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1613 if (size == old_args_size)
1616 old_args_size = size;
1619 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1620 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1621 add_fde_cfi (label, cfi);
1624 /* Record a stack adjustment of OFFSET bytes. */
1627 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1629 if (cfa.reg == STACK_POINTER_REGNUM)
1630 cfa.offset += offset;
1632 if (cfa_store.reg == STACK_POINTER_REGNUM)
1633 cfa_store.offset += offset;
1635 if (ACCUMULATE_OUTGOING_ARGS)
1638 #ifndef STACK_GROWS_DOWNWARD
1642 args_size += offset;
1646 def_cfa_1 (label, &cfa);
1647 if (flag_asynchronous_unwind_tables)
1648 dwarf2out_args_size (label, args_size);
1651 /* Check INSN to see if it looks like a push or a stack adjustment, and
1652 make a note of it if it does. EH uses this information to find out
1653 how much extra space it needs to pop off the stack. */
1656 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1658 HOST_WIDE_INT offset;
1662 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1663 with this function. Proper support would require all frame-related
1664 insns to be marked, and to be able to handle saving state around
1665 epilogues textually in the middle of the function. */
1666 if (prologue_epilogue_contains (insn))
1669 /* If INSN is an instruction from target of an annulled branch, the
1670 effects are for the target only and so current argument size
1671 shouldn't change at all. */
1673 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1674 && INSN_FROM_TARGET_P (insn))
1677 /* If only calls can throw, and we have a frame pointer,
1678 save up adjustments until we see the CALL_INSN. */
1679 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1681 if (CALL_P (insn) && !after_p)
1683 /* Extract the size of the args from the CALL rtx itself. */
1684 insn = PATTERN (insn);
1685 if (GET_CODE (insn) == PARALLEL)
1686 insn = XVECEXP (insn, 0, 0);
1687 if (GET_CODE (insn) == SET)
1688 insn = SET_SRC (insn);
1689 gcc_assert (GET_CODE (insn) == CALL);
1690 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1695 if (CALL_P (insn) && !after_p)
1697 if (!flag_asynchronous_unwind_tables)
1698 dwarf2out_args_size ("", args_size);
1701 else if (BARRIER_P (insn))
1703 /* Don't call compute_barrier_args_size () if the only
1704 BARRIER is at the end of function. */
1705 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1706 compute_barrier_args_size ();
1707 if (barrier_args_size == NULL)
1711 offset = barrier_args_size[INSN_UID (insn)];
1716 offset -= args_size;
1717 #ifndef STACK_GROWS_DOWNWARD
1721 else if (GET_CODE (PATTERN (insn)) == SET)
1722 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1723 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1724 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1726 /* There may be stack adjustments inside compound insns. Search
1728 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1729 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1730 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1739 label = dwarf2out_cfi_label (false);
1740 dwarf2out_stack_adjust (offset, label);
1743 /* We delay emitting a register save until either (a) we reach the end
1744 of the prologue or (b) the register is clobbered. This clusters
1745 register saves so that there are fewer pc advances. */
1747 struct GTY(()) queued_reg_save {
1748 struct queued_reg_save *next;
1750 HOST_WIDE_INT cfa_offset;
1754 static GTY(()) struct queued_reg_save *queued_reg_saves;
1756 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1757 struct GTY(()) reg_saved_in_data {
1762 /* A list of registers saved in other registers.
1763 The list intentionally has a small maximum capacity of 4; if your
1764 port needs more than that, you might consider implementing a
1765 more efficient data structure. */
1766 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1767 static GTY(()) size_t num_regs_saved_in_regs;
1769 static const char *last_reg_save_label;
1771 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1772 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1775 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1777 struct queued_reg_save *q;
1779 /* Duplicates waste space, but it's also necessary to remove them
1780 for correctness, since the queue gets output in reverse
1782 for (q = queued_reg_saves; q != NULL; q = q->next)
1783 if (REGNO (q->reg) == REGNO (reg))
1788 q = ggc_alloc_queued_reg_save ();
1789 q->next = queued_reg_saves;
1790 queued_reg_saves = q;
1794 q->cfa_offset = offset;
1795 q->saved_reg = sreg;
1797 last_reg_save_label = label;
1800 /* Output all the entries in QUEUED_REG_SAVES. */
1803 dwarf2out_flush_queued_reg_saves (void)
1805 struct queued_reg_save *q;
1807 for (q = queued_reg_saves; q; q = q->next)
1810 unsigned int reg, sreg;
1812 for (i = 0; i < num_regs_saved_in_regs; i++)
1813 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1815 if (q->saved_reg && i == num_regs_saved_in_regs)
1817 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1818 num_regs_saved_in_regs++;
1820 if (i != num_regs_saved_in_regs)
1822 regs_saved_in_regs[i].orig_reg = q->reg;
1823 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1826 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1828 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1830 sreg = INVALID_REGNUM;
1831 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1834 queued_reg_saves = NULL;
1835 last_reg_save_label = NULL;
1838 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1839 location for? Or, does it clobber a register which we've previously
1840 said that some other register is saved in, and for which we now
1841 have a new location for? */
1844 clobbers_queued_reg_save (const_rtx insn)
1846 struct queued_reg_save *q;
1848 for (q = queued_reg_saves; q; q = q->next)
1851 if (modified_in_p (q->reg, insn))
1853 for (i = 0; i < num_regs_saved_in_regs; i++)
1854 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1855 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1862 /* Entry point for saving the first register into the second. */
1865 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1868 unsigned int regno, sregno;
1870 for (i = 0; i < num_regs_saved_in_regs; i++)
1871 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1873 if (i == num_regs_saved_in_regs)
1875 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1876 num_regs_saved_in_regs++;
1878 regs_saved_in_regs[i].orig_reg = reg;
1879 regs_saved_in_regs[i].saved_in_reg = sreg;
1881 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1882 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1883 reg_save (label, regno, sregno, 0);
1886 /* What register, if any, is currently saved in REG? */
1889 reg_saved_in (rtx reg)
1891 unsigned int regn = REGNO (reg);
1893 struct queued_reg_save *q;
1895 for (q = queued_reg_saves; q; q = q->next)
1896 if (q->saved_reg && regn == REGNO (q->saved_reg))
1899 for (i = 0; i < num_regs_saved_in_regs; i++)
1900 if (regs_saved_in_regs[i].saved_in_reg
1901 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1902 return regs_saved_in_regs[i].orig_reg;
1908 /* A temporary register holding an integral value used in adjusting SP
1909 or setting up the store_reg. The "offset" field holds the integer
1910 value, not an offset. */
1911 static dw_cfa_location cfa_temp;
1913 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1916 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1918 memset (&cfa, 0, sizeof (cfa));
1920 switch (GET_CODE (pat))
1923 cfa.reg = REGNO (XEXP (pat, 0));
1924 cfa.offset = INTVAL (XEXP (pat, 1));
1928 cfa.reg = REGNO (pat);
1933 pat = XEXP (pat, 0);
1934 if (GET_CODE (pat) == PLUS)
1936 cfa.base_offset = INTVAL (XEXP (pat, 1));
1937 pat = XEXP (pat, 0);
1939 cfa.reg = REGNO (pat);
1943 /* Recurse and define an expression. */
1947 def_cfa_1 (label, &cfa);
1950 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1953 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1957 gcc_assert (GET_CODE (pat) == SET);
1958 dest = XEXP (pat, 0);
1959 src = XEXP (pat, 1);
1961 switch (GET_CODE (src))
1964 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1965 cfa.offset -= INTVAL (XEXP (src, 1));
1975 cfa.reg = REGNO (dest);
1976 gcc_assert (cfa.indirect == 0);
1978 def_cfa_1 (label, &cfa);
1981 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1984 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1986 HOST_WIDE_INT offset;
1987 rtx src, addr, span;
1989 src = XEXP (set, 1);
1990 addr = XEXP (set, 0);
1991 gcc_assert (MEM_P (addr));
1992 addr = XEXP (addr, 0);
1994 /* As documented, only consider extremely simple addresses. */
1995 switch (GET_CODE (addr))
1998 gcc_assert (REGNO (addr) == cfa.reg);
1999 offset = -cfa.offset;
2002 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
2003 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2009 span = targetm.dwarf_register_span (src);
2011 /* ??? We'd like to use queue_reg_save, but we need to come up with
2012 a different flushing heuristic for epilogues. */
2014 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2017 /* We have a PARALLEL describing where the contents of SRC live.
2018 Queue register saves for each piece of the PARALLEL. */
2021 HOST_WIDE_INT span_offset = offset;
2023 gcc_assert (GET_CODE (span) == PARALLEL);
2025 limit = XVECLEN (span, 0);
2026 for (par_index = 0; par_index < limit; par_index++)
2028 rtx elem = XVECEXP (span, 0, par_index);
2030 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2031 INVALID_REGNUM, span_offset);
2032 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2037 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2040 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2043 unsigned sregno, dregno;
2045 src = XEXP (set, 1);
2046 dest = XEXP (set, 0);
2049 sregno = DWARF_FRAME_RETURN_COLUMN;
2051 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2053 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2055 /* ??? We'd like to use queue_reg_save, but we need to come up with
2056 a different flushing heuristic for epilogues. */
2057 reg_save (label, sregno, dregno, 0);
2060 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2063 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2065 rtx src, dest, span;
2066 dw_cfi_ref cfi = new_cfi ();
2068 dest = SET_DEST (set);
2069 src = SET_SRC (set);
2071 gcc_assert (REG_P (src));
2072 gcc_assert (MEM_P (dest));
2074 span = targetm.dwarf_register_span (src);
2077 cfi->dw_cfi_opc = DW_CFA_expression;
2078 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2079 cfi->dw_cfi_oprnd2.dw_cfi_loc
2080 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2081 VAR_INIT_STATUS_INITIALIZED);
2083 /* ??? We'd like to use queue_reg_save, were the interface different,
2084 and, as above, we could manage flushing for epilogues. */
2085 add_fde_cfi (label, cfi);
2088 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2091 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2093 dw_cfi_ref cfi = new_cfi ();
2094 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2096 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2097 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2099 add_fde_cfi (label, cfi);
2102 /* Record call frame debugging information for an expression EXPR,
2103 which either sets SP or FP (adjusting how we calculate the frame
2104 address) or saves a register to the stack or another register.
2105 LABEL indicates the address of EXPR.
2107 This function encodes a state machine mapping rtxes to actions on
2108 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2109 users need not read the source code.
2111 The High-Level Picture
2113 Changes in the register we use to calculate the CFA: Currently we
2114 assume that if you copy the CFA register into another register, we
2115 should take the other one as the new CFA register; this seems to
2116 work pretty well. If it's wrong for some target, it's simple
2117 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2119 Changes in the register we use for saving registers to the stack:
2120 This is usually SP, but not always. Again, we deduce that if you
2121 copy SP into another register (and SP is not the CFA register),
2122 then the new register is the one we will be using for register
2123 saves. This also seems to work.
2125 Register saves: There's not much guesswork about this one; if
2126 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2127 register save, and the register used to calculate the destination
2128 had better be the one we think we're using for this purpose.
2129 It's also assumed that a copy from a call-saved register to another
2130 register is saving that register if RTX_FRAME_RELATED_P is set on
2131 that instruction. If the copy is from a call-saved register to
2132 the *same* register, that means that the register is now the same
2133 value as in the caller.
2135 Except: If the register being saved is the CFA register, and the
2136 offset is nonzero, we are saving the CFA, so we assume we have to
2137 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2138 the intent is to save the value of SP from the previous frame.
2140 In addition, if a register has previously been saved to a different
2143 Invariants / Summaries of Rules
2145 cfa current rule for calculating the CFA. It usually
2146 consists of a register and an offset.
2147 cfa_store register used by prologue code to save things to the stack
2148 cfa_store.offset is the offset from the value of
2149 cfa_store.reg to the actual CFA
2150 cfa_temp register holding an integral value. cfa_temp.offset
2151 stores the value, which will be used to adjust the
2152 stack pointer. cfa_temp is also used like cfa_store,
2153 to track stores to the stack via fp or a temp reg.
2155 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2156 with cfa.reg as the first operand changes the cfa.reg and its
2157 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2160 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2161 expression yielding a constant. This sets cfa_temp.reg
2162 and cfa_temp.offset.
2164 Rule 5: Create a new register cfa_store used to save items to the
2167 Rules 10-14: Save a register to the stack. Define offset as the
2168 difference of the original location and cfa_store's
2169 location (or cfa_temp's location if cfa_temp is used).
2171 Rules 16-20: If AND operation happens on sp in prologue, we assume
2172 stack is realigned. We will use a group of DW_OP_XXX
2173 expressions to represent the location of the stored
2174 register instead of CFA+offset.
2178 "{a,b}" indicates a choice of a xor b.
2179 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2182 (set <reg1> <reg2>:cfa.reg)
2183 effects: cfa.reg = <reg1>
2184 cfa.offset unchanged
2185 cfa_temp.reg = <reg1>
2186 cfa_temp.offset = cfa.offset
2189 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2190 {<const_int>,<reg>:cfa_temp.reg}))
2191 effects: cfa.reg = sp if fp used
2192 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2193 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2194 if cfa_store.reg==sp
2197 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2198 effects: cfa.reg = fp
2199 cfa_offset += +/- <const_int>
2202 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2203 constraints: <reg1> != fp
2205 effects: cfa.reg = <reg1>
2206 cfa_temp.reg = <reg1>
2207 cfa_temp.offset = cfa.offset
2210 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2211 constraints: <reg1> != fp
2213 effects: cfa_store.reg = <reg1>
2214 cfa_store.offset = cfa.offset - cfa_temp.offset
2217 (set <reg> <const_int>)
2218 effects: cfa_temp.reg = <reg>
2219 cfa_temp.offset = <const_int>
2222 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2223 effects: cfa_temp.reg = <reg1>
2224 cfa_temp.offset |= <const_int>
2227 (set <reg> (high <exp>))
2231 (set <reg> (lo_sum <exp> <const_int>))
2232 effects: cfa_temp.reg = <reg>
2233 cfa_temp.offset = <const_int>
2236 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2237 effects: cfa_store.offset -= <const_int>
2238 cfa.offset = cfa_store.offset if cfa.reg == sp
2240 cfa.base_offset = -cfa_store.offset
2243 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2244 effects: cfa_store.offset += -/+ mode_size(mem)
2245 cfa.offset = cfa_store.offset if cfa.reg == sp
2247 cfa.base_offset = -cfa_store.offset
2250 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2253 effects: cfa.reg = <reg1>
2254 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2257 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2258 effects: cfa.reg = <reg1>
2259 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2262 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2263 effects: cfa.reg = <reg1>
2264 cfa.base_offset = -cfa_temp.offset
2265 cfa_temp.offset -= mode_size(mem)
2268 (set <reg> {unspec, unspec_volatile})
2269 effects: target-dependent
2272 (set sp (and: sp <const_int>))
2273 constraints: cfa_store.reg == sp
2274 effects: current_fde.stack_realign = 1
2275 cfa_store.offset = 0
2276 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2279 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2280 effects: cfa_store.offset += -/+ mode_size(mem)
2283 (set (mem ({pre_inc, pre_dec} sp)) fp)
2284 constraints: fde->stack_realign == 1
2285 effects: cfa_store.offset = 0
2286 cfa.reg != HARD_FRAME_POINTER_REGNUM
2289 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2290 constraints: fde->stack_realign == 1
2292 && cfa.indirect == 0
2293 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2294 effects: Use DW_CFA_def_cfa_expression to define cfa
2295 cfa.reg == fde->drap_reg */
2298 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2300 rtx src, dest, span;
2301 HOST_WIDE_INT offset;
2304 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2305 the PARALLEL independently. The first element is always processed if
2306 it is a SET. This is for backward compatibility. Other elements
2307 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2308 flag is set in them. */
2309 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2312 int limit = XVECLEN (expr, 0);
2315 /* PARALLELs have strict read-modify-write semantics, so we
2316 ought to evaluate every rvalue before changing any lvalue.
2317 It's cumbersome to do that in general, but there's an
2318 easy approximation that is enough for all current users:
2319 handle register saves before register assignments. */
2320 if (GET_CODE (expr) == PARALLEL)
2321 for (par_index = 0; par_index < limit; par_index++)
2323 elem = XVECEXP (expr, 0, par_index);
2324 if (GET_CODE (elem) == SET
2325 && MEM_P (SET_DEST (elem))
2326 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2327 dwarf2out_frame_debug_expr (elem, label);
2330 for (par_index = 0; par_index < limit; par_index++)
2332 elem = XVECEXP (expr, 0, par_index);
2333 if (GET_CODE (elem) == SET
2334 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2335 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2336 dwarf2out_frame_debug_expr (elem, label);
2337 else if (GET_CODE (elem) == SET
2339 && !RTX_FRAME_RELATED_P (elem))
2341 /* Stack adjustment combining might combine some post-prologue
2342 stack adjustment into a prologue stack adjustment. */
2343 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2346 dwarf2out_stack_adjust (offset, label);
2352 gcc_assert (GET_CODE (expr) == SET);
2354 src = SET_SRC (expr);
2355 dest = SET_DEST (expr);
2359 rtx rsi = reg_saved_in (src);
2364 fde = current_fde ();
2366 switch (GET_CODE (dest))
2369 switch (GET_CODE (src))
2371 /* Setting FP from SP. */
2373 if (cfa.reg == (unsigned) REGNO (src))
2376 /* Update the CFA rule wrt SP or FP. Make sure src is
2377 relative to the current CFA register.
2379 We used to require that dest be either SP or FP, but the
2380 ARM copies SP to a temporary register, and from there to
2381 FP. So we just rely on the backends to only set
2382 RTX_FRAME_RELATED_P on appropriate insns. */
2383 cfa.reg = REGNO (dest);
2384 cfa_temp.reg = cfa.reg;
2385 cfa_temp.offset = cfa.offset;
2389 /* Saving a register in a register. */
2390 gcc_assert (!fixed_regs [REGNO (dest)]
2391 /* For the SPARC and its register window. */
2392 || (DWARF_FRAME_REGNUM (REGNO (src))
2393 == DWARF_FRAME_RETURN_COLUMN));
2395 /* After stack is aligned, we can only save SP in FP
2396 if drap register is used. In this case, we have
2397 to restore stack pointer with the CFA value and we
2398 don't generate this DWARF information. */
2400 && fde->stack_realign
2401 && REGNO (src) == STACK_POINTER_REGNUM)
2402 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2403 && fde->drap_reg != INVALID_REGNUM
2404 && cfa.reg != REGNO (src));
2406 queue_reg_save (label, src, dest, 0);
2413 if (dest == stack_pointer_rtx)
2417 switch (GET_CODE (XEXP (src, 1)))
2420 offset = INTVAL (XEXP (src, 1));
2423 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2425 offset = cfa_temp.offset;
2431 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2433 /* Restoring SP from FP in the epilogue. */
2434 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2435 cfa.reg = STACK_POINTER_REGNUM;
2437 else if (GET_CODE (src) == LO_SUM)
2438 /* Assume we've set the source reg of the LO_SUM from sp. */
2441 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2443 if (GET_CODE (src) != MINUS)
2445 if (cfa.reg == STACK_POINTER_REGNUM)
2446 cfa.offset += offset;
2447 if (cfa_store.reg == STACK_POINTER_REGNUM)
2448 cfa_store.offset += offset;
2450 else if (dest == hard_frame_pointer_rtx)
2453 /* Either setting the FP from an offset of the SP,
2454 or adjusting the FP */
2455 gcc_assert (frame_pointer_needed);
2457 gcc_assert (REG_P (XEXP (src, 0))
2458 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2459 && CONST_INT_P (XEXP (src, 1)));
2460 offset = INTVAL (XEXP (src, 1));
2461 if (GET_CODE (src) != MINUS)
2463 cfa.offset += offset;
2464 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2468 gcc_assert (GET_CODE (src) != MINUS);
2471 if (REG_P (XEXP (src, 0))
2472 && REGNO (XEXP (src, 0)) == cfa.reg
2473 && CONST_INT_P (XEXP (src, 1)))
2475 /* Setting a temporary CFA register that will be copied
2476 into the FP later on. */
2477 offset = - INTVAL (XEXP (src, 1));
2478 cfa.offset += offset;
2479 cfa.reg = REGNO (dest);
2480 /* Or used to save regs to the stack. */
2481 cfa_temp.reg = cfa.reg;
2482 cfa_temp.offset = cfa.offset;
2486 else if (REG_P (XEXP (src, 0))
2487 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2488 && XEXP (src, 1) == stack_pointer_rtx)
2490 /* Setting a scratch register that we will use instead
2491 of SP for saving registers to the stack. */
2492 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2493 cfa_store.reg = REGNO (dest);
2494 cfa_store.offset = cfa.offset - cfa_temp.offset;
2498 else if (GET_CODE (src) == LO_SUM
2499 && CONST_INT_P (XEXP (src, 1)))
2501 cfa_temp.reg = REGNO (dest);
2502 cfa_temp.offset = INTVAL (XEXP (src, 1));
2511 cfa_temp.reg = REGNO (dest);
2512 cfa_temp.offset = INTVAL (src);
2517 gcc_assert (REG_P (XEXP (src, 0))
2518 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2519 && CONST_INT_P (XEXP (src, 1)));
2521 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2522 cfa_temp.reg = REGNO (dest);
2523 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2526 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2527 which will fill in all of the bits. */
2534 case UNSPEC_VOLATILE:
2535 gcc_assert (targetm.dwarf_handle_frame_unspec);
2536 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2541 /* If this AND operation happens on stack pointer in prologue,
2542 we assume the stack is realigned and we extract the
2544 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2546 /* We interpret reg_save differently with stack_realign set.
2547 Thus we must flush whatever we have queued first. */
2548 dwarf2out_flush_queued_reg_saves ();
2550 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2551 fde->stack_realign = 1;
2552 fde->stack_realignment = INTVAL (XEXP (src, 1));
2553 cfa_store.offset = 0;
2555 if (cfa.reg != STACK_POINTER_REGNUM
2556 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2557 fde->drap_reg = cfa.reg;
2565 def_cfa_1 (label, &cfa);
2570 /* Saving a register to the stack. Make sure dest is relative to the
2572 switch (GET_CODE (XEXP (dest, 0)))
2577 /* We can't handle variable size modifications. */
2578 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2580 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2582 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2583 && cfa_store.reg == STACK_POINTER_REGNUM);
2585 cfa_store.offset += offset;
2586 if (cfa.reg == STACK_POINTER_REGNUM)
2587 cfa.offset = cfa_store.offset;
2589 offset = -cfa_store.offset;
2595 offset = GET_MODE_SIZE (GET_MODE (dest));
2596 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2599 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2600 == STACK_POINTER_REGNUM)
2601 && cfa_store.reg == STACK_POINTER_REGNUM);
2603 cfa_store.offset += offset;
2605 /* Rule 18: If stack is aligned, we will use FP as a
2606 reference to represent the address of the stored
2609 && fde->stack_realign
2610 && src == hard_frame_pointer_rtx)
2612 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2613 cfa_store.offset = 0;
2616 if (cfa.reg == STACK_POINTER_REGNUM)
2617 cfa.offset = cfa_store.offset;
2619 offset = -cfa_store.offset;
2623 /* With an offset. */
2630 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2631 && REG_P (XEXP (XEXP (dest, 0), 0)));
2632 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2633 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2636 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2638 if (cfa.reg == (unsigned) regno)
2639 offset -= cfa.offset;
2640 else if (cfa_store.reg == (unsigned) regno)
2641 offset -= cfa_store.offset;
2644 gcc_assert (cfa_temp.reg == (unsigned) regno);
2645 offset -= cfa_temp.offset;
2651 /* Without an offset. */
2654 int regno = REGNO (XEXP (dest, 0));
2656 if (cfa.reg == (unsigned) regno)
2657 offset = -cfa.offset;
2658 else if (cfa_store.reg == (unsigned) regno)
2659 offset = -cfa_store.offset;
2662 gcc_assert (cfa_temp.reg == (unsigned) regno);
2663 offset = -cfa_temp.offset;
2670 gcc_assert (cfa_temp.reg
2671 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2672 offset = -cfa_temp.offset;
2673 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2681 /* If the source operand of this MEM operation is not a
2682 register, basically the source is return address. Here
2683 we only care how much stack grew and we don't save it. */
2687 if (REGNO (src) != STACK_POINTER_REGNUM
2688 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2689 && (unsigned) REGNO (src) == cfa.reg)
2691 /* We're storing the current CFA reg into the stack. */
2693 if (cfa.offset == 0)
2696 /* If stack is aligned, putting CFA reg into stack means
2697 we can no longer use reg + offset to represent CFA.
2698 Here we use DW_CFA_def_cfa_expression instead. The
2699 result of this expression equals to the original CFA
2702 && fde->stack_realign
2703 && cfa.indirect == 0
2704 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2706 dw_cfa_location cfa_exp;
2708 gcc_assert (fde->drap_reg == cfa.reg);
2710 cfa_exp.indirect = 1;
2711 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2712 cfa_exp.base_offset = offset;
2715 fde->drap_reg_saved = 1;
2717 def_cfa_1 (label, &cfa_exp);
2721 /* If the source register is exactly the CFA, assume
2722 we're saving SP like any other register; this happens
2724 def_cfa_1 (label, &cfa);
2725 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2730 /* Otherwise, we'll need to look in the stack to
2731 calculate the CFA. */
2732 rtx x = XEXP (dest, 0);
2736 gcc_assert (REG_P (x));
2738 cfa.reg = REGNO (x);
2739 cfa.base_offset = offset;
2741 def_cfa_1 (label, &cfa);
2746 def_cfa_1 (label, &cfa);
2748 span = targetm.dwarf_register_span (src);
2751 queue_reg_save (label, src, NULL_RTX, offset);
2754 /* We have a PARALLEL describing where the contents of SRC
2755 live. Queue register saves for each piece of the
2759 HOST_WIDE_INT span_offset = offset;
2761 gcc_assert (GET_CODE (span) == PARALLEL);
2763 limit = XVECLEN (span, 0);
2764 for (par_index = 0; par_index < limit; par_index++)
2766 rtx elem = XVECEXP (span, 0, par_index);
2768 queue_reg_save (label, elem, NULL_RTX, span_offset);
2769 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2780 /* Record call frame debugging information for INSN, which either
2781 sets SP or FP (adjusting how we calculate the frame address) or saves a
2782 register to the stack. If INSN is NULL_RTX, initialize our state.
2784 If AFTER_P is false, we're being called before the insn is emitted,
2785 otherwise after. Call instructions get invoked twice. */
2788 dwarf2out_frame_debug (rtx insn, bool after_p)
2792 bool handled_one = false;
2794 if (insn == NULL_RTX)
2798 /* Flush any queued register saves. */
2799 dwarf2out_flush_queued_reg_saves ();
2801 /* Set up state for generating call frame debug info. */
2804 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2806 cfa.reg = STACK_POINTER_REGNUM;
2809 cfa_temp.offset = 0;
2811 for (i = 0; i < num_regs_saved_in_regs; i++)
2813 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2814 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2816 num_regs_saved_in_regs = 0;
2818 if (barrier_args_size)
2820 XDELETEVEC (barrier_args_size);
2821 barrier_args_size = NULL;
2826 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2827 dwarf2out_flush_queued_reg_saves ();
2829 if (!RTX_FRAME_RELATED_P (insn))
2831 /* ??? This should be done unconditionally since stack adjustments
2832 matter if the stack pointer is not the CFA register anymore but
2833 is still used to save registers. */
2834 if (!ACCUMULATE_OUTGOING_ARGS)
2835 dwarf2out_notice_stack_adjust (insn, after_p);
2839 label = dwarf2out_cfi_label (false);
2840 any_cfis_emitted = false;
2842 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2843 switch (REG_NOTE_KIND (note))
2845 case REG_FRAME_RELATED_EXPR:
2846 insn = XEXP (note, 0);
2849 case REG_CFA_DEF_CFA:
2850 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2854 case REG_CFA_ADJUST_CFA:
2859 if (GET_CODE (n) == PARALLEL)
2860 n = XVECEXP (n, 0, 0);
2862 dwarf2out_frame_debug_adjust_cfa (n, label);
2866 case REG_CFA_OFFSET:
2869 n = single_set (insn);
2870 dwarf2out_frame_debug_cfa_offset (n, label);
2874 case REG_CFA_REGISTER:
2879 if (GET_CODE (n) == PARALLEL)
2880 n = XVECEXP (n, 0, 0);
2882 dwarf2out_frame_debug_cfa_register (n, label);
2886 case REG_CFA_EXPRESSION:
2889 n = single_set (insn);
2890 dwarf2out_frame_debug_cfa_expression (n, label);
2894 case REG_CFA_RESTORE:
2899 if (GET_CODE (n) == PARALLEL)
2900 n = XVECEXP (n, 0, 0);
2903 dwarf2out_frame_debug_cfa_restore (n, label);
2907 case REG_CFA_SET_VDRAP:
2911 dw_fde_ref fde = current_fde ();
2914 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2916 fde->vdrap_reg = REGNO (n);
2927 if (any_cfis_emitted)
2928 dwarf2out_flush_queued_reg_saves ();
2932 insn = PATTERN (insn);
2934 dwarf2out_frame_debug_expr (insn, label);
2936 /* Check again. A parallel can save and update the same register.
2937 We could probably check just once, here, but this is safer than
2938 removing the check above. */
2939 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2940 dwarf2out_flush_queued_reg_saves ();
2943 /* Determine if we need to save and restore CFI information around this
2944 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2945 we do need to save/restore, then emit the save now, and insert a
2946 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2949 dwarf2out_cfi_begin_epilogue (rtx insn)
2951 bool saw_frp = false;
2954 /* Scan forward to the return insn, noticing if there are possible
2955 frame related insns. */
2956 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2961 /* Look for both regular and sibcalls to end the block. */
2962 if (returnjump_p (i))
2964 if (CALL_P (i) && SIBLING_CALL_P (i))
2967 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2970 rtx seq = PATTERN (i);
2972 if (returnjump_p (XVECEXP (seq, 0, 0)))
2974 if (CALL_P (XVECEXP (seq, 0, 0))
2975 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2978 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2979 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2983 if (RTX_FRAME_RELATED_P (i))
2987 /* If the port doesn't emit epilogue unwind info, we don't need a
2988 save/restore pair. */
2992 /* Otherwise, search forward to see if the return insn was the last
2993 basic block of the function. If so, we don't need save/restore. */
2994 gcc_assert (i != NULL);
2995 i = next_real_insn (i);
2999 /* Insert the restore before that next real insn in the stream, and before
3000 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3001 properly nested. This should be after any label or alignment. This
3002 will be pushed into the CFI stream by the function below. */
3005 rtx p = PREV_INSN (i);
3008 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3012 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3014 emit_cfa_remember = true;
3016 /* And emulate the state save. */
3017 gcc_assert (!cfa_remember.in_use);
3019 cfa_remember.in_use = 1;
3022 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3026 dwarf2out_frame_debug_restore_state (void)
3028 dw_cfi_ref cfi = new_cfi ();
3029 const char *label = dwarf2out_cfi_label (false);
3031 cfi->dw_cfi_opc = DW_CFA_restore_state;
3032 add_fde_cfi (label, cfi);
3034 gcc_assert (cfa_remember.in_use);
3036 cfa_remember.in_use = 0;
3039 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3040 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3041 (enum dwarf_call_frame_info cfi);
3043 static enum dw_cfi_oprnd_type
3044 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3049 case DW_CFA_GNU_window_save:
3050 case DW_CFA_remember_state:
3051 case DW_CFA_restore_state:
3052 return dw_cfi_oprnd_unused;
3054 case DW_CFA_set_loc:
3055 case DW_CFA_advance_loc1:
3056 case DW_CFA_advance_loc2:
3057 case DW_CFA_advance_loc4:
3058 case DW_CFA_MIPS_advance_loc8:
3059 return dw_cfi_oprnd_addr;
3062 case DW_CFA_offset_extended:
3063 case DW_CFA_def_cfa:
3064 case DW_CFA_offset_extended_sf:
3065 case DW_CFA_def_cfa_sf:
3066 case DW_CFA_restore:
3067 case DW_CFA_restore_extended:
3068 case DW_CFA_undefined:
3069 case DW_CFA_same_value:
3070 case DW_CFA_def_cfa_register:
3071 case DW_CFA_register:
3072 case DW_CFA_expression:
3073 return dw_cfi_oprnd_reg_num;
3075 case DW_CFA_def_cfa_offset:
3076 case DW_CFA_GNU_args_size:
3077 case DW_CFA_def_cfa_offset_sf:
3078 return dw_cfi_oprnd_offset;
3080 case DW_CFA_def_cfa_expression:
3081 return dw_cfi_oprnd_loc;
3088 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3089 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3090 (enum dwarf_call_frame_info cfi);
3092 static enum dw_cfi_oprnd_type
3093 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3097 case DW_CFA_def_cfa:
3098 case DW_CFA_def_cfa_sf:
3100 case DW_CFA_offset_extended_sf:
3101 case DW_CFA_offset_extended:
3102 return dw_cfi_oprnd_offset;
3104 case DW_CFA_register:
3105 return dw_cfi_oprnd_reg_num;
3107 case DW_CFA_expression:
3108 return dw_cfi_oprnd_loc;
3111 return dw_cfi_oprnd_unused;
3115 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3116 switch to the data section instead, and write out a synthetic start label
3117 for collect2 the first time around. */
3120 switch_to_eh_frame_section (bool back)
3124 #ifdef EH_FRAME_SECTION_NAME
3125 if (eh_frame_section == 0)
3129 if (EH_TABLES_CAN_BE_READ_ONLY)
3135 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3137 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3139 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3141 flags = ((! flag_pic
3142 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3143 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3144 && (per_encoding & 0x70) != DW_EH_PE_absptr
3145 && (per_encoding & 0x70) != DW_EH_PE_aligned
3146 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3147 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3148 ? 0 : SECTION_WRITE);
3151 flags = SECTION_WRITE;
3152 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3154 #endif /* EH_FRAME_SECTION_NAME */
3156 if (eh_frame_section)
3157 switch_to_section (eh_frame_section);
3160 /* We have no special eh_frame section. Put the information in
3161 the data section and emit special labels to guide collect2. */
3162 switch_to_section (data_section);
3166 label = get_file_function_name ("F");
3167 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3168 targetm.asm_out.globalize_label (asm_out_file,
3169 IDENTIFIER_POINTER (label));
3170 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3175 /* Switch [BACK] to the eh or debug frame table section, depending on
3179 switch_to_frame_table_section (int for_eh, bool back)
3182 switch_to_eh_frame_section (back);
3185 if (!debug_frame_section)
3186 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3187 SECTION_DEBUG, NULL);
3188 switch_to_section (debug_frame_section);
3192 /* Output a Call Frame Information opcode and its operand(s). */
3195 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3200 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3201 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3202 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3203 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3204 ((unsigned HOST_WIDE_INT)
3205 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3206 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3208 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3209 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3210 "DW_CFA_offset, column %#lx", r);
3211 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3212 dw2_asm_output_data_uleb128 (off, NULL);
3214 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3216 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3217 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3218 "DW_CFA_restore, column %#lx", r);
3222 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3223 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3225 switch (cfi->dw_cfi_opc)
3227 case DW_CFA_set_loc:
3229 dw2_asm_output_encoded_addr_rtx (
3230 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3231 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3234 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3235 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3236 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3239 case DW_CFA_advance_loc1:
3240 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3241 fde->dw_fde_current_label, NULL);
3242 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3245 case DW_CFA_advance_loc2:
3246 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3247 fde->dw_fde_current_label, NULL);
3248 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3251 case DW_CFA_advance_loc4:
3252 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3253 fde->dw_fde_current_label, NULL);
3254 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3257 case DW_CFA_MIPS_advance_loc8:
3258 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3259 fde->dw_fde_current_label, NULL);
3260 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3263 case DW_CFA_offset_extended:
3264 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3265 dw2_asm_output_data_uleb128 (r, NULL);
3266 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3267 dw2_asm_output_data_uleb128 (off, NULL);
3270 case DW_CFA_def_cfa:
3271 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3272 dw2_asm_output_data_uleb128 (r, NULL);
3273 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3276 case DW_CFA_offset_extended_sf:
3277 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3278 dw2_asm_output_data_uleb128 (r, NULL);
3279 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3280 dw2_asm_output_data_sleb128 (off, NULL);
3283 case DW_CFA_def_cfa_sf:
3284 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3285 dw2_asm_output_data_uleb128 (r, NULL);
3286 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3287 dw2_asm_output_data_sleb128 (off, NULL);
3290 case DW_CFA_restore_extended:
3291 case DW_CFA_undefined:
3292 case DW_CFA_same_value:
3293 case DW_CFA_def_cfa_register:
3294 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3295 dw2_asm_output_data_uleb128 (r, NULL);
3298 case DW_CFA_register:
3299 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3300 dw2_asm_output_data_uleb128 (r, NULL);
3301 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3302 dw2_asm_output_data_uleb128 (r, NULL);
3305 case DW_CFA_def_cfa_offset:
3306 case DW_CFA_GNU_args_size:
3307 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3310 case DW_CFA_def_cfa_offset_sf:
3311 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3312 dw2_asm_output_data_sleb128 (off, NULL);
3315 case DW_CFA_GNU_window_save:
3318 case DW_CFA_def_cfa_expression:
3319 case DW_CFA_expression:
3320 output_cfa_loc (cfi, for_eh);
3323 case DW_CFA_GNU_negative_offset_extended:
3324 /* Obsoleted by DW_CFA_offset_extended_sf. */
3333 /* Similar, but do it via assembler directives instead. */
3336 output_cfi_directive (dw_cfi_ref cfi)
3338 unsigned long r, r2;
3340 switch (cfi->dw_cfi_opc)
3342 case DW_CFA_advance_loc:
3343 case DW_CFA_advance_loc1:
3344 case DW_CFA_advance_loc2:
3345 case DW_CFA_advance_loc4:
3346 case DW_CFA_MIPS_advance_loc8:
3347 case DW_CFA_set_loc:
3348 /* Should only be created by add_fde_cfi in a code path not
3349 followed when emitting via directives. The assembler is
3350 going to take care of this for us. */
3354 case DW_CFA_offset_extended:
3355 case DW_CFA_offset_extended_sf:
3356 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3357 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3358 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3361 case DW_CFA_restore:
3362 case DW_CFA_restore_extended:
3363 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3364 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3367 case DW_CFA_undefined:
3368 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3369 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3372 case DW_CFA_same_value:
3373 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3374 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3377 case DW_CFA_def_cfa:
3378 case DW_CFA_def_cfa_sf:
3379 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3380 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3381 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3384 case DW_CFA_def_cfa_register:
3385 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3386 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3389 case DW_CFA_register:
3390 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3391 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3392 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3395 case DW_CFA_def_cfa_offset:
3396 case DW_CFA_def_cfa_offset_sf:
3397 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3398 HOST_WIDE_INT_PRINT_DEC"\n",
3399 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3402 case DW_CFA_remember_state:
3403 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3405 case DW_CFA_restore_state:
3406 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3409 case DW_CFA_GNU_args_size:
3410 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3411 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3413 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3414 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3415 fputc ('\n', asm_out_file);
3418 case DW_CFA_GNU_window_save:
3419 fprintf (asm_out_file, "\t.cfi_window_save\n");
3422 case DW_CFA_def_cfa_expression:
3423 case DW_CFA_expression:
3424 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3425 output_cfa_loc_raw (cfi);
3426 fputc ('\n', asm_out_file);
3434 DEF_VEC_P (dw_cfi_ref);
3435 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3437 /* Output CFIs to bring current FDE to the same state as after executing
3438 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3439 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3440 other arguments to pass to output_cfi. */
3443 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3445 struct dw_cfi_struct cfi_buf;
3447 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3448 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3449 unsigned int len, idx;
3451 for (;; cfi = cfi->dw_cfi_next)
3452 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3454 case DW_CFA_advance_loc:
3455 case DW_CFA_advance_loc1:
3456 case DW_CFA_advance_loc2:
3457 case DW_CFA_advance_loc4:
3458 case DW_CFA_MIPS_advance_loc8:
3459 case DW_CFA_set_loc:
3460 /* All advances should be ignored. */
3462 case DW_CFA_remember_state:
3464 dw_cfi_ref args_size = cfi_args_size;
3466 /* Skip everything between .cfi_remember_state and
3467 .cfi_restore_state. */
3468 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3469 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3471 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3474 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3481 cfi_args_size = args_size;
3485 case DW_CFA_GNU_args_size:
3486 cfi_args_size = cfi;
3488 case DW_CFA_GNU_window_save:
3491 case DW_CFA_offset_extended:
3492 case DW_CFA_offset_extended_sf:
3493 case DW_CFA_restore:
3494 case DW_CFA_restore_extended:
3495 case DW_CFA_undefined:
3496 case DW_CFA_same_value:
3497 case DW_CFA_register:
3498 case DW_CFA_val_offset:
3499 case DW_CFA_val_offset_sf:
3500 case DW_CFA_expression:
3501 case DW_CFA_val_expression:
3502 case DW_CFA_GNU_negative_offset_extended:
3503 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3504 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3505 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3506 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3508 case DW_CFA_def_cfa:
3509 case DW_CFA_def_cfa_sf:
3510 case DW_CFA_def_cfa_expression:
3512 cfi_cfa_offset = cfi;
3514 case DW_CFA_def_cfa_register:
3517 case DW_CFA_def_cfa_offset:
3518 case DW_CFA_def_cfa_offset_sf:
3519 cfi_cfa_offset = cfi;
3522 gcc_assert (cfi == NULL);
3524 len = VEC_length (dw_cfi_ref, regs);
3525 for (idx = 0; idx < len; idx++)
3527 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3529 && cfi2->dw_cfi_opc != DW_CFA_restore
3530 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3533 output_cfi_directive (cfi2);
3535 output_cfi (cfi2, fde, for_eh);
3538 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3540 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3542 switch (cfi_cfa_offset->dw_cfi_opc)
3544 case DW_CFA_def_cfa_offset:
3545 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3546 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3548 case DW_CFA_def_cfa_offset_sf:
3549 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3550 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3552 case DW_CFA_def_cfa:
3553 case DW_CFA_def_cfa_sf:
3554 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3555 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3562 else if (cfi_cfa_offset)
3563 cfi_cfa = cfi_cfa_offset;
3567 output_cfi_directive (cfi_cfa);
3569 output_cfi (cfi_cfa, fde, for_eh);
3572 cfi_cfa_offset = NULL;