OSDN Git Service

* config/freebsd-spec.h (FBSD_CPP_PREDEFINES): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
index e8a5f18..445f325 100644 (file)
@@ -1,6 +1,6 @@
 /* Output Dwarf2 format symbol table information from the GNU C compiler.
-   Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+   2003 Free Software Foundation, Inc.
    Contributed by Gary Funck (gary@intrepid.com).
    Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
    Extensively modified by Jason Merrill (jason@cygnus.com).
@@ -22,8 +22,7 @@ along with GCC; see the file COPYING.  If not, write to the Free
 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.  */
 
-/* TODO: Implement .debug_str handling, and share entries somehow.
-        Emit .debug_line header even when there are no functions, since
+/* TODO: Emit .debug_line header even when there are no functions, since
           the file numbers are used by .debug_info.  Alternately, leave
           out locations for types and decls.
         Avoid talking about ctors and op= for PODs.
@@ -37,8 +36,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "flags.h"
+#include "real.h"
 #include "rtl.h"
 #include "hard-reg-set.h"
 #include "regs.h"
@@ -59,6 +61,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "tm_p.h"
 #include "diagnostic.h"
 #include "debug.h"
+#include "target.h"
+#include "langhooks.h"
+#include "hashtab.h"
 
 #ifdef DWARF2_DEBUGGING_INFO
 static void dwarf2out_source_line      PARAMS ((unsigned int, const char *));
@@ -89,6 +94,7 @@ int
 dwarf2out_do_frame ()
 {
   return (write_symbols == DWARF2_DEBUG
+         || write_symbols == VMS_AND_DWARF2_DEBUG
 #ifdef DWARF2_FRAME_INFO
          || DWARF2_FRAME_INFO
 #endif
@@ -99,14 +105,62 @@ dwarf2out_do_frame ()
          );
 }
 
-/* The number of the current function definition for which debugging
-   information is being generated.  These numbers range from 1 up to the
-   maximum number of function definitions contained within the current
-   compilation unit.  These numbers are used to create unique label id's
-   unique to each function definition.  */
-unsigned current_funcdef_number = 0;
+/* The size of the target's pointer type.  */
+#ifndef PTR_SIZE
+#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
+#endif
 
-#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
+/* Default version of targetm.eh_frame_section.  Note this must appear
+   outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
+   guards.  */
+
+void
+default_eh_frame_section ()
+{
+#ifdef EH_FRAME_SECTION_NAME
+#ifdef HAVE_LD_RO_RW_SECTION_MIXING
+  int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
+  int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
+  int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
+  int flags;
+
+  flags = (! flag_pic
+          || ((fde_encoding & 0x70) != DW_EH_PE_absptr
+              && (fde_encoding & 0x70) != DW_EH_PE_aligned
+              && (per_encoding & 0x70) != DW_EH_PE_absptr
+              && (per_encoding & 0x70) != DW_EH_PE_aligned
+              && (lsda_encoding & 0x70) != DW_EH_PE_absptr
+              && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
+         ? 0 : SECTION_WRITE;
+  named_section_flags (EH_FRAME_SECTION_NAME, flags);
+#else
+  named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
+#endif
+#else
+  tree label = get_file_function_name ('F');
+
+  data_section ();
+  ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
+  (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
+  ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
+#endif
+}
+
+/* Array of RTXes referenced by the debugging information, which therefore
+   must be kept around forever.  */
+static GTY(()) varray_type used_rtx_varray;
+
+/* A pointer to the base of a list of incomplete types which might be
+   completed at some later time.  incomplete_types_list needs to be a VARRAY
+   because we want to tell the garbage collector about it.  */
+static GTY(()) varray_type incomplete_types;
+
+/* A pointer to the base of a table of references to declaration
+   scopes.  This table is a display which tracks the nesting
+   of declaration scopes at the current scope and containing
+   scopes.  This table is used to find the proper place to
+   define type declaration DIE's.  */
+static GTY(()) varray_type decl_scope_table;
 
 /* How to start an assembler comment.  */
 #ifndef ASM_COMMENT_START
@@ -122,21 +176,31 @@ typedef union  dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
    and address fields are provided as possible operands;
    their use is selected by the opcode field.  */
 
-typedef union dw_cfi_oprnd_struct
+enum dw_cfi_oprnd_type {
+  dw_cfi_oprnd_unused,
+  dw_cfi_oprnd_reg_num,
+  dw_cfi_oprnd_offset,
+  dw_cfi_oprnd_addr,
+  dw_cfi_oprnd_loc
+};
+
+typedef union dw_cfi_oprnd_struct GTY(())
 {
-  unsigned long dw_cfi_reg_num;
-  long int dw_cfi_offset;
-  const char *dw_cfi_addr;
-  struct dw_loc_descr_struct *dw_cfi_loc;
+  unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
+  long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
+  const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
+  struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
 }
 dw_cfi_oprnd;
 
-typedef struct dw_cfi_struct
+typedef struct dw_cfi_struct GTY(())
 {
   dw_cfi_ref dw_cfi_next;
   enum dwarf_call_frame_info dw_cfi_opc;
-  dw_cfi_oprnd dw_cfi_oprnd1;
-  dw_cfi_oprnd dw_cfi_oprnd2;
+  dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)"))) 
+    dw_cfi_oprnd1;
+  dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)"))) 
+    dw_cfi_oprnd2;
 }
 dw_cfi_node;
 
@@ -145,7 +209,7 @@ dw_cfi_node;
    It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
    Instead of passing around REG and OFFSET, we pass a copy
    of this structure.  */
-typedef struct cfa_loc
+typedef struct cfa_loc GTY(())
 {
   unsigned long reg;
   long offset;
@@ -159,13 +223,14 @@ typedef struct cfa_loc
    CIE obviates the need to keep track of multiple CIE's
    in the DWARF generation routines below.  */
 
-typedef struct dw_fde_struct
+typedef struct dw_fde_struct GTY(())
 {
   const char *dw_fde_begin;
   const char *dw_fde_current_label;
   const char *dw_fde_end;
   dw_cfi_ref dw_fde_cfi;
   unsigned funcdef_number;
+  unsigned all_throwers_are_sibcalls : 1;
   unsigned nothrow : 1;
   unsigned uses_eh_lsda : 1;
 }
@@ -174,11 +239,6 @@ dw_fde_node;
 /* Maximum size (in bytes) of an artificially generated label.  */
 #define MAX_ARTIFICIAL_LABEL_BYTES     30
 
-/* The size of the target's pointer type.  */
-#ifndef PTR_SIZE
-#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
-#endif
-
 /* The size of addresses as they appear in the Dwarf 2 data.
    Some architectures use word addresses to refer to code locations,
    but Dwarf 2 info always uses byte addresses.  On such machines,
@@ -210,30 +270,47 @@ dw_fde_node;
 #else
 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
 #endif
-#endif /* not DWARF_CIE_DATA_ALIGNMENT */
+#endif
 
 /* A pointer to the base of a table that contains frame description
    information for each routine.  */
-static dw_fde_ref fde_table;
+static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
 
 /* Number of elements currently allocated for fde_table.  */
 static unsigned fde_table_allocated;
 
 /* Number of elements in fde_table currently in use.  */
-static unsigned fde_table_in_use;
+static GTY(()) unsigned fde_table_in_use;
 
 /* Size (in elements) of increments by which we may expand the
    fde_table.  */
 #define FDE_TABLE_INCREMENT 256
 
 /* A list of call frame insns for the CIE.  */
-static dw_cfi_ref cie_cfi_head;
+static GTY(()) dw_cfi_ref cie_cfi_head;
 
+#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
    attribute that accelerates the lookup of the FDE associated
    with the subprogram.  This variable holds the table index of the FDE
    associated with the current function (body) definition.  */
 static unsigned current_funcdef_fde;
+#endif
+
+struct indirect_string_node GTY(())
+{
+  const char *str;
+  unsigned int refcount;
+  unsigned int form;
+  char *label;
+};
+
+static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
+
+static GTY(()) int dw2_string_counter;
+static GTY(()) unsigned long dwarf2out_cfi_label_num;
+
+#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
 
 /* Forward declarations for functions defined in this file.  */
 
@@ -242,7 +319,8 @@ static const char *dwarf_cfi_name   PARAMS ((unsigned));
 static dw_cfi_ref new_cfi              PARAMS ((void));
 static void add_cfi                    PARAMS ((dw_cfi_ref *, dw_cfi_ref));
 static void add_fde_cfi                        PARAMS ((const char *, dw_cfi_ref));
-static void lookup_cfa_1               PARAMS ((dw_cfi_ref, dw_cfa_location *));
+static void lookup_cfa_1               PARAMS ((dw_cfi_ref,
+                                                dw_cfa_location *));
 static void lookup_cfa                 PARAMS ((dw_cfa_location *));
 static void reg_save                   PARAMS ((const char *, unsigned,
                                                 unsigned, long));
@@ -259,10 +337,11 @@ static void dwarf2out_frame_debug_expr    PARAMS ((rtx, const char *));
 /* Support for complex CFA locations.  */
 static void output_cfa_loc             PARAMS ((dw_cfi_ref));
 static void get_cfa_from_loc_descr     PARAMS ((dw_cfa_location *,
-                                               struct dw_loc_descr_struct *));
+                                               struct dw_loc_descr_struct *));
 static struct dw_loc_descr_struct *build_cfa_loc
                                        PARAMS ((dw_cfa_location *));
-static void def_cfa_1                  PARAMS ((const char *, dw_cfa_location *));
+static void def_cfa_1                  PARAMS ((const char *,
+                                                dw_cfa_location *));
 
 /* How to start an assembler comment.  */
 #ifndef ASM_COMMENT_START
@@ -273,11 +352,6 @@ static void def_cfa_1                      PARAMS ((const char *, dw_cfa_location *));
 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
 
-/* Pseudo-op for defining a new section.  */
-#ifndef SECTION_ASM_OP
-#define SECTION_ASM_OP "\t.section\t"
-#endif
-
 #ifndef DEBUG_FRAME_SECTION
 #define DEBUG_FRAME_SECTION    ".debug_frame"
 #endif
@@ -285,41 +359,23 @@ static void def_cfa_1                     PARAMS ((const char *, dw_cfa_location *));
 #ifndef FUNC_BEGIN_LABEL
 #define FUNC_BEGIN_LABEL       "LFB"
 #endif
+
 #ifndef FUNC_END_LABEL
 #define FUNC_END_LABEL         "LFE"
 #endif
+
 #define FRAME_BEGIN_LABEL      "Lframe"
 #define CIE_AFTER_SIZE_LABEL   "LSCIE"
 #define CIE_END_LABEL          "LECIE"
-#define CIE_LENGTH_LABEL       "LLCIE"
 #define FDE_LABEL              "LSFDE"
 #define FDE_AFTER_SIZE_LABEL   "LASFDE"
 #define FDE_END_LABEL          "LEFDE"
-#define FDE_LENGTH_LABEL       "LLFDE"
 #define LINE_NUMBER_BEGIN_LABEL        "LSLT"
 #define LINE_NUMBER_END_LABEL  "LELT"
 #define LN_PROLOG_AS_LABEL     "LASLTP"
 #define LN_PROLOG_END_LABEL    "LELTP"
 #define DIE_LABEL_PREFIX       "DW"
 
-/* Definitions of defaults for various types of primitive assembly language
-   output operations.  These may be overridden from within the tm.h file,
-   but typically, that is unnecessary.  */
-
-#ifdef SET_ASM_OP
-#ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
-#define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO)            \
- do {                                                                  \
-  fprintf (FILE, "%s", SET_ASM_OP);                                    \
-  assemble_name (FILE, SY);                                            \
-  fputc (',', FILE);                                                   \
-  assemble_name (FILE, HI);                                            \
-  fputc ('-', FILE);                                                   \
-  assemble_name (FILE, LO);                                            \
- } while (0)
-#endif
-#endif /* SET_ASM_OP */
-
 /* The DWARF 2 CFA column which tracks the return address.  Normally this
    is the column for PC, or the first column after all of the hard
    registers.  */
@@ -337,6 +393,12 @@ static void def_cfa_1                      PARAMS ((const char *, dw_cfa_location *));
 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
 #endif
 
+/* The offset from the incoming value of %sp to the top of the stack frame
+   for the current function.  */
+#ifndef INCOMING_FRAME_SP_OFFSET
+#define INCOMING_FRAME_SP_OFFSET 0
+#endif
+\f
 /* Hook used by __throw.  */
 
 rtx
@@ -345,12 +407,6 @@ expand_builtin_dwarf_fp_regnum ()
   return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
 }
 
-/* The offset from the incoming value of %sp to the top of the stack frame
-   for the current function.  */
-#ifndef INCOMING_FRAME_SP_OFFSET
-#define INCOMING_FRAME_SP_OFFSET 0
-#endif
-\f
 /* Return a pointer to a copy of the section string name S with all
    attributes stripped off, and an asterisk prepended (for assemble_name).  */
 
@@ -379,18 +435,19 @@ expand_builtin_init_dwarf_reg_sizes (address)
   int i;
   enum machine_mode mode = TYPE_MODE (char_type_node);
   rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
-  rtx mem = gen_rtx_MEM (mode, addr);
+  rtx mem = gen_rtx_MEM (BLKmode, addr);
 
-  for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
-    {
-      int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
-      int size = GET_MODE_SIZE (reg_raw_mode[i]);
+  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+    if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
+      {
+       HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
+       HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
 
-      if (offset < 0)
-       continue;
+       if (offset < 0)
+         continue;
 
-      emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
-    }
+       emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
+      }
 }
 
 /* Convert a DWARF call frame info. operation to its string name */
@@ -437,8 +494,18 @@ dwarf_cfi_name (cfi_opc)
       return "DW_CFA_def_cfa_register";
     case DW_CFA_def_cfa_offset:
       return "DW_CFA_def_cfa_offset";
+
+    /* DWARF 3 */
     case DW_CFA_def_cfa_expression:
       return "DW_CFA_def_cfa_expression";
+    case DW_CFA_expression:
+      return "DW_CFA_expression";
+    case DW_CFA_offset_extended_sf:
+      return "DW_CFA_offset_extended_sf";
+    case DW_CFA_def_cfa_sf:
+      return "DW_CFA_def_cfa_sf";
+    case DW_CFA_def_cfa_offset_sf:
+      return "DW_CFA_def_cfa_offset_sf";
 
     /* SGI/MIPS specific */
     case DW_CFA_MIPS_advance_loc8:
@@ -462,7 +529,7 @@ dwarf_cfi_name (cfi_opc)
 static inline dw_cfi_ref
 new_cfi ()
 {
-  dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
+  dw_cfi_ref cfi = (dw_cfi_ref) ggc_alloc (sizeof (dw_cfi_node));
 
   cfi->dw_cfi_next = NULL;
   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
@@ -493,11 +560,9 @@ char *
 dwarf2out_cfi_label ()
 {
   static char label[20];
-  static unsigned long label_num = 0;
 
-  ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
+  ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
   ASM_OUTPUT_LABEL (asm_out_file, label);
-
   return label;
 }
 
@@ -621,6 +686,7 @@ dwarf2out_def_cfa (label, reg, offset)
 
 /* This routine does the actual work.  The CFA is now calculated from
    the dw_cfa_location structure.  */
+
 static void
 def_cfa_1 (label, loc_p)
      const char *label;
@@ -638,15 +704,11 @@ def_cfa_1 (label, loc_p)
   loc.reg = DWARF_FRAME_REGNUM (loc.reg);
   lookup_cfa (&old_cfa);
 
-  if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
-      loc.indirect == old_cfa.indirect)
-    {
-      if (loc.indirect == 0
-         || loc.base_offset == old_cfa.base_offset)
-       /* Nothing changed so no need to issue any call frame
-           instructions.  */
-       return;
-    }
+  /* If nothing changed, no need to issue any call frame instructions.  */
+  if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
+      && loc.indirect == old_cfa.indirect
+      && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
+    return;
 
   cfi = new_cfi ();
 
@@ -686,6 +748,7 @@ def_cfa_1 (label, loc_p)
         calculate the CFA using a full location expression since no
         register-offset pair is available.  */
       struct dw_loc_descr_struct *loc_list;
+
       cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
       loc_list = build_cfa_loc (&loc);
       cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
@@ -735,10 +798,8 @@ reg_save (label, reg, sreg, offset)
 #endif
       offset /= DWARF_CIE_DATA_ALIGNMENT;
       if (offset < 0)
-       {
-         cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
-         offset = -offset;
-       }
+       cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
+
       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
     }
   else if (sreg == reg)
@@ -765,6 +826,7 @@ dwarf2out_window_save (label)
      const char *label;
 {
   dw_cfi_ref cfi = new_cfi ();
+
   cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
   add_fde_cfi (label, cfi);
 }
@@ -781,6 +843,7 @@ dwarf2out_args_size (label, size)
 
   if (size == old_args_size)
     return;
+
   old_args_size = size;
 
   cfi = new_cfi ();
@@ -831,7 +894,7 @@ initial_return_save (rtl)
      rtx rtl;
 {
   unsigned int reg = (unsigned int) -1;
-  long offset = 0;
+  HOST_WIDE_INT offset = 0;
 
   switch (GET_CODE (rtl))
     {
@@ -839,6 +902,7 @@ initial_return_save (rtl)
       /* RA is in a register.  */
       reg = DWARF_FRAME_REGNUM (REGNO (rtl));
       break;
+
     case MEM:
       /* RA is on the stack.  */
       rtl = XEXP (rtl, 0);
@@ -849,20 +913,25 @@ initial_return_save (rtl)
            abort ();
          offset = 0;
          break;
+
        case PLUS:
          if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
            abort ();
          offset = INTVAL (XEXP (rtl, 1));
          break;
+
        case MINUS:
          if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
            abort ();
          offset = -INTVAL (XEXP (rtl, 1));
          break;
+
        default:
          abort ();
        }
+
       break;
+
     case PLUS:
       /* The return address is at some offset from any value we can
         actually load.  For instance, on the SPARC it is in %i7+8. Just
@@ -871,6 +940,7 @@ initial_return_save (rtl)
        abort ();
       initial_return_save (XEXP (rtl, 0));
       return;
+
     default:
       abort ();
     }
@@ -883,11 +953,11 @@ initial_return_save (rtl)
 
 static long
 stack_adjust_offset (pattern)
-  rtx pattern;
+     rtx pattern;
 {
   rtx src = SET_SRC (pattern);
   rtx dest = SET_DEST (pattern);
-  long offset = 0;
+  HOST_WIDE_INT offset = 0;
   enum rtx_code code;
 
   if (dest == stack_pointer_rtx)
@@ -900,6 +970,8 @@ stack_adjust_offset (pattern)
        return 0;
 
       offset = INTVAL (XEXP (src, 1));
+      if (code == PLUS)
+       offset = -offset;
     }
   else if (GET_CODE (dest) == MEM)
     {
@@ -907,28 +979,47 @@ stack_adjust_offset (pattern)
       src = XEXP (dest, 0);
       code = GET_CODE (src);
 
-      if (! (code == PRE_DEC || code == PRE_INC
-            || code == PRE_MODIFY)
-         || XEXP (src, 0) != stack_pointer_rtx)
-       return 0;
-
-      if (code == PRE_MODIFY)
+      switch (code)
        {
-         rtx val = XEXP (XEXP (src, 1), 1);
-         /* We handle only adjustments by constant amount.  */
-         if (GET_CODE (XEXP (src, 1)) != PLUS ||
-             GET_CODE (val) != CONST_INT)
-           abort();
-         offset = -INTVAL (val);
+       case PRE_MODIFY:
+       case POST_MODIFY:
+         if (XEXP (src, 0) == stack_pointer_rtx)
+           {
+             rtx val = XEXP (XEXP (src, 1), 1);
+             /* We handle only adjustments by constant amount.  */
+             if (GET_CODE (XEXP (src, 1)) != PLUS ||
+                 GET_CODE (val) != CONST_INT)
+               abort ();
+             offset = -INTVAL (val);
+             break;
+           }
+         return 0;
+
+       case PRE_DEC:
+       case POST_DEC:
+         if (XEXP (src, 0) == stack_pointer_rtx)
+           {
+             offset = GET_MODE_SIZE (GET_MODE (dest));
+             break;
+           }
+         return 0;
+
+       case PRE_INC:
+       case POST_INC:
+         if (XEXP (src, 0) == stack_pointer_rtx)
+           {
+             offset = -GET_MODE_SIZE (GET_MODE (dest));
+             break;
+           }
+         return 0;
+
+       default:
+         return 0;
        }
-      else offset = GET_MODE_SIZE (GET_MODE (dest));
     }
   else
     return 0;
 
-  if (code == PLUS || code == PRE_INC)
-    offset = -offset;
-
   return offset;
 }
 
@@ -940,13 +1031,13 @@ static void
 dwarf2out_stack_adjust (insn)
      rtx insn;
 {
-  long offset;
+  HOST_WIDE_INT offset;
   const char *label;
+  int i;
 
-  if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
+  if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
     {
       /* Extract the size of the args from the CALL rtx itself.  */
-
       insn = PATTERN (insn);
       if (GET_CODE (insn) == PARALLEL)
        insn = XVECEXP (insn, 0, 0);
@@ -954,14 +1045,14 @@ dwarf2out_stack_adjust (insn)
        insn = SET_SRC (insn);
       if (GET_CODE (insn) != CALL)
        abort ();
+
       dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
       return;
     }
 
   /* If only calls can throw, and we have a frame pointer,
      save up adjustments until we see the CALL_INSN.  */
-  else if (! flag_non_call_exceptions
-          && cfa.reg != STACK_POINTER_REGNUM)
+  else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
     return;
 
   if (GET_CODE (insn) == BARRIER)
@@ -976,23 +1067,15 @@ dwarf2out_stack_adjust (insn)
 #endif
     }
   else if (GET_CODE (PATTERN (insn)) == SET)
-    {
-      offset = stack_adjust_offset (PATTERN (insn));
-    }
+    offset = stack_adjust_offset (PATTERN (insn));
   else if (GET_CODE (PATTERN (insn)) == PARALLEL
           || GET_CODE (PATTERN (insn)) == SEQUENCE)
     {
       /* There may be stack adjustments inside compound insns.  Search
-         for them.  */
-      int j;
-
-      offset = 0;
-      for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
-       {
-         rtx pattern = XVECEXP (PATTERN (insn), 0, j);
-         if (GET_CODE (pattern) == SET)
-           offset += stack_adjust_offset (pattern);
-       }
+        for them.  */
+      for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
+       if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
+         offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
     }
   else
     return;
@@ -1006,6 +1089,7 @@ dwarf2out_stack_adjust (insn)
 #ifndef STACK_GROWS_DOWNWARD
   offset = -offset;
 #endif
+
   args_size += offset;
   if (args_size < 0)
     args_size = 0;
@@ -1015,18 +1099,22 @@ dwarf2out_stack_adjust (insn)
   dwarf2out_args_size (label, args_size);
 }
 
+#endif
+
 /* We delay emitting a register save until either (a) we reach the end
    of the prologue or (b) the register is clobbered.  This clusters
    register saves so that there are fewer pc advances.  */
 
-struct queued_reg_save
+struct queued_reg_save GTY(())
 {
   struct queued_reg_save *next;
   rtx reg;
   long cfa_offset;
 };
 
-static struct queued_reg_save *queued_reg_saves;
+static GTY(()) struct queued_reg_save *queued_reg_saves;
+
+#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
 static const char *last_reg_save_label;
 
 static void
@@ -1035,7 +1123,7 @@ queue_reg_save (label, reg, offset)
      rtx reg;
      long offset;
 {
-  struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
+  struct queued_reg_save *q = ggc_alloc (sizeof (*q));
 
   q->next = queued_reg_saves;
   q->reg = reg;
@@ -1050,11 +1138,10 @@ flush_queued_reg_saves ()
 {
   struct queued_reg_save *q, *next;
 
-  for (q = queued_reg_saves; q ; q = next)
+  for (q = queued_reg_saves; q; q = next)
     {
       dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
       next = q->next;
-      free (q);
     }
 
   queued_reg_saves = NULL;
@@ -1067,13 +1154,13 @@ clobbers_queued_reg_save (insn)
 {
   struct queued_reg_save *q;
 
-  for (q = queued_reg_saves; q ; q = q->next)
+  for (q = queued_reg_saves; q; q = q->next)
     if (modified_in_p (q->reg, insn))
       return true;
 
   return false;
 }
-  
+
 
 /* A temporary register holding an integral value used in adjusting SP
    or setting up the store_reg.  The "offset" field holds the integer
@@ -1109,7 +1196,7 @@ static dw_cfa_location cfa_temp;
   had better be the one we think we're using for this purpose.
 
   Except: If the register being saved is the CFA register, and the
-  offset is non-zero, we are saving the CFA, so we assume we have to
+  offset is nonzero, we are saving the CFA, so we assume we have to
   use DW_CFA_def_cfa_expression.  If the offset is 0, we assume that
   the intent is to save the value of SP from the previous frame.
 
@@ -1124,7 +1211,7 @@ static dw_cfa_location cfa_temp;
               stores the value, which will be used to adjust the
               stack pointer.  cfa_temp is also used like cfa_store,
               to track stores to the stack via fp or a temp reg.
+
   Rules  1- 4: Setting a register's value to cfa.reg or an expression
               with cfa.reg as the first operand changes the cfa.reg and its
               cfa.offset.  Rule 1 and 4 also set cfa_temp.reg and
@@ -1149,12 +1236,13 @@ static dw_cfa_location cfa_temp;
   Rule 1:
   (set <reg1> <reg2>:cfa.reg)
   effects: cfa.reg = <reg1>
-           cfa.offset unchanged
+          cfa.offset unchanged
           cfa_temp.reg = <reg1>
           cfa_temp.offset = cfa.offset
 
   Rule 2:
-  (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
+  (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
+                             {<const_int>,<reg>:cfa_temp.reg}))
   effects: cfa.reg = sp if fp used
           cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
           cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
@@ -1214,7 +1302,9 @@ static dw_cfa_location cfa_temp;
           cfa.base_offset = -cfa_store.offset
 
   Rule 12:
-  (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
+  (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
+
+       <reg2>)
   effects: cfa.reg = <reg1>
           cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
 
@@ -1235,28 +1325,24 @@ dwarf2out_frame_debug_expr (expr, label)
      const char *label;
 {
   rtx src, dest;
-  long offset;
+  HOST_WIDE_INT offset;
 
   /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
      the PARALLEL independently. The first element is always processed if
      it is a SET. This is for backward compatibility.   Other elements
      are processed only if they are SETs and the RTX_FRAME_RELATED_P
      flag is set in them.  */
-
-  if (GET_CODE (expr) == PARALLEL
-      || GET_CODE (expr) == SEQUENCE)
+  if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
     {
       int par_index;
       int limit = XVECLEN (expr, 0);
 
       for (par_index = 0; par_index < limit; par_index++)
-       {
-         rtx x = XVECEXP (expr, 0, par_index);
+       if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
+           && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
+               || par_index == 0))
+         dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
 
-         if (GET_CODE (x) == SET &&
-             (RTX_FRAME_RELATED_P (x) || par_index == 0))
-           dwarf2out_frame_debug_expr (x, label);
-       }
       return;
     }
 
@@ -1271,7 +1357,7 @@ dwarf2out_frame_debug_expr (expr, label)
     case REG:
       /* Rule 1 */
       /* Update the CFA rule wrt SP or FP.  Make sure src is
-         relative to the current CFA register.  */
+        relative to the current CFA register.  */
       switch (GET_CODE (src))
        {
          /* Setting FP from SP.  */
@@ -1372,6 +1458,7 @@ dwarf2out_frame_debug_expr (expr, label)
                  cfa_temp.reg = cfa.reg;
                  cfa_temp.offset = cfa.offset;
                }
+
              /* Rule 5 */
              else if (GET_CODE (XEXP (src, 0)) == REG
                       && REGNO (XEXP (src, 0)) == cfa_temp.reg
@@ -1384,6 +1471,7 @@ dwarf2out_frame_debug_expr (expr, label)
                  cfa_store.reg = REGNO (dest);
                  cfa_store.offset = cfa.offset - cfa_temp.offset;
                }
+
              /* Rule 9 */
              else if (GET_CODE (src) == LO_SUM
                       && GET_CODE (XEXP (src, 1)) == CONST_INT)
@@ -1408,6 +1496,7 @@ dwarf2out_frame_debug_expr (expr, label)
              || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
              || GET_CODE (XEXP (src, 1)) != CONST_INT)
            abort ();
+
          if ((unsigned) REGNO (dest) != cfa_temp.reg)
            cfa_temp.reg = REGNO (dest);
          cfa_temp.offset |= INTVAL (XEXP (src, 1));
@@ -1422,6 +1511,7 @@ dwarf2out_frame_debug_expr (expr, label)
        default:
          abort ();
        }
+
       def_cfa_1 (label, &cfa);
       break;
 
@@ -1438,18 +1528,20 @@ dwarf2out_frame_debug_expr (expr, label)
        case PRE_MODIFY:
          /* We can't handle variable size modifications.  */
          if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
-           abort();
+           abort ();
          offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
 
          if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
              || cfa_store.reg != STACK_POINTER_REGNUM)
            abort ();
+
          cfa_store.offset += offset;
          if (cfa.reg == STACK_POINTER_REGNUM)
            cfa.offset = cfa_store.offset;
 
          offset = -cfa_store.offset;
          break;
+
          /* Rule 11 */
        case PRE_INC:
        case PRE_DEC:
@@ -1460,6 +1552,7 @@ dwarf2out_frame_debug_expr (expr, label)
          if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
              || cfa_store.reg != STACK_POINTER_REGNUM)
            abort ();
+
          cfa_store.offset += offset;
          if (cfa.reg == STACK_POINTER_REGNUM)
            cfa.offset = cfa_store.offset;
@@ -1520,7 +1613,6 @@ dwarf2out_frame_debug_expr (expr, label)
              /* If the source register is exactly the CFA, assume
                 we're saving SP like any other register; this happens
                 on the ARM.  */
-
              def_cfa_1 (label, &cfa);
              queue_reg_save (label, stack_pointer_rtx, offset);
              break;
@@ -1528,14 +1620,15 @@ dwarf2out_frame_debug_expr (expr, label)
          else
            {
              /* Otherwise, we'll need to look in the stack to
-                 calculate the CFA.  */
-
+                calculate the CFA.  */
              rtx x = XEXP (dest, 0);
+
              if (GET_CODE (x) != REG)
                x = XEXP (x, 0);
              if (GET_CODE (x) != REG)
                abort ();
-             cfa.reg = (unsigned) REGNO (x);
+
+             cfa.reg = REGNO (x);
              cfa.base_offset = offset;
              cfa.indirect = 1;
              def_cfa_1 (label, &cfa);
@@ -1572,6 +1665,7 @@ dwarf2out_frame_debug (insn)
       lookup_cfa (&cfa);
       if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
        abort ();
+
       cfa.reg = STACK_POINTER_REGNUM;
       cfa_store = cfa;
       cfa_temp.reg = -1;
@@ -1585,12 +1679,12 @@ dwarf2out_frame_debug (insn)
   if (! RTX_FRAME_RELATED_P (insn))
     {
       if (!ACCUMULATE_OUTGOING_ARGS)
-        dwarf2out_stack_adjust (insn);
+       dwarf2out_stack_adjust (insn);
+
       return;
     }
 
   label = dwarf2out_cfi_label ();
-
   src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
   if (src)
     insn = XEXP (src, 0);
@@ -1600,6 +1694,82 @@ dwarf2out_frame_debug (insn)
   dwarf2out_frame_debug_expr (insn, label);
 }
 
+#endif
+
+/* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used.  */
+static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc 
+   PARAMS ((enum dwarf_call_frame_info cfi));
+
+static enum dw_cfi_oprnd_type
+dw_cfi_oprnd1_desc (cfi)
+     enum dwarf_call_frame_info cfi;
+{
+  switch (cfi)
+    {
+    case DW_CFA_nop:
+    case DW_CFA_GNU_window_save:
+      return dw_cfi_oprnd_unused;
+
+    case DW_CFA_set_loc:
+    case DW_CFA_advance_loc1:
+    case DW_CFA_advance_loc2:
+    case DW_CFA_advance_loc4:
+    case DW_CFA_MIPS_advance_loc8:
+      return dw_cfi_oprnd_addr;
+
+    case DW_CFA_offset:
+    case DW_CFA_offset_extended:
+    case DW_CFA_def_cfa:
+    case DW_CFA_offset_extended_sf:
+    case DW_CFA_def_cfa_sf:
+    case DW_CFA_restore_extended:
+    case DW_CFA_undefined:
+    case DW_CFA_same_value:
+    case DW_CFA_def_cfa_register:
+    case DW_CFA_register:
+      return dw_cfi_oprnd_reg_num;
+
+    case DW_CFA_def_cfa_offset:
+    case DW_CFA_GNU_args_size:
+    case DW_CFA_def_cfa_offset_sf:
+      return dw_cfi_oprnd_offset;
+      
+    case DW_CFA_def_cfa_expression:
+    case DW_CFA_expression:
+      return dw_cfi_oprnd_loc;
+
+    default:
+      abort ();
+    }
+}
+
+/* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used.  */
+static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc 
+   PARAMS ((enum dwarf_call_frame_info cfi));
+
+static enum dw_cfi_oprnd_type
+dw_cfi_oprnd2_desc (cfi)
+     enum dwarf_call_frame_info cfi;
+{
+  switch (cfi)
+    {
+    case DW_CFA_def_cfa:
+    case DW_CFA_def_cfa_sf:
+    case DW_CFA_offset:
+    case DW_CFA_offset_extended_sf:
+    case DW_CFA_offset_extended:
+      return dw_cfi_oprnd_offset;
+
+    case DW_CFA_register:
+      return dw_cfi_oprnd_reg_num;
+
+    default:
+      return dw_cfi_oprnd_unused;
+    }
+}
+
+#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
+
 /* Output a Call Frame Information opcode and its operand(s).  */
 
 static void
@@ -1609,12 +1779,10 @@ output_cfi (cfi, fde, for_eh)
      int for_eh;
 {
   if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
-    {
-      dw2_asm_output_data (1, (cfi->dw_cfi_opc
-                              | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
-                          "DW_CFA_advance_loc 0x%lx",
-                          cfi->dw_cfi_oprnd1.dw_cfi_offset);
-    }
+    dw2_asm_output_data (1, (cfi->dw_cfi_opc
+                            | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
+                        "DW_CFA_advance_loc 0x%lx",
+                        cfi->dw_cfi_oprnd1.dw_cfi_offset);
   else if (cfi->dw_cfi_opc == DW_CFA_offset)
     {
       dw2_asm_output_data (1, (cfi->dw_cfi_opc
@@ -1624,12 +1792,10 @@ output_cfi (cfi, fde, for_eh)
       dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
     }
   else if (cfi->dw_cfi_opc == DW_CFA_restore)
-    {
-      dw2_asm_output_data (1, (cfi->dw_cfi_opc
-                              | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
-                          "DW_CFA_restore, column 0x%lx",
-                          cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
-    }
+    dw2_asm_output_data (1, (cfi->dw_cfi_opc
+                            | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
+                        "DW_CFA_restore, column 0x%lx",
+                        cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
   else
     {
       dw2_asm_output_data (1, cfi->dw_cfi_opc,
@@ -1647,51 +1813,81 @@ output_cfi (cfi, fde, for_eh)
            dw2_asm_output_addr (DWARF2_ADDR_SIZE,
                                 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
          break;
+
        case DW_CFA_advance_loc1:
          dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
                                fde->dw_fde_current_label, NULL);
          fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
          break;
+
        case DW_CFA_advance_loc2:
          dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
                                fde->dw_fde_current_label, NULL);
          fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
          break;
+
        case DW_CFA_advance_loc4:
          dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
                                fde->dw_fde_current_label, NULL);
          fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
          break;
+
        case DW_CFA_MIPS_advance_loc8:
          dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
                                fde->dw_fde_current_label, NULL);
          fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
          break;
+
        case DW_CFA_offset_extended:
-       case DW_CFA_GNU_negative_offset_extended:
        case DW_CFA_def_cfa:
-         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
+         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
+                                      NULL);
          dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
          break;
+
+       case DW_CFA_offset_extended_sf:
+       case DW_CFA_def_cfa_sf:
+         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
+                                      NULL);
+         dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
+         break;
+
        case DW_CFA_restore_extended:
        case DW_CFA_undefined:
        case DW_CFA_same_value:
        case DW_CFA_def_cfa_register:
-         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
+         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
+                                      NULL);
          break;
+
        case DW_CFA_register:
-         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
-         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
+         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
+                                      NULL);
+         dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
+                                      NULL);
          break;
+
        case DW_CFA_def_cfa_offset:
        case DW_CFA_GNU_args_size:
          dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
          break;
+
+       case DW_CFA_def_cfa_offset_sf:
+         dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
+         break;
+
        case DW_CFA_GNU_window_save:
          break;
+
        case DW_CFA_def_cfa_expression:
+       case DW_CFA_expression:
          output_cfa_loc (cfi);
          break;
+
+       case DW_CFA_GNU_negative_offset_extended:
+         /* Obsoleted by DW_CFA_offset_extended_sf.  */
+         abort ();
+
        default:
          break;
        }
@@ -1717,12 +1913,17 @@ output_call_frame_info (for_eh)
   int per_encoding = DW_EH_PE_absptr;
   int lsda_encoding = DW_EH_PE_absptr;
 
-  /* If we don't have any functions we'll want to unwind out of, don't
-     emit any EH unwind information.  */
+  /* Don't emit a CIE if there won't be any FDEs.  */
+  if (fde_table_in_use == 0)
+    return;
+
+  /* If we don't have any functions we'll want to unwind out of, don't emit any
+     EH unwind information.  */
   if (for_eh)
     {
-      int any_eh_needed = 0;
-      for (i = 0; i < fde_table_in_use; ++i)
+      int any_eh_needed = flag_asynchronous_unwind_tables;
+
+      for (i = 0; i < fde_table_in_use; i++)
        if (fde_table[i].uses_eh_lsda)
          any_eh_needed = any_lsda_needed = 1;
        else if (! fde_table[i].nothrow)
@@ -1737,18 +1938,7 @@ output_call_frame_info (for_eh)
     app_enable ();
 
   if (for_eh)
-    {
-#ifdef EH_FRAME_SECTION_NAME
-      named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
-#else
-      tree label = get_file_function_name ('F');
-
-      data_section ();
-      ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
-      ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
-      ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
-#endif
-    }
+    (*targetm.asm_out.eh_frame_section) ();
   else
     named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
 
@@ -1809,7 +1999,7 @@ output_call_frame_info (for_eh)
       if (p > augmentation + 1)
        {
          augmentation[0] = 'z';
-          *p = '\0';
+         *p = '\0';
        }
 
       /* Ug.  Some platforms can't do unaligned dynamic relocations at all.  */
@@ -1834,13 +2024,11 @@ output_call_frame_info (for_eh)
            abort ();
        }
     }
-  dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
 
+  dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
   dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
-
   dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
                               "CIE Data Alignment Factor");
-
   dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
 
   if (augmentation[0])
@@ -1853,9 +2041,11 @@ output_call_frame_info (for_eh)
          dw2_asm_output_encoded_addr_rtx (per_encoding,
                                           eh_personality_libfunc, NULL);
        }
+
       if (any_lsda_needed)
        dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
                             eh_data_format_name (lsda_encoding));
+
       if (fde_encoding != DW_EH_PE_absptr)
        dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
                             eh_data_format_name (fde_encoding));
@@ -1865,20 +2055,22 @@ output_call_frame_info (for_eh)
     output_cfi (cfi, NULL, for_eh);
 
   /* Pad the CIE out to an address sized boundary.  */
-  ASM_OUTPUT_ALIGN (asm_out_file, 
+  ASM_OUTPUT_ALIGN (asm_out_file,
                    floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
   ASM_OUTPUT_LABEL (asm_out_file, l2);
 
   /* Loop through all of the FDE's.  */
-  for (i = 0; i < fde_table_in_use; ++i)
+  for (i = 0; i < fde_table_in_use; i++)
     {
       fde = &fde_table[i];
 
       /* Don't emit EH unwind info for leaf functions that don't need it.  */
-      if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
+      if (!flag_asynchronous_unwind_tables && for_eh
+         && (fde->nothrow || fde->all_throwers_are_sibcalls)
+         && !fde->uses_eh_lsda)
        continue;
 
-      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
+      (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
       ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
       ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
       dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
@@ -1897,15 +2089,15 @@ output_call_frame_info (for_eh)
                   gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
                   "FDE initial location");
          dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
-                               fde->dw_fde_end, fde->dw_fde_begin, 
+                               fde->dw_fde_end, fde->dw_fde_begin,
                                "FDE address range");
        }
       else
        {
          dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
                               "FDE initial location");
-         dw2_asm_output_delta (DWARF2_ADDR_SIZE, 
-                               fde->dw_fde_end, fde->dw_fde_begin, 
+         dw2_asm_output_delta (DWARF2_ADDR_SIZE,
+                               fde->dw_fde_end, fde->dw_fde_begin,
                                "FDE address range");
        }
 
@@ -1931,19 +2123,20 @@ output_call_frame_info (for_eh)
              dw2_asm_output_data_uleb128 (size, "Augmentation size");
 
              if (fde->uses_eh_lsda)
-               {
-                 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
+               {
+                 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
                                               fde->funcdef_number);
-                 dw2_asm_output_encoded_addr_rtx (
+                 dw2_asm_output_encoded_addr_rtx (
                        lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
                        "Language Specific Data Area");
-               }
+               }
              else
                {
                  if (lsda_encoding == DW_EH_PE_aligned)
                    ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
-                 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
-                                      0, "Language Specific Data Area (none)");
+                 dw2_asm_output_data
+                   (size_of_encoded_value (lsda_encoding), 0,
+                    "Language Specific Data Area (none)");
                }
            }
          else
@@ -1957,15 +2150,13 @@ output_call_frame_info (for_eh)
        output_cfi (cfi, fde, for_eh);
 
       /* Pad the FDE out to an address sized boundary.  */
-      ASM_OUTPUT_ALIGN (asm_out_file, 
-                       floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
+      ASM_OUTPUT_ALIGN (asm_out_file,
+                       floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
       ASM_OUTPUT_LABEL (asm_out_file, l2);
     }
 
-#ifndef EH_FRAME_SECTION_NAME
-  if (for_eh)
+  if (for_eh && targetm.terminate_dw2_eh_frame_info)
     dw2_asm_output_data (4, 0, "End of Table");
-#endif
 #ifdef MIPS_DEBUGGING_INFO
   /* Work around Irix 6 assembler bug whereby labels at the end of a section
      get a value of 0.  Putting .align 0 after the label fixes it.  */
@@ -2002,13 +2193,11 @@ dwarf2out_begin_prologue (line, file)
     return;
 #endif
 
-  ++current_funcdef_number;
-
   function_section (current_function_decl);
   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
-                              current_funcdef_number);
+                              current_function_funcdef_no);
   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
-                         current_funcdef_number);
+                         current_function_funcdef_no);
   current_function_func_begin_label = get_identifier (label);
 
 #ifdef IA64_UNWIND_INFO
@@ -2021,9 +2210,10 @@ dwarf2out_begin_prologue (line, file)
   if (fde_table_in_use == fde_table_allocated)
     {
       fde_table_allocated += FDE_TABLE_INCREMENT;
-      fde_table
-       = (dw_fde_ref) xrealloc (fde_table,
-                                fde_table_allocated * sizeof (dw_fde_node));
+      fde_table = ggc_realloc (fde_table,
+                              fde_table_allocated * sizeof (dw_fde_node));
+      memset (fde_table + fde_table_in_use, 0,
+             FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
     }
 
   /* Record the FDE associated with this function.  */
@@ -2035,14 +2225,15 @@ dwarf2out_begin_prologue (line, file)
   fde->dw_fde_current_label = NULL;
   fde->dw_fde_end = NULL;
   fde->dw_fde_cfi = NULL;
-  fde->funcdef_number = current_funcdef_number;
+  fde->funcdef_number = current_function_funcdef_no;
   fde->nothrow = current_function_nothrow;
   fde->uses_eh_lsda = cfun->uses_eh_lsda;
+  fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
 
   args_size = old_args_size = 0;
 
-  /* We only want to output line number information for the genuine
-     dwarf2 prologue case, not the eh frame case.  */
+  /* We only want to output line number information for the genuine dwarf2
+     prologue case, not the eh frame case.  */
 #ifdef DWARF2_DEBUGGING_INFO
   if (file)
     dwarf2out_source_line (line, file);
@@ -2054,14 +2245,17 @@ dwarf2out_begin_prologue (line, file)
    been generated.  */
 
 void
-dwarf2out_end_epilogue ()
+dwarf2out_end_epilogue (line, file)
+     unsigned int line ATTRIBUTE_UNUSED;
+     const char *file ATTRIBUTE_UNUSED;
 {
   dw_fde_ref fde;
   char label[MAX_ARTIFICIAL_LABEL_BYTES];
 
   /* Output a label to mark the endpoint of the code generated for this
-     function.        */
-  ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
+     function.  */
+  ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
+                              current_function_funcdef_no);
   ASM_OUTPUT_LABEL (asm_out_file, label);
   fde = &fde_table[fde_table_in_use - 1];
   fde->dw_fde_end = xstrdup (label);
@@ -2071,7 +2265,8 @@ void
 dwarf2out_frame_init ()
 {
   /* Allocate the initial hunk of the fde_table.  */
-  fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
+  fde_table = (dw_fde_ref) ggc_alloc_cleared (FDE_TABLE_INCREMENT
+                                             * sizeof (dw_fde_node));
   fde_table_allocated = FDE_TABLE_INCREMENT;
   fde_table_in_use = 0;
 
@@ -2089,15 +2284,22 @@ void
 dwarf2out_frame_finish ()
 {
   /* Output call frame information.  */
-  if (write_symbols == DWARF2_DEBUG)
+  if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
     output_call_frame_info (0);
+
   if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
     output_call_frame_info (1);
 }
+#endif
 \f
 /* And now, the subset of the debugging information support code necessary
    for emitting location expressions.  */
 
+/* We need some way to distinguish DW_OP_addr with a direct symbol
+   relocation from DW_OP_addr with a dtp-relative symbol relocation.  */
+#define INTERNAL_DW_OP_tls_addr                (0x100 + DW_OP_addr)
+
+
 typedef struct dw_val_struct *dw_val_ref;
 typedef struct die_struct *dw_die_ref;
 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
@@ -2107,12 +2309,13 @@ typedef struct dw_loc_list_struct *dw_loc_list_ref;
    can take on several forms.  The forms that are used in this
    implementation are listed below.  */
 
-typedef enum
+enum dw_val_class
 {
   dw_val_class_addr,
   dw_val_class_offset,
   dw_val_class_loc,
   dw_val_class_loc_list,
+  dw_val_class_range_list,
   dw_val_class_const,
   dw_val_class_unsigned_const,
   dw_val_class_long_long,
@@ -2123,13 +2326,12 @@ typedef enum
   dw_val_class_lbl_id,
   dw_val_class_lbl_offset,
   dw_val_class_str
-}
-dw_val_class;
+};
 
 /* Describe a double word constant value.  */
 /* ??? Every instance of long_long in the code really means CONST_DOUBLE.  */
 
-typedef struct dw_long_long_struct
+typedef struct dw_long_long_struct GTY(())
 {
   unsigned long hi;
   unsigned long low;
@@ -2138,9 +2340,9 @@ dw_long_long_const;
 
 /* Describe a floating point constant value.  */
 
-typedef struct dw_fp_struct
+typedef struct dw_fp_struct GTY(())
 {
-  long *array;
+  long * GTY((length ("%h.length"))) array;
   unsigned length;
 }
 dw_float_const;
@@ -2148,36 +2350,37 @@ dw_float_const;
 /* The dw_val_node describes an attribute's value, as it is
    represented internally.  */
 
-typedef struct dw_val_struct
-{
-  dw_val_class val_class;
-  union
-    {
-      rtx val_addr;
-      long unsigned val_offset;
-      dw_loc_list_ref  val_loc_list;
-      dw_loc_descr_ref val_loc;
-      long int val_int;
-      long unsigned val_unsigned;
-      dw_long_long_const val_long_long;
-      dw_float_const val_float;
-      struct {
-       dw_die_ref die;
-       int external;
-      } val_die_ref;
-      unsigned val_fde_index;
-      char *val_str;
-      char *val_lbl_id;
-      unsigned char val_flag;
-    }
-  v;
+typedef struct dw_val_struct GTY(())
+{
+  enum dw_val_class val_class;
+  union dw_val_struct_union
+    {
+      rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
+      long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
+      dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
+      dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
+      long int GTY ((default (""))) val_int;
+      long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
+      dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
+      dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
+      struct dw_val_die_union
+       {
+         dw_die_ref die;
+         int external;
+       } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
+      unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
+      struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
+      char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
+      unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
+    }
+  GTY ((desc ("%1.val_class"))) v;
 }
 dw_val_node;
 
 /* Locations in memory are described using a sequence of stack machine
    operations.  */
 
-typedef struct dw_loc_descr_struct
+typedef struct dw_loc_descr_struct GTY(())
 {
   dw_loc_descr_ref dw_loc_next;
   enum dwarf_location_atom dw_loc_opc;
@@ -2190,16 +2393,19 @@ dw_loc_descr_node;
 /* Location lists are ranges + location descriptions for that range,
    so you can track variables that are in different places over
    their entire life.  */
-typedef struct dw_loc_list_struct
+typedef struct dw_loc_list_struct GTY(())
 {
   dw_loc_list_ref dw_loc_next;
   const char *begin; /* Label for begin address of range */
   const char *end;  /* Label for end address of range */
-  char *ll_symbol; /* Label for beginning of location list. Only on head of list */
+  char *ll_symbol; /* Label for beginning of location list.
+                     Only on head of list */
   const char *section; /* Section this loclist is relative to */
   dw_loc_descr_ref expr;
 } dw_loc_list_node;
 
+#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
+
 static const char *dwarf_stack_op_name PARAMS ((unsigned));
 static dw_loc_descr_ref new_loc_descr  PARAMS ((enum dwarf_location_atom,
                                                 unsigned long,
@@ -2220,6 +2426,7 @@ dwarf_stack_op_name (op)
   switch (op)
     {
     case DW_OP_addr:
+    case INTERNAL_DW_OP_tls_addr:
       return "DW_OP_addr";
     case DW_OP_deref:
       return "DW_OP_deref";
@@ -2509,6 +2716,16 @@ dwarf_stack_op_name (op)
       return "DW_OP_xderef_size";
     case DW_OP_nop:
       return "DW_OP_nop";
+    case DW_OP_push_object_address:
+      return "DW_OP_push_object_address";
+    case DW_OP_call2:
+      return "DW_OP_call2";
+    case DW_OP_call4:
+      return "DW_OP_call4";
+    case DW_OP_call_ref:
+      return "DW_OP_call_ref";
+    case DW_OP_GNU_push_tls_address:
+      return "DW_OP_GNU_push_tls_address";
     default:
       return "OP_<unknown>";
     }
@@ -2524,10 +2741,8 @@ new_loc_descr (op, oprnd1, oprnd2)
      unsigned long oprnd1;
      unsigned long oprnd2;
 {
-  /* Use xcalloc here so we clear out all of the long_long constant in
-     the union.  */
   dw_loc_descr_ref descr
-    = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
+    = (dw_loc_descr_ref) ggc_alloc_cleared (sizeof (dw_loc_descr_node));
 
   descr->dw_loc_opc = op;
   descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
@@ -2566,6 +2781,7 @@ size_of_loc_descr (loc)
   switch (loc->dw_loc_opc)
     {
     case DW_OP_addr:
+    case INTERNAL_DW_OP_tls_addr:
       size += DWARF2_ADDR_SIZE;
       break;
     case DW_OP_const1u:
@@ -2651,7 +2867,16 @@ size_of_loc_descr (loc)
     case DW_OP_xderef_size:
       size += 1;
       break;
-    default:
+    case DW_OP_call2:
+      size += 2;
+      break;
+    case DW_OP_call4:
+      size += 4;
+      break;
+    case DW_OP_call_ref:
+      size += DWARF2_ADDR_SIZE;
+      break;
+    default:
       break;
     }
 
@@ -2664,9 +2889,9 @@ static unsigned long
 size_of_locs (loc)
      dw_loc_descr_ref loc;
 {
-  unsigned long size = 0;
+  unsigned long size;
 
-  for (; loc != NULL; loc = loc->dw_loc_next)
+  for (size = 0; loc != NULL; loc = loc->dw_loc_next)
     {
       loc->dw_loc_addr = size;
       size += size_of_loc_descr (loc);
@@ -2728,9 +2953,9 @@ output_loc_operands (loc)
     case DW_OP_skip:
     case DW_OP_bra:
       /* We currently don't make any attempt to make sure these are
-         aligned properly like we do for the main unwind info, so
-         don't support emitting things larger than a byte if we're
-         only doing unwinding.  */
+        aligned properly like we do for the main unwind info, so
+        don't support emitting things larger than a byte if we're
+        only doing unwinding.  */
       abort ();
 #endif
     case DW_OP_const1u:
@@ -2800,6 +3025,17 @@ output_loc_operands (loc)
     case DW_OP_xderef_size:
       dw2_asm_output_data (1, val1->v.val_int, NULL);
       break;
+
+    case INTERNAL_DW_OP_tls_addr:
+#ifdef ASM_OUTPUT_DWARF_DTPREL
+      ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
+                              val1->v.val_addr);
+      fputc ('\n', asm_out_file);
+#else
+      abort ();
+#endif
+      break;
+
     default:
       /* Other codes have no operands.  */
       break;
@@ -2865,6 +3101,7 @@ build_cfa_loc (cfa)
     head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
   else
     head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
+
   head->dw_loc_oprnd1.val_class = dw_val_class_const;
   tmp = new_loc_descr (DW_OP_deref, 0, 0);
   add_loc_descr (&head, tmp);
@@ -2873,11 +3110,12 @@ build_cfa_loc (cfa)
       tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
       add_loc_descr (&head, tmp);
     }
+
   return head;
 }
 
-/* This function fills in aa dw_cfa_location structure from a
-   dwarf location descriptor sequence.  */
+/* This function fills in aa dw_cfa_location structure from a dwarf location
+   descriptor sequence.  */
 
 static void
 get_cfa_from_loc_descr (cfa, loc)
@@ -2893,6 +3131,7 @@ get_cfa_from_loc_descr (cfa, loc)
   for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
     {
       enum dwarf_location_atom op = ptr->dw_loc_opc;
+
       switch (op)
        {
        case DW_OP_reg0:
@@ -2978,7 +3217,7 @@ get_cfa_from_loc_descr (cfa, loc)
          cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
          break;
        default:
-         internal_error ("DW_LOC_OP %s not implememnted\n",
+         internal_error ("DW_LOC_OP %s not implemented\n",
                          dwarf_stack_op_name (ptr->dw_loc_opc));
        }
     }
@@ -2988,6 +3227,9 @@ get_cfa_from_loc_descr (cfa, loc)
 /* And now, the support for symbolic debugging information.  */
 #ifdef DWARF2_DEBUGGING_INFO
 
+/* .debug_str support.  */
+static int output_indirect_string      PARAMS ((void **, void *));
+
 static void dwarf2out_init             PARAMS ((const char *));
 static void dwarf2out_finish           PARAMS ((const char *));
 static void dwarf2out_define           PARAMS ((unsigned int, const char *));
@@ -3002,7 +3244,7 @@ static void dwarf2out_abstract_function PARAMS ((tree));
 
 /* The debug hooks structure.  */
 
-struct gcc_debug_hooks dwarf2_debug_hooks =
+const struct gcc_debug_hooks dwarf2_debug_hooks =
 {
   dwarf2out_init,
   dwarf2out_finish,
@@ -3015,7 +3257,7 @@ struct gcc_debug_hooks dwarf2_debug_hooks =
   dwarf2out_ignore_block,
   dwarf2out_source_line,
   dwarf2out_begin_prologue,
-  debug_nothing_int,           /* end_prologue */
+  debug_nothing_int_charstar,  /* end_prologue */
   dwarf2out_end_epilogue,
   debug_nothing_tree,          /* begin_function */
   debug_nothing_int,           /* end_function */
@@ -3028,6 +3270,7 @@ struct gcc_debug_hooks dwarf2_debug_hooks =
   dwarf2out_abstract_function, /* outlining_inline_function */
   debug_nothing_rtx            /* label */
 };
+#endif
 \f
 /* NOTE: In the comments in this file, many references are made to
    "Debugging Information Entries".  This term is abbreviated as `DIE'
@@ -3056,7 +3299,7 @@ typedef struct dw_ranges_struct *dw_ranges_ref;
    entry.  The label gives the PC value associated with
    the line number entry.  */
 
-typedef struct dw_line_info_struct
+typedef struct dw_line_info_struct GTY(())
 {
   unsigned long dw_file_num;
   unsigned long dw_line_num;
@@ -3065,7 +3308,7 @@ dw_line_info_entry;
 
 /* Line information for functions in separate sections; each one gets its
    own sequence.  */
-typedef struct dw_separate_line_info_struct
+typedef struct dw_separate_line_info_struct GTY(())
 {
   unsigned long dw_file_num;
   unsigned long dw_line_num;
@@ -3077,7 +3320,7 @@ dw_separate_line_info_entry;
    a link to the next attribute in the chain, and an attribute value.
    Attributes are typically linked below the DIE they modify.  */
 
-typedef struct dw_attr_struct
+typedef struct dw_attr_struct GTY(())
 {
   enum dwarf_attribute dw_attr;
   dw_attr_ref dw_attr_next;
@@ -3087,7 +3330,7 @@ dw_attr_node;
 
 /* The Debugging Information Entry (DIE) structure */
 
-typedef struct die_struct
+typedef struct die_struct GTY(())
 {
   enum dwarf_tag die_tag;
   char *die_symbol;
@@ -3103,22 +3346,23 @@ die_node;
 
 /* The pubname structure */
 
-typedef struct pubname_struct
+typedef struct pubname_struct GTY(())
 {
   dw_die_ref die;
   char *name;
 }
 pubname_entry;
 
-struct dw_ranges_struct
+struct dw_ranges_struct GTY(())
 {
   int block_num;
 };
 
 /* The limbo die list structure.  */
-typedef struct limbo_die_struct
+typedef struct limbo_die_struct GTY(())
 {
   dw_die_ref die;
+  tree created_for;
   struct limbo_die_struct *next;
 }
 limbo_die_node;
@@ -3128,7 +3372,7 @@ limbo_die_node;
 #define ASM_COMMENT_START ";#"
 #endif
 
-/* Define a macro which returns non-zero for a TYPE_DECL which was
+/* Define a macro which returns nonzero for a TYPE_DECL which was
    implicitly generated for a tagged type.
 
    Note that unlike the gcc front end (which generates a NULL named
@@ -3152,14 +3396,9 @@ limbo_die_node;
 /* Information concerning the compilation unit's programming
    language, and compiler version.  */
 
-extern int flag_traditional;
-
 /* Fixed size portion of the DWARF compilation unit header.  */
 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
 
-/* Fixed size portion of debugging line information prolog.  */
-#define DWARF_LINE_PROLOG_HEADER_SIZE 5
-
 /* Fixed size portion of public names info.  */
 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
 
@@ -3183,22 +3422,11 @@ extern int flag_traditional;
 #endif
 #endif
 
-/* Define the architecture-dependent minimum instruction length (in bytes).
-   In this implementation of DWARF, this field is used for information
-   purposes only.  Since GCC generates assembly language, we have
-   no a priori knowledge of how many instruction bytes are generated
-   for each source line, and therefore can use only the  DW_LNE_set_address
-   and DW_LNS_fixed_advance_pc line information commands.  */
-
-#ifndef DWARF_LINE_MIN_INSTR_LENGTH
-#define DWARF_LINE_MIN_INSTR_LENGTH 4
-#endif
-
 /* Minimum line offset in a special line info. opcode.
    This value was chosen to give a reasonable range of values.  */
 #define DWARF_LINE_BASE  -10
 
-/* First special line opcde - leave room for the standard opcodes.  */
+/* First special line opcode - leave room for the standard opcodes.  */
 #define DWARF_LINE_OPCODE_BASE  10
 
 /* Range of line offsets in a special line info. opcode.  */
@@ -3210,68 +3438,59 @@ extern int flag_traditional;
    is not made available by the GCC front-end.  */
 #define        DWARF_LINE_DEFAULT_IS_STMT_START 1
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* This location is used by calc_die_sizes() to keep track
    the offset of each DIE within the .debug_info section.  */
 static unsigned long next_die_offset;
+#endif
 
 /* Record the root of the DIE's built for the current compilation unit.  */
-static dw_die_ref comp_unit_die;
+static GTY(()) dw_die_ref comp_unit_die;
 
-/* A list of DIEs with a NULL parent waiting to be relocated.  */
-static limbo_die_node *limbo_die_list = 0;
-
-/* Structure used by lookup_filename to manage sets of filenames.  */
-struct file_table
-{
-  char **table;
-  unsigned allocated;
-  unsigned in_use;
-  unsigned last_lookup_index;
-};
+#ifdef DWARF2_DEBUGGING_INFO
+/* We need special handling in dwarf2out_start_source_file if it is
+   first one.  */
+static int is_main_source;
+#endif
 
-/* Size (in elements) of increments by which we may expand the filename
-   table.  */
-#define FILE_TABLE_INCREMENT 64
+/* A list of DIEs with a NULL parent waiting to be relocated.  */
+static GTY(()) limbo_die_node *limbo_die_list;
 
 /* Filenames referenced by this compilation unit.  */
-static struct file_table file_table;
-
-/* Local pointer to the name of the main input file.  Initialized in
-   dwarf2out_init.  */
-static const char *primary_filename;
+static GTY(()) varray_type file_table;
+static GTY(()) varray_type file_table_emitted;
+static GTY(()) size_t file_table_last_lookup_index;
 
 /* A pointer to the base of a table of references to DIE's that describe
    declarations.  The table is indexed by DECL_UID() which is a unique
    number identifying each decl.  */
-static dw_die_ref *decl_die_table;
+static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
 
 /* Number of elements currently allocated for the decl_die_table.  */
 static unsigned decl_die_table_allocated;
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* Number of elements in decl_die_table currently in use.  */
 static unsigned decl_die_table_in_use;
+#endif
 
 /* Size (in elements) of increments by which we may expand the
    decl_die_table.  */
 #define DECL_DIE_TABLE_INCREMENT 256
 
-/* A pointer to the base of a table of references to declaration
-   scopes.  This table is a display which tracks the nesting
-   of declaration scopes at the current scope and containing
-   scopes.  This table is used to find the proper place to
-   define type declaration DIE's.  */
-varray_type decl_scope_table;
-
 /* A pointer to the base of a list of references to DIE's that
    are uniquely identified by their tag, presence/absence of
    children DIE's, and list of attribute/value pairs.  */
-static dw_die_ref *abbrev_die_table;
+static GTY((length ("abbrev_die_table_allocated"))) 
+  dw_die_ref *abbrev_die_table;
 
 /* Number of elements currently allocated for abbrev_die_table.  */
 static unsigned abbrev_die_table_allocated;
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* Number of elements in type_die_table currently in use.  */
 static unsigned abbrev_die_table_in_use;
+#endif
 
 /* Size (in elements) of increments by which we may expand the
    abbrev_die_table.  */
@@ -3279,23 +3498,29 @@ static unsigned abbrev_die_table_in_use;
 
 /* A pointer to the base of a table that contains line information
    for each source code line in .text in the compilation unit.  */
-static dw_line_info_ref line_info_table;
+static GTY((length ("line_info_table_allocated"))) 
+     dw_line_info_ref line_info_table;
 
 /* Number of elements currently allocated for line_info_table.  */
 static unsigned line_info_table_allocated;
 
-/* Number of elements in separate_line_info_table currently in use.  */
-static unsigned separate_line_info_table_in_use;
+#ifdef DWARF2_DEBUGGING_INFO
+/* Number of elements in line_info_table currently in use.  */
+static unsigned line_info_table_in_use;
+#endif
 
 /* A pointer to the base of a table that contains line information
    for each source code line outside of .text in the compilation unit.  */
-static dw_separate_line_info_ref separate_line_info_table;
+static GTY ((length ("separate_line_info_table_allocated")))
+     dw_separate_line_info_ref separate_line_info_table;
 
 /* Number of elements currently allocated for separate_line_info_table.  */
 static unsigned separate_line_info_table_allocated;
 
-/* Number of elements in line_info_table currently in use.  */
-static unsigned line_info_table_in_use;
+#ifdef DWARF2_DEBUGGING_INFO
+/* Number of elements in separate_line_info_table currently in use.  */
+static unsigned separate_line_info_table_in_use;
+#endif
 
 /* Size (in elements) of increments by which we may expand the
    line_info_table.  */
@@ -3303,37 +3528,42 @@ static unsigned line_info_table_in_use;
 
 /* A pointer to the base of a table that contains a list of publicly
    accessible names.  */
-static pubname_ref pubname_table;
+static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
 
 /* Number of elements currently allocated for pubname_table.  */
 static unsigned pubname_table_allocated;
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* Number of elements in pubname_table currently in use.  */
 static unsigned pubname_table_in_use;
+#endif
 
 /* Size (in elements) of increments by which we may expand the
    pubname_table.  */
 #define PUBNAME_TABLE_INCREMENT 64
 
 /* Array of dies for which we should generate .debug_arange info.  */
-static dw_die_ref *arange_table;
+static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
 
 /* Number of elements currently allocated for arange_table.  */
 static unsigned arange_table_allocated;
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* Number of elements in arange_table currently in use.  */
 static unsigned arange_table_in_use;
+#endif
 
 /* Size (in elements) of increments by which we may expand the
    arange_table.  */
 #define ARANGE_TABLE_INCREMENT 64
 
 /* Array of dies for which we should generate .debug_ranges info.  */
-static dw_ranges_ref ranges_table;
+static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
 
 /* Number of elements currently allocated for ranges_table.  */
 static unsigned ranges_table_allocated;
 
+#ifdef DWARF2_DEBUGGING_INFO
 /* Number of elements in ranges_table currently in use.  */
 static unsigned ranges_table_in_use;
 
@@ -3344,24 +3574,14 @@ static unsigned ranges_table_in_use;
 /* Whether we have location lists that need outputting */
 static unsigned have_location_lists;
 
-/* A pointer to the base of a list of incomplete types which might be
-   completed at some later time.  incomplete_types_list needs to be a VARRAY
-   because we want to tell the garbage collector about it.  If we don't tell
-   the garbage collector about it, we can garbage collect live data.
-   Bug 4215.*/
-varray_type incomplete_types;
-
 /* Record whether the function being analyzed contains inlined functions.  */
 static int current_function_has_inlines;
+#endif
 #if 0 && defined (MIPS_DEBUGGING_INFO)
 static int comp_unit_has_inlines;
 #endif
 
-/* Array of RTXes referenced by the debugging information, which therefore
-   must be kept around forever.  We do this rather than perform GC on
-   the dwarf info because almost all of the dwarf info lives forever, and
-   it's easier to support non-GC frontends this way.  */
-static varray_type used_rtx_varray;
+#ifdef DWARF2_DEBUGGING_INFO
 
 /* Forward declarations for functions defined in this file.  */
 
@@ -3378,14 +3598,18 @@ static tree decl_ultimate_origin        PARAMS ((tree));
 static tree block_ultimate_origin      PARAMS ((tree));
 static tree decl_class_context         PARAMS ((tree));
 static void add_dwarf_attr             PARAMS ((dw_die_ref, dw_attr_ref));
+static inline enum dw_val_class AT_class       PARAMS ((dw_attr_ref));
 static void add_AT_flag                        PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned));
+static inline unsigned AT_flag         PARAMS ((dw_attr_ref));
 static void add_AT_int                 PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute, long));
+static inline long int AT_int          PARAMS ((dw_attr_ref));
 static void add_AT_unsigned            PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned long));
+static inline unsigned long            AT_unsigned PARAMS ((dw_attr_ref));
 static void add_AT_long_long           PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned long,
@@ -3393,24 +3617,34 @@ static void add_AT_long_long            PARAMS ((dw_die_ref,
 static void add_AT_float               PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned, long *));
+static hashval_t debug_str_do_hash     PARAMS ((const void *));
+static int debug_str_eq                        PARAMS ((const void *, const void *));
 static void add_AT_string              PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 const char *));
+static inline const char *AT_string    PARAMS ((dw_attr_ref));
+static int AT_string_form              PARAMS ((dw_attr_ref));
 static void add_AT_die_ref             PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 dw_die_ref));
+static inline dw_die_ref AT_ref                PARAMS ((dw_attr_ref));
+static inline int AT_ref_external      PARAMS ((dw_attr_ref));
+static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
 static void add_AT_fde_ref             PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned));
 static void add_AT_loc                 PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 dw_loc_descr_ref));
+static inline dw_loc_descr_ref AT_loc  PARAMS ((dw_attr_ref));
 static void add_AT_loc_list            PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 dw_loc_list_ref));
+static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
 static void add_AT_addr                        PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 rtx));
+static inline rtx AT_addr              PARAMS ((dw_attr_ref));
 static void add_AT_lbl_id              PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 const char *));
@@ -3420,6 +3654,10 @@ static void add_AT_lbl_offset            PARAMS ((dw_die_ref,
 static void add_AT_offset              PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute,
                                                 unsigned long));
+static void add_AT_range_list          PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned long));
+static inline const char *AT_lbl       PARAMS ((dw_attr_ref));
 static dw_attr_ref get_AT              PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute));
 static const char *get_AT_low_pc       PARAMS ((dw_die_ref));
@@ -3433,13 +3671,16 @@ static unsigned get_AT_unsigned         PARAMS ((dw_die_ref,
 static inline dw_die_ref get_AT_ref    PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute));
 static int is_c_family                 PARAMS ((void));
+static int is_cxx                      PARAMS ((void));
 static int is_java                     PARAMS ((void));
 static int is_fortran                  PARAMS ((void));
 static void remove_AT                  PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute));
+static inline void free_die            PARAMS ((dw_die_ref));
 static void remove_children            PARAMS ((dw_die_ref));
 static void add_child_die              PARAMS ((dw_die_ref, dw_die_ref));
-static dw_die_ref new_die              PARAMS ((enum dwarf_tag, dw_die_ref));
+static dw_die_ref new_die              PARAMS ((enum dwarf_tag, dw_die_ref,
+                                                tree));
 static dw_die_ref lookup_type_die      PARAMS ((tree));
 static void equate_type_number_to_die  PARAMS ((tree, dw_die_ref));
 static dw_die_ref lookup_decl_die      PARAMS ((tree));
@@ -3451,24 +3692,41 @@ static void reverse_die_lists           PARAMS ((dw_die_ref));
 static void reverse_all_dies           PARAMS ((dw_die_ref));
 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
 static dw_die_ref pop_compile_unit     PARAMS ((dw_die_ref));
-static void loc_checksum        PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
-static void attr_checksum            PARAMS ((dw_attr_ref, struct md5_ctx *));
-static void die_checksum              PARAMS ((dw_die_ref, struct md5_ctx *));
+static void loc_checksum               PARAMS ((dw_loc_descr_ref,
+                                                struct md5_ctx *));
+static void attr_checksum              PARAMS ((dw_attr_ref,
+                                                struct md5_ctx *,
+                                                int *));
+static void die_checksum               PARAMS ((dw_die_ref,
+                                                struct md5_ctx *,
+                                                int *));
+static int same_loc_p                  PARAMS ((dw_loc_descr_ref,
+                                                dw_loc_descr_ref, int *));
+static int same_dw_val_p               PARAMS ((dw_val_node *, dw_val_node *,
+                                                int *));
+static int same_attr_p                 PARAMS ((dw_attr_ref, dw_attr_ref, int *));
+static int same_die_p                  PARAMS ((dw_die_ref, dw_die_ref, int *));
+static int same_die_p_wrap             PARAMS ((dw_die_ref, dw_die_ref));
 static void compute_section_prefix     PARAMS ((dw_die_ref));
 static int is_type_die                 PARAMS ((dw_die_ref));
 static int is_comdat_die               PARAMS ((dw_die_ref));
 static int is_symbol_die               PARAMS ((dw_die_ref));
 static void assign_symbol_names                PARAMS ((dw_die_ref));
 static void break_out_includes         PARAMS ((dw_die_ref));
+static hashval_t htab_cu_hash          PARAMS ((const void *));
+static int htab_cu_eq                  PARAMS ((const void *, const void *));
+static void htab_cu_del                        PARAMS ((void *));
+static int check_duplicate_cu          PARAMS ((dw_die_ref, htab_t, unsigned *));
+static void record_comdat_symbol_number        PARAMS ((dw_die_ref, htab_t, unsigned));
 static void add_sibling_attributes     PARAMS ((dw_die_ref));
 static void build_abbrev_table         PARAMS ((dw_die_ref));
 static void output_location_lists      PARAMS ((dw_die_ref));
-static unsigned long size_of_string    PARAMS ((const char *));
 static int constant_size               PARAMS ((long unsigned));
 static unsigned long size_of_die       PARAMS ((dw_die_ref));
 static void calc_die_sizes             PARAMS ((dw_die_ref));
 static void mark_dies                  PARAMS ((dw_die_ref));
 static void unmark_dies                        PARAMS ((dw_die_ref));
+static void unmark_all_dies             PARAMS ((dw_die_ref));
 static unsigned long size_of_pubnames  PARAMS ((void));
 static unsigned long size_of_aranges   PARAMS ((void));
 static enum dwarf_form value_format    PARAMS ((dw_attr_ref));
@@ -3477,7 +3735,7 @@ static void output_abbrev_section PARAMS ((void));
 static void output_die_symbol          PARAMS ((dw_die_ref));
 static void output_die                 PARAMS ((dw_die_ref));
 static void output_compilation_unit_header PARAMS ((void));
-static void output_comp_unit           PARAMS ((dw_die_ref));
+static void output_comp_unit           PARAMS ((dw_die_ref, int));
 static const char *dwarf2_name         PARAMS ((tree, int));
 static void add_pubname                        PARAMS ((tree, dw_die_ref));
 static void output_pubnames            PARAMS ((void));
@@ -3494,6 +3752,8 @@ static dw_die_ref modified_type_die       PARAMS ((tree, int, int, dw_die_ref));
 static int type_is_enum                        PARAMS ((tree));
 static unsigned int reg_number         PARAMS ((rtx));
 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
+static dw_loc_descr_ref one_reg_loc_descriptor PARAMS ((unsigned int));
+static dw_loc_descr_ref multiple_reg_loc_descriptor PARAMS ((rtx, rtx));
 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
 static dw_loc_descr_ref based_loc_descr        PARAMS ((unsigned, long));
 static int is_based_loc                        PARAMS ((rtx));
@@ -3508,13 +3768,15 @@ static unsigned int simple_decl_align_in_bits PARAMS ((tree));
 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
 static void add_AT_location_description        PARAMS ((dw_die_ref,
-                                                enum dwarf_attribute, rtx));
+                                                enum dwarf_attribute,
+                                                dw_loc_descr_ref));
 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
 static void add_const_value_attribute  PARAMS ((dw_die_ref, rtx));
 static rtx rtl_for_decl_location       PARAMS ((tree));
 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
 static void add_name_attribute         PARAMS ((dw_die_ref, const char *));
+static void add_comp_dir_attribute     PARAMS ((dw_die_ref));
 static void add_bound_info             PARAMS ((dw_die_ref,
                                                 enum dwarf_attribute, tree));
 static void add_subscript_info         PARAMS ((dw_die_ref, tree));
@@ -3527,8 +3789,10 @@ static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
 static void add_src_coords_attributes  PARAMS ((dw_die_ref, tree));
 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
 static void push_decl_scope            PARAMS ((tree));
-static dw_die_ref scope_die_for                PARAMS ((tree, dw_die_ref));
 static void pop_decl_scope             PARAMS ((void));
+static dw_die_ref scope_die_for                PARAMS ((tree, dw_die_ref));
+static inline int local_scope_p                PARAMS ((dw_die_ref));
+static inline int class_scope_p                PARAMS ((dw_die_ref));
 static void add_type_attribute         PARAMS ((dw_die_ref, tree, int, int,
                                                 dw_die_ref));
 static const char *type_tag            PARAMS ((tree));
@@ -3557,7 +3821,7 @@ static void gen_field_die         PARAMS ((tree, dw_die_ref));
 static void gen_ptr_to_mbr_type_die    PARAMS ((tree, dw_die_ref));
 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
 static void gen_string_type_die                PARAMS ((tree, dw_die_ref));
-static void gen_inheritance_die                PARAMS ((tree, dw_die_ref));
+static void gen_inheritance_die                PARAMS ((tree, tree, dw_die_ref));
 static void gen_member_die             PARAMS ((tree, dw_die_ref));
 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
 static void gen_subroutine_type_die    PARAMS ((tree, dw_die_ref));
@@ -3570,13 +3834,11 @@ static int is_redundant_typedef         PARAMS ((tree));
 static void gen_decl_die               PARAMS ((tree, dw_die_ref));
 static unsigned lookup_filename                PARAMS ((const char *));
 static void init_file_table            PARAMS ((void));
-static void add_incomplete_type                PARAMS ((tree));
 static void retry_incomplete_types     PARAMS ((void));
 static void gen_type_die_for_member    PARAMS ((tree, tree, dw_die_ref));
-static rtx save_rtx                    PARAMS ((rtx));
 static void splice_child_die           PARAMS ((dw_die_ref, dw_die_ref));
 static int file_info_cmp               PARAMS ((const void *, const void *));
-static dw_loc_list_ref new_loc_list     PARAMS ((dw_loc_descr_ref, 
+static dw_loc_list_ref new_loc_list     PARAMS ((dw_loc_descr_ref,
                                                 const char *, const char *,
                                                 const char *, unsigned));
 static void add_loc_descr_to_loc_list   PARAMS ((dw_loc_list_ref *,
@@ -3585,6 +3847,14 @@ static void add_loc_descr_to_loc_list   PARAMS ((dw_loc_list_ref *,
 static void output_loc_list            PARAMS ((dw_loc_list_ref));
 static char *gen_internal_sym          PARAMS ((const char *));
 
+static void prune_unmark_dies          PARAMS ((dw_die_ref));
+static void prune_unused_types_mark     PARAMS ((dw_die_ref, int));
+static void prune_unused_types_walk     PARAMS ((dw_die_ref));
+static void prune_unused_types_walk_attribs PARAMS ((dw_die_ref));
+static void prune_unused_types_prune    PARAMS ((dw_die_ref));
+static void prune_unused_types          PARAMS ((void));
+static int maybe_emit_file              PARAMS ((int));
+
 /* Section names used to hold DWARF debugging information.  */
 #ifndef DEBUG_INFO_SECTION
 #define DEBUG_INFO_SECTION     ".debug_info"
@@ -3619,6 +3889,14 @@ static char *gen_internal_sym            PARAMS ((const char *));
 #define TEXT_SECTION_NAME      ".text"
 #endif
 
+/* Section flags for .debug_str section.  */
+#ifdef HAVE_GAS_SHF_MERGE
+#define DEBUG_STR_SECTION_FLAGS \
+  (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
+#else
+#define DEBUG_STR_SECTION_FLAGS        SECTION_DEBUG
+#endif
+
 /* Labels we insert at beginning sections we can reference instead of
    the section names themselves.  */
 
@@ -3637,6 +3915,9 @@ static char *gen_internal_sym             PARAMS ((const char *));
 #ifndef DEBUG_LOC_SECTION_LABEL
 #define DEBUG_LOC_SECTION_LABEL                "Ldebug_loc"
 #endif
+#ifndef DEBUG_RANGES_SECTION_LABEL
+#define DEBUG_RANGES_SECTION_LABEL     "Ldebug_ranges"
+#endif
 #ifndef DEBUG_MACINFO_SECTION_LABEL
 #define DEBUG_MACINFO_SECTION_LABEL     "Ldebug_macinfo"
 #endif
@@ -3654,27 +3935,17 @@ static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
+static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
+
 #ifndef TEXT_END_LABEL
 #define TEXT_END_LABEL         "Letext"
 #endif
-#ifndef DATA_END_LABEL
-#define DATA_END_LABEL         "Ledata"
-#endif
-#ifndef BSS_END_LABEL
-#define BSS_END_LABEL           "Lebss"
-#endif
 #ifndef BLOCK_BEGIN_LABEL
 #define BLOCK_BEGIN_LABEL      "LBB"
 #endif
 #ifndef BLOCK_END_LABEL
 #define BLOCK_END_LABEL                "LBE"
 #endif
-#ifndef BODY_BEGIN_LABEL
-#define BODY_BEGIN_LABEL       "Lbb"
-#endif
-#ifndef BODY_END_LABEL
-#define BODY_END_LABEL         "Lbe"
-#endif
 #ifndef LINE_CODE_LABEL
 #define LINE_CODE_LABEL                "LM"
 #endif
@@ -3693,19 +3964,6 @@ dwarf2out_set_demangle_name_func (func)
 {
   demangle_name_func = func;
 }
-\f
-/* Return an rtx like ORIG which lives forever.  If we're doing GC,
-   that means adding it to used_rtx_varray.  If not, that means making
-   a copy on the permanent_obstack.  */
-
-static rtx
-save_rtx (orig)
-     rtx orig;
-{
-  VARRAY_PUSH_RTX (used_rtx_varray, orig);
-
-  return orig;
-}
 
 /* Test if rtl node points to a pseudo register.  */
 
@@ -3727,11 +3985,11 @@ type_main_variant (type)
 {
   type = TYPE_MAIN_VARIANT (type);
 
-  /* There really should be only one main variant among any group of variants
-     of a given type (and all of the MAIN_VARIANT values for all members of
-     the group should point to that one type) but sometimes the C front-end
-     messes this up for array types, so we work around that bug here.  */
-
+  /* ??? There really should be only one main variant among any group of
+     variants of a given type (and all of the MAIN_VARIANT values for all
+     members of the group should point to that one type) but sometimes the C
+     front-end messes this up for array types, so we work around that bug
+     here.  */
   if (TREE_CODE (type) == ARRAY_TYPE)
     while (type != TYPE_MAIN_VARIANT (type))
       type = TYPE_MAIN_VARIANT (type);
@@ -3739,7 +3997,7 @@ type_main_variant (type)
   return type;
 }
 
-/* Return non-zero if the given type node represents a tagged type.  */
+/* Return nonzero if the given type node represents a tagged type.  */
 
 static inline int
 is_tagged_type (type)
@@ -4065,6 +4323,12 @@ dwarf_attr_name (attr)
       return "DW_AT_body_begin";
     case DW_AT_body_end:
       return "DW_AT_body_end";
+    case DW_AT_GNU_vector:
+      return "DW_AT_GNU_vector";
+
+    case DW_AT_VMS_rtnbeg_pd_address:
+      return "DW_AT_VMS_rtnbeg_pd_address";
+
     default:
       return "DW_AT_<unknown>";
     }
@@ -4210,9 +4474,8 @@ block_ultimate_origin (block)
       do
        {
          ret_val = lookahead;
-         lookahead = (TREE_CODE (ret_val) == BLOCK)
-           ? BLOCK_ABSTRACT_ORIGIN (ret_val)
-           : NULL;
+         lookahead = (TREE_CODE (ret_val) == BLOCK
+                      ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
        }
       while (lookahead != NULL && lookahead != ret_val);
 
@@ -4257,8 +4520,7 @@ add_dwarf_attr (die, attr)
     }
 }
 
-static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
-static inline dw_val_class
+static inline enum dw_val_class
 AT_class (a)
      dw_attr_ref a;
 {
@@ -4273,7 +4535,7 @@ add_AT_flag (die, attr_kind, flag)
      enum dwarf_attribute attr_kind;
      unsigned flag;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4282,7 +4544,6 @@ add_AT_flag (die, attr_kind, flag)
   add_dwarf_attr (die, attr);
 }
 
-static inline unsigned AT_flag PARAMS ((dw_attr_ref));
 static inline unsigned
 AT_flag (a)
      dw_attr_ref a;
@@ -4301,7 +4562,7 @@ add_AT_int (die, attr_kind, int_val)
      enum dwarf_attribute attr_kind;
      long int int_val;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4310,7 +4571,6 @@ add_AT_int (die, attr_kind, int_val)
   add_dwarf_attr (die, attr);
 }
 
-static inline long int AT_int PARAMS ((dw_attr_ref));
 static inline long int
 AT_int (a)
      dw_attr_ref a;
@@ -4329,7 +4589,7 @@ add_AT_unsigned (die, attr_kind, unsigned_val)
      enum dwarf_attribute attr_kind;
      unsigned long unsigned_val;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4338,7 +4598,6 @@ add_AT_unsigned (die, attr_kind, unsigned_val)
   add_dwarf_attr (die, attr);
 }
 
-static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
 static inline unsigned long
 AT_unsigned (a)
      dw_attr_ref a;
@@ -4358,7 +4617,7 @@ add_AT_long_long (die, attr_kind, val_hi, val_low)
      unsigned long val_hi;
      unsigned long val_low;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4377,7 +4636,7 @@ add_AT_float (die, attr_kind, length, array)
      unsigned length;
      long *array;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4387,6 +4646,24 @@ add_AT_float (die, attr_kind, length, array)
   add_dwarf_attr (die, attr);
 }
 
+/* Hash and equality functions for debug_str_hash.  */
+
+static hashval_t
+debug_str_do_hash (x)
+     const void * x;
+{
+  return htab_hash_string (((const struct indirect_string_node *)x)->str);
+}
+
+static int
+debug_str_eq (x1, x2)
+     const void * x1;
+     const void * x2;
+{
+  return strcmp ((((const struct indirect_string_node *)x1)->str),
+                (const char *)x2) == 0;
+}
+
 /* Add a string attribute value to a DIE.  */
 
 static inline void
@@ -4395,22 +4672,76 @@ add_AT_string (die, attr_kind, str)
      enum dwarf_attribute attr_kind;
      const char *str;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
+  struct indirect_string_node *node;
+  PTR *slot;
+
+  if (! debug_str_hash)
+    debug_str_hash = htab_create_ggc (10, debug_str_do_hash, 
+                                     debug_str_eq, NULL);
+
+  slot = htab_find_slot_with_hash (debug_str_hash, str,
+                                  htab_hash_string (str), INSERT);
+  if (*slot == NULL)
+    *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
+  node = (struct indirect_string_node *) *slot;
+  node->str = ggc_alloc_string (str, -1);
+  node->refcount++;
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
   attr->dw_attr_val.val_class = dw_val_class_str;
-  attr->dw_attr_val.v.val_str = xstrdup (str);
+  attr->dw_attr_val.v.val_str = node;
   add_dwarf_attr (die, attr);
 }
 
-static inline const char *AT_string PARAMS ((dw_attr_ref));
 static inline const char *
 AT_string (a)
      dw_attr_ref a;
 {
   if (a && AT_class (a) == dw_val_class_str)
-    return a->dw_attr_val.v.val_str;
+    return a->dw_attr_val.v.val_str->str;
+
+  abort ();
+}
+
+/* Find out whether a string should be output inline in DIE
+   or out-of-line in .debug_str section.  */
+
+static int
+AT_string_form (a)
+     dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_str)
+    {
+      struct indirect_string_node *node;
+      unsigned int len;
+      char label[32];
+
+      node = a->dw_attr_val.v.val_str;
+      if (node->form)
+       return node->form;
+
+      len = strlen (node->str) + 1;
+
+      /* If the string is shorter or equal to the size of the reference, it is
+        always better to put it inline.  */
+      if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
+       return node->form = DW_FORM_string;
+
+      /* If we cannot expect the linker to merge strings in .debug_str
+        section, only put it into .debug_str if it is worth even in this
+        single module.  */
+      if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
+         && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
+       return node->form = DW_FORM_string;
+
+      ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
+      ++dw2_string_counter;
+      node->label = xstrdup (label);
+
+      return node->form = DW_FORM_strp;
+    }
 
   abort ();
 }
@@ -4423,7 +4754,7 @@ add_AT_die_ref (die, attr_kind, targ_die)
      enum dwarf_attribute attr_kind;
      dw_die_ref targ_die;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4433,7 +4764,6 @@ add_AT_die_ref (die, attr_kind, targ_die)
   add_dwarf_attr (die, attr);
 }
 
-static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
 static inline dw_die_ref
 AT_ref (a)
      dw_attr_ref a;
@@ -4444,7 +4774,6 @@ AT_ref (a)
   abort ();
 }
 
-static inline int AT_ref_external PARAMS ((dw_attr_ref));
 static inline int
 AT_ref_external (a)
      dw_attr_ref a;
@@ -4455,7 +4784,6 @@ AT_ref_external (a)
   return 0;
 }
 
-static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
 static inline void
 set_AT_ref_external (a, i)
      dw_attr_ref a;
@@ -4475,7 +4803,7 @@ add_AT_fde_ref (die, attr_kind, targ_fde)
      enum dwarf_attribute attr_kind;
      unsigned targ_fde;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4492,7 +4820,7 @@ add_AT_loc (die, attr_kind, loc)
      enum dwarf_attribute attr_kind;
      dw_loc_descr_ref loc;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4501,7 +4829,6 @@ add_AT_loc (die, attr_kind, loc)
   add_dwarf_attr (die, attr);
 }
 
-static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
 static inline dw_loc_descr_ref
 AT_loc (a)
      dw_attr_ref a;
@@ -4518,7 +4845,7 @@ add_AT_loc_list (die, attr_kind, loc_list)
      enum dwarf_attribute attr_kind;
      dw_loc_list_ref loc_list;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4528,8 +4855,6 @@ add_AT_loc_list (die, attr_kind, loc_list)
   have_location_lists = 1;
 }
 
-static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
-
 static inline dw_loc_list_ref
 AT_loc_list (a)
      dw_attr_ref a;
@@ -4548,7 +4873,7 @@ add_AT_addr (die, attr_kind, addr)
      enum dwarf_attribute attr_kind;
      rtx addr;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4557,7 +4882,6 @@ add_AT_addr (die, attr_kind, addr)
   add_dwarf_attr (die, attr);
 }
 
-static inline rtx AT_addr PARAMS ((dw_attr_ref));
 static inline rtx
 AT_addr (a)
      dw_attr_ref a;
@@ -4576,7 +4900,7 @@ add_AT_lbl_id (die, attr_kind, lbl_id)
      enum dwarf_attribute attr_kind;
      const char *lbl_id;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4593,7 +4917,7 @@ add_AT_lbl_offset (die, attr_kind, label)
      enum dwarf_attribute attr_kind;
      const char *label;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4604,13 +4928,13 @@ add_AT_lbl_offset (die, attr_kind, label)
 
 /* Add an offset attribute value to a DIE.  */
 
-static void
+static inline void
 add_AT_offset (die, attr_kind, offset)
      dw_die_ref die;
      enum dwarf_attribute attr_kind;
      unsigned long offset;
 {
-  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
 
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
@@ -4619,7 +4943,23 @@ add_AT_offset (die, attr_kind, offset)
   add_dwarf_attr (die, attr);
 }
 
-static inline const char *AT_lbl PARAMS ((dw_attr_ref));
+/* Add an range_list attribute value to a DIE.  */
+
+static void
+add_AT_range_list (die, attr_kind, offset)
+     dw_die_ref die;
+     enum dwarf_attribute attr_kind;
+     unsigned long offset;
+{
+  dw_attr_ref attr = (dw_attr_ref) ggc_alloc (sizeof (dw_attr_node));
+
+  attr->dw_attr_next = NULL;
+  attr->dw_attr = attr_kind;
+  attr->dw_attr_val.val_class = dw_val_class_range_list;
+  attr->dw_attr_val.v.val_offset = offset;
+  add_dwarf_attr (die, attr);
+}
+
 static inline const char *
 AT_lbl (a)
      dw_attr_ref a;
@@ -4644,14 +4984,11 @@ get_AT (die, attr_kind)
   if (die != NULL)
     {
       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
-       {
-         if (a->dw_attr == attr_kind)
-           return a;
-
-         if (a->dw_attr == DW_AT_specification
-             || a->dw_attr == DW_AT_abstract_origin)
-           spec = AT_ref (a);
-       }
+       if (a->dw_attr == attr_kind)
+         return a;
+       else if (a->dw_attr == DW_AT_specification
+                || a->dw_attr == DW_AT_abstract_origin)
+         spec = AT_ref (a);
 
       if (spec)
        return get_AT (spec, attr_kind);
@@ -4660,29 +4997,29 @@ get_AT (die, attr_kind)
   return NULL;
 }
 
-/* Return the "low pc" attribute value, typically associated with
-   a subprogram DIE.  Return null if the "low pc" attribute is
-   either not prsent, or if it cannot be represented as an
-   assembler label identifier.  */
+/* Return the "low pc" attribute value, typically associated with a subprogram
+   DIE.  Return null if the "low pc" attribute is either not present, or if it
+   cannot be represented as an assembler label identifier.  */
 
 static inline const char *
 get_AT_low_pc (die)
      dw_die_ref die;
 {
   dw_attr_ref a = get_AT (die, DW_AT_low_pc);
+
   return a ? AT_lbl (a) : NULL;
 }
 
-/* Return the "high pc" attribute value, typically associated with
-   a subprogram DIE.  Return null if the "high pc" attribute is
-   either not prsent, or if it cannot be represented as an
-   assembler label identifier.  */
+/* Return the "high pc" attribute value, typically associated with a subprogram
+   DIE.  Return null if the "high pc" attribute is either not present, or if it
+   cannot be represented as an assembler label identifier.  */
 
 static inline const char *
 get_AT_hi_pc (die)
      dw_die_ref die;
 {
   dw_attr_ref a = get_AT (die, DW_AT_high_pc);
+
   return a ? AT_lbl (a) : NULL;
 }
 
@@ -4695,6 +5032,7 @@ get_AT_string (die, attr_kind)
      enum dwarf_attribute attr_kind;
 {
   dw_attr_ref a = get_AT (die, attr_kind);
+
   return a ? AT_string (a) : NULL;
 }
 
@@ -4707,6 +5045,7 @@ get_AT_flag (die, attr_kind)
      enum dwarf_attribute attr_kind;
 {
   dw_attr_ref a = get_AT (die, attr_kind);
+
   return a ? AT_flag (a) : 0;
 }
 
@@ -4719,6 +5058,7 @@ get_AT_unsigned (die, attr_kind)
      enum dwarf_attribute attr_kind;
 {
   dw_attr_ref a = get_AT (die, attr_kind);
+
   return a ? AT_unsigned (a) : 0;
 }
 
@@ -4728,6 +5068,7 @@ get_AT_ref (die, attr_kind)
      enum dwarf_attribute attr_kind;
 {
   dw_attr_ref a = get_AT (die, attr_kind);
+
   return a ? AT_ref (a) : NULL;
 }
 
@@ -4741,6 +5082,13 @@ is_c_family ()
 }
 
 static inline int
+is_cxx ()
+{
+  return (get_AT_unsigned (comp_unit_die, DW_AT_language)
+         == DW_LANG_C_plus_plus);
+}
+
+static inline int
 is_fortran ()
 {
   unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
@@ -4763,23 +5111,9 @@ static inline void
 free_AT (a)
      dw_attr_ref a;
 {
-  switch (AT_class (a))
-    {
-    case dw_val_class_str:
-    case dw_val_class_lbl_id:
-    case dw_val_class_lbl_offset:
-      free (a->dw_attr_val.v.val_str);
-      break;
-
-    case dw_val_class_float:
-      free (a->dw_attr_val.v.val_float.array);
-      break;
-
-    default:
-      break;
-    }
-
-  free (a);
+  if (AT_class (a) == dw_val_class_str)
+    if (a->dw_attr_val.v.val_str->refcount)
+      a->dw_attr_val.v.val_str->refcount--;
 }
 
 /* Remove the specified attribute if present.  */
@@ -4809,13 +5143,11 @@ remove_AT (die, attr_kind)
 
 /* Free up the memory used by DIE.  */
 
-static inline void free_die PARAMS ((dw_die_ref));
 static inline void
 free_die (die)
      dw_die_ref die;
 {
   remove_children (die);
-  free (die);
 }
 
 /* Discard the children of this DIE.  */
@@ -4859,6 +5191,7 @@ add_child_die (die, child_die)
     {
       if (die == child_die)
        abort ();
+
       child_die->die_parent = die;
       child_die->die_sib = die->die_child;
       die->die_child = child_die;
@@ -4879,6 +5212,7 @@ splice_child_die (parent, child)
   if (child->die_parent != parent)
     {
       dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
+
       if (tmp)
        child = tmp;
     }
@@ -4894,6 +5228,7 @@ splice_child_die (parent, child)
        break;
       }
 
+  child->die_parent = parent;
   child->die_sib = parent->die_child;
   parent->die_child = child;
 }
@@ -4901,11 +5236,12 @@ splice_child_die (parent, child)
 /* Return a pointer to a newly created DIE node.  */
 
 static inline dw_die_ref
-new_die (tag_value, parent_die)
+new_die (tag_value, parent_die, t)
      enum dwarf_tag tag_value;
      dw_die_ref parent_die;
+     tree t;
 {
-  dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
+  dw_die_ref die = (dw_die_ref) ggc_alloc_cleared (sizeof (die_node));
 
   die->die_tag = tag_value;
 
@@ -4915,8 +5251,9 @@ new_die (tag_value, parent_die)
     {
       limbo_die_node *limbo_node;
 
-      limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
+      limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
       limbo_node->die = die;
+      limbo_node->created_for = t;
       limbo_node->next = limbo_die_list;
       limbo_die_list = limbo_node;
     }
@@ -4930,9 +5267,7 @@ static inline dw_die_ref
 lookup_type_die (type)
      tree type;
 {
-  if (TREE_CODE (type) == VECTOR_TYPE)
-    type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
-  return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
+  return TYPE_SYMTAB_DIE (type);
 }
 
 /* Equate a DIE to a given type specifier.  */
@@ -4942,7 +5277,7 @@ equate_type_number_to_die (type, type_die)
      tree type;
      dw_die_ref type_die;
 {
-  TYPE_SYMTAB_POINTER (type) = (char *) type_die;
+  TYPE_SYMTAB_DIE (type) = type_die;
 }
 
 /* Return the DIE associated with a given declaration.  */
@@ -4953,8 +5288,7 @@ lookup_decl_die (decl)
 {
   unsigned decl_id = DECL_UID (decl);
 
-  return (decl_id < decl_die_table_in_use
-         ? decl_die_table[decl_id] : NULL);
+  return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
 }
 
 /* Equate a DIE to a particular declaration.  */
@@ -4964,8 +5298,8 @@ equate_decl_number_to_die (decl, decl_die)
      tree decl;
      dw_die_ref decl_die;
 {
-  unsigned decl_id = DECL_UID (decl);
-  unsigned num_allocated;
+  unsigned int decl_id = DECL_UID (decl);
+  unsigned int num_allocated;
 
   if (decl_id >= decl_die_table_allocated)
     {
@@ -4974,9 +5308,8 @@ equate_decl_number_to_die (decl, decl_die)
           / DECL_DIE_TABLE_INCREMENT)
          * DECL_DIE_TABLE_INCREMENT;
 
-      decl_die_table
-       = (dw_die_ref *) xrealloc (decl_die_table,
-                                  sizeof (dw_die_ref) * num_allocated);
+      decl_die_table = ggc_realloc (decl_die_table,
+                                   sizeof (dw_die_ref) * num_allocated);
 
       memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
             (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
@@ -5041,6 +5374,9 @@ print_die (die, outfile)
          fprintf (outfile, "location list -> label:%s",
                   AT_loc_list (a)->ll_symbol);
          break;
+       case dw_val_class_range_list:
+         fprintf (outfile, "range list");
+         break;
        case dw_val_class_const:
          fprintf (outfile, "%ld", AT_int (a));
          break;
@@ -5109,11 +5445,12 @@ print_dwarf_line_table (outfile)
   dw_line_info_ref line_info;
 
   fprintf (outfile, "\n\nDWARF source line information\n");
-  for (i = 1; i < line_info_table_in_use; ++i)
+  for (i = 1; i < line_info_table_in_use; i++)
     {
       line_info = &line_info_table[i];
       fprintf (outfile, "%5d: ", i);
-      fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
+      fprintf (outfile, "%-20s",
+              VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
       fprintf (outfile, "%6ld", line_info->dw_line_num);
       fprintf (outfile, "\n");
     }
@@ -5159,6 +5496,7 @@ reverse_die_lists (die)
       a->dw_attr_next = ap;
       ap = a;
     }
+
   die->die_attr = ap;
 
   for (c = die->die_child, cp = 0; c; c = cn)
@@ -5167,15 +5505,15 @@ reverse_die_lists (die)
       c->die_sib = cp;
       cp = c;
     }
+
   die->die_child = cp;
 }
 
-/* reverse_die_lists only reverses the single die you pass it. Since
-   we used to reverse all dies in add_sibling_attributes, which runs
-   through all the dies, it would reverse all the dies.  Now, however,
-   since we don't call reverse_die_lists in add_sibling_attributes, we
-   need a routine to recursively reverse all the dies. This is that
-   routine.  */
+/* reverse_die_lists only reverses the single die you pass it. Since we used to
+   reverse all dies in add_sibling_attributes, which runs through all the dies,
+   it would reverse all the dies.  Now, however, since we don't call
+   reverse_die_lists in add_sibling_attributes, we need a routine to
+   recursively reverse all the dies. This is that routine.  */
 
 static void
 reverse_all_dies (die)
@@ -5189,10 +5527,9 @@ reverse_all_dies (die)
     reverse_all_dies (c);
 }
 
-/* Start a new compilation unit DIE for an include file.  OLD_UNIT is
-   the CU for the enclosing include file, if any.  BINCL_DIE is the
-   DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
-   include file.  */
+/* Start a new compilation unit DIE for an include file.  OLD_UNIT is the CU
+   for the enclosing include file, if any.  BINCL_DIE is the DW_TAG_GNU_BINCL
+   DIE that marks the start of the DIEs for this include file.  */
 
 static dw_die_ref
 push_new_compile_unit (old_unit, bincl_die)
@@ -5200,6 +5537,7 @@ push_new_compile_unit (old_unit, bincl_die)
 {
   const char *filename = get_AT_string (bincl_die, DW_AT_name);
   dw_die_ref new_unit = gen_compile_unit_die (filename);
+
   new_unit->die_sib = old_unit;
   return new_unit;
 }
@@ -5211,12 +5549,13 @@ pop_compile_unit (old_unit)
      dw_die_ref old_unit;
 {
   dw_die_ref new_unit = old_unit->die_sib;
+
   old_unit->die_sib = NULL;
   return new_unit;
 }
 
-#define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
-#define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
+#define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
+#define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
 
 /* Calculate the checksum of a location expression.  */
 
@@ -5225,22 +5564,23 @@ loc_checksum (loc, ctx)
      dw_loc_descr_ref loc;
      struct md5_ctx *ctx;
 {
-  PROCESS (loc->dw_loc_opc);
-  PROCESS (loc->dw_loc_oprnd1);
-  PROCESS (loc->dw_loc_oprnd2);
+  CHECKSUM (loc->dw_loc_opc);
+  CHECKSUM (loc->dw_loc_oprnd1);
+  CHECKSUM (loc->dw_loc_oprnd2);
 }
 
 /* Calculate the checksum of an attribute.  */
 
 static void
-attr_checksum (at, ctx)
+attr_checksum (at, ctx, mark)
      dw_attr_ref at;
      struct md5_ctx *ctx;
+     int *mark;
 {
   dw_loc_descr_ref loc;
   rtx r;
 
-  PROCESS (at->dw_attr);
+  CHECKSUM (at->dw_attr);
 
   /* We don't care about differences in file numbering.  */
   if (at->dw_attr == DW_AT_decl_file
@@ -5252,23 +5592,22 @@ attr_checksum (at, ctx)
   switch (AT_class (at))
     {
     case dw_val_class_const:
-      PROCESS (at->dw_attr_val.v.val_int);
+      CHECKSUM (at->dw_attr_val.v.val_int);
       break;
     case dw_val_class_unsigned_const:
-      PROCESS (at->dw_attr_val.v.val_unsigned);
+      CHECKSUM (at->dw_attr_val.v.val_unsigned);
       break;
     case dw_val_class_long_long:
-      PROCESS (at->dw_attr_val.v.val_long_long);
+      CHECKSUM (at->dw_attr_val.v.val_long_long);
       break;
     case dw_val_class_float:
-      PROCESS (at->dw_attr_val.v.val_float);
+      CHECKSUM (at->dw_attr_val.v.val_float);
       break;
     case dw_val_class_flag:
-      PROCESS (at->dw_attr_val.v.val_flag);
+      CHECKSUM (at->dw_attr_val.v.val_flag);
       break;
-
     case dw_val_class_str:
-      PROCESS_STRING (AT_string (at));
+      CHECKSUM_STRING (AT_string (at));
       break;
 
     case dw_val_class_addr:
@@ -5276,7 +5615,7 @@ attr_checksum (at, ctx)
       switch (GET_CODE (r))
        {
        case SYMBOL_REF:
-         PROCESS_STRING (XSTR (r, 0));
+         CHECKSUM_STRING (XSTR (r, 0));
          break;
 
        default:
@@ -5285,7 +5624,7 @@ attr_checksum (at, ctx)
       break;
 
     case dw_val_class_offset:
-      PROCESS (at->dw_attr_val.v.val_offset);
+      CHECKSUM (at->dw_attr_val.v.val_offset);
       break;
 
     case dw_val_class_loc:
@@ -5294,9 +5633,8 @@ attr_checksum (at, ctx)
       break;
 
     case dw_val_class_die_ref:
-      if (AT_ref (at)->die_offset)
-       PROCESS (AT_ref (at)->die_offset);
-      /* FIXME else use target die name or something.  */
+      die_checksum (AT_ref (at), ctx, mark);
+      break;
 
     case dw_val_class_fde_ref:
     case dw_val_class_lbl_id:
@@ -5311,94 +5649,265 @@ attr_checksum (at, ctx)
 /* Calculate the checksum of a DIE.  */
 
 static void
-die_checksum (die, ctx)
+die_checksum (die, ctx, mark)
      dw_die_ref die;
      struct md5_ctx *ctx;
+     int *mark;
 {
   dw_die_ref c;
   dw_attr_ref a;
 
-  PROCESS (die->die_tag);
+  /* To avoid infinite recursion.  */
+  if (die->die_mark)
+    {
+      CHECKSUM (die->die_mark);
+      return;
+    }
+  die->die_mark = ++(*mark);
+
+  CHECKSUM (die->die_tag);
 
   for (a = die->die_attr; a; a = a->dw_attr_next)
-    attr_checksum (a, ctx);
+    attr_checksum (a, ctx, mark);
 
   for (c = die->die_child; c; c = c->die_sib)
-    die_checksum (c, ctx);
+    die_checksum (c, ctx, mark);
 }
 
-#undef PROCESS
-#undef PROCESS_STRING
+#undef CHECKSUM
+#undef CHECKSUM_STRING
 
-/* The prefix to attach to symbols on DIEs in the current comdat debug
-   info section.  */
-static char *comdat_symbol_id;
+/* Do the location expressions look same?  */
+static inline int
+same_loc_p (loc1, loc2, mark)
+     dw_loc_descr_ref loc1;
+     dw_loc_descr_ref loc2;
+     int *mark;
+{
+  return loc1->dw_loc_opc == loc2->dw_loc_opc
+        && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
+        && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
+}
 
-/* The index of the current symbol within the current comdat CU.  */
-static unsigned int comdat_symbol_number;
+/* Do the values look the same?  */
+static int
+same_dw_val_p (v1, v2, mark)
+     dw_val_node *v1;
+     dw_val_node *v2;
+     int *mark;
+{
+  dw_loc_descr_ref loc1, loc2;
+  rtx r1, r2;
+  unsigned i;
 
-/* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
-   children, and set comdat_symbol_id accordingly.  */
+  if (v1->val_class != v2->val_class)
+    return 0;
 
-static void
-compute_section_prefix (unit_die)
-     dw_die_ref unit_die;
-{
-  char *name;
-  int i;
-  unsigned char checksum[16];
-  struct md5_ctx ctx;
+  switch (v1->val_class)
+    {
+    case dw_val_class_const:
+      return v1->v.val_int == v2->v.val_int;
+    case dw_val_class_unsigned_const:
+      return v1->v.val_unsigned == v2->v.val_unsigned;
+    case dw_val_class_long_long:
+      return v1->v.val_long_long.hi == v2->v.val_long_long.hi
+            && v1->v.val_long_long.low == v2->v.val_long_long.low;
+    case dw_val_class_float:
+      if (v1->v.val_float.length != v2->v.val_float.length)
+       return 0;
+      for (i = 0; i < v1->v.val_float.length; i++)
+       if (v1->v.val_float.array[i] != v2->v.val_float.array[i])
+         return 0;
+      return 1;
+    case dw_val_class_flag:
+      return v1->v.val_flag == v2->v.val_flag;
+    case dw_val_class_str:
+      return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
 
-  md5_init_ctx (&ctx);
-  die_checksum (unit_die, &ctx);
-  md5_finish_ctx (&ctx, checksum);
+    case dw_val_class_addr:
+      r1 = v1->v.val_addr;
+      r2 = v2->v.val_addr;
+      if (GET_CODE (r1) != GET_CODE (r2))
+       return 0;
+      switch (GET_CODE (r1))
+       {
+       case SYMBOL_REF:
+         return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
 
-  {
-    const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
-    name = (char *) alloca (strlen (p) + 64);
-    sprintf (name, "%s.", p);
-  }
+       default:
+         abort ();
+       }
 
-  clean_symbol_name (name);
+    case dw_val_class_offset:
+      return v1->v.val_offset == v2->v.val_offset;
 
-  {
-    char *p = name + strlen (name);
-    for (i = 0; i < 4; ++i)
-      {
-       sprintf (p, "%.2x", checksum[i]);
-       p += 2;
-      }
-  }
+    case dw_val_class_loc:
+      for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
+          loc1 && loc2;
+          loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
+       if (!same_loc_p (loc1, loc2, mark))
+         return 0;
+      return !loc1 && !loc2;
 
-  comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
-  comdat_symbol_number = 0;
+    case dw_val_class_die_ref:
+      return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
+
+    case dw_val_class_fde_ref:
+    case dw_val_class_lbl_id:
+    case dw_val_class_lbl_offset:
+      return 1;
+
+    default:
+      return 1;
+    }
 }
 
-/* Returns nonzero iff DIE represents a type, in the sense of TYPE_P.  */
+/* Do the attributes look the same?  */
 
 static int
-is_type_die (die)
-     dw_die_ref die;
+same_attr_p (at1, at2, mark)
+     dw_attr_ref at1;
+     dw_attr_ref at2;
+     int *mark;
 {
-  switch (die->die_tag)
-    {
-    case DW_TAG_array_type:
-    case DW_TAG_class_type:
-    case DW_TAG_enumeration_type:
-    case DW_TAG_pointer_type:
-    case DW_TAG_reference_type:
-    case DW_TAG_string_type:
-    case DW_TAG_structure_type:
-    case DW_TAG_subroutine_type:
-    case DW_TAG_union_type:
-    case DW_TAG_ptr_to_member_type:
-    case DW_TAG_set_type:
+  if (at1->dw_attr != at2->dw_attr)
+    return 0;
+
+  /* We don't care about differences in file numbering.  */
+  if (at1->dw_attr == DW_AT_decl_file
+      /* Or that this was compiled with a different compiler snapshot; if
+        the output is the same, that's what matters.  */
+      || at1->dw_attr == DW_AT_producer)
+    return 1;
+
+  return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
+}
+
+/* Do the dies look the same?  */
+
+static int
+same_die_p (die1, die2, mark)
+     dw_die_ref die1;
+     dw_die_ref die2;
+     int *mark;
+{
+  dw_die_ref c1, c2;
+  dw_attr_ref a1, a2;
+
+  /* To avoid infinite recursion.  */
+  if (die1->die_mark)
+    return die1->die_mark == die2->die_mark;
+  die1->die_mark = die2->die_mark = ++(*mark);
+
+  if (die1->die_tag != die2->die_tag)
+    return 0;
+
+  for (a1 = die1->die_attr, a2 = die2->die_attr;
+       a1 && a2;
+       a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
+    if (!same_attr_p (a1, a2, mark))
+      return 0;
+  if (a1 || a2)
+    return 0;
+
+  for (c1 = die1->die_child, c2 = die2->die_child;
+       c1 && c2;
+       c1 = c1->die_sib, c2 = c2->die_sib)
+    if (!same_die_p (c1, c2, mark))
+      return 0;
+  if (c1 || c2)
+    return 0;
+
+  return 1;
+}
+
+/* Do the dies look the same?  Wrapper around same_die_p.  */
+
+static int
+same_die_p_wrap (die1, die2)
+     dw_die_ref die1;
+     dw_die_ref die2;
+{
+  int mark = 0;
+  int ret = same_die_p (die1, die2, &mark);
+
+  unmark_all_dies (die1);
+  unmark_all_dies (die2);
+
+  return ret;
+}
+
+/* The prefix to attach to symbols on DIEs in the current comdat debug
+   info section.  */
+static char *comdat_symbol_id;
+
+/* The index of the current symbol within the current comdat CU.  */
+static unsigned int comdat_symbol_number;
+
+/* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
+   children, and set comdat_symbol_id accordingly.  */
+
+static void
+compute_section_prefix (unit_die)
+     dw_die_ref unit_die;
+{
+  const char *die_name = get_AT_string (unit_die, DW_AT_name);
+  const char *base = die_name ? lbasename (die_name) : "anonymous";
+  char *name = (char *) alloca (strlen (base) + 64);
+  char *p;
+  int i, mark;
+  unsigned char checksum[16];
+  struct md5_ctx ctx;
+
+  /* Compute the checksum of the DIE, then append part of it as hex digits to
+     the name filename of the unit.  */
+
+  md5_init_ctx (&ctx);
+  mark = 0;
+  die_checksum (unit_die, &ctx, &mark);
+  unmark_all_dies (unit_die);
+  md5_finish_ctx (&ctx, checksum);
+
+  sprintf (name, "%s.", base);
+  clean_symbol_name (name);
+
+  p = name + strlen (name);
+  for (i = 0; i < 4; i++)
+    {
+      sprintf (p, "%.2x", checksum[i]);
+      p += 2;
+    }
+
+  comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
+  comdat_symbol_number = 0;
+}
+
+/* Returns nonzero if DIE represents a type, in the sense of TYPE_P.  */
+
+static int
+is_type_die (die)
+     dw_die_ref die;
+{
+  switch (die->die_tag)
+    {
+    case DW_TAG_array_type:
+    case DW_TAG_class_type:
+    case DW_TAG_enumeration_type:
+    case DW_TAG_pointer_type:
+    case DW_TAG_reference_type:
+    case DW_TAG_string_type:
+    case DW_TAG_structure_type:
+    case DW_TAG_subroutine_type:
+    case DW_TAG_union_type:
+    case DW_TAG_ptr_to_member_type:
+    case DW_TAG_set_type:
     case DW_TAG_subrange_type:
     case DW_TAG_base_type:
     case DW_TAG_const_type:
     case DW_TAG_file_type:
     case DW_TAG_packed_type:
     case DW_TAG_volatile_type:
+    case DW_TAG_typedef:
       return 1;
     default:
       return 0;
@@ -5414,12 +5923,11 @@ static int
 is_comdat_die (c)
      dw_die_ref c;
 {
-#if 1
-  /* I think we want to leave base types and __vtbl_ptr_type in the
-     main CU, as we do for stabs.  The advantage is a greater
-     likelihood of sharing between objects that don't include headers
-     in the same order (and therefore would put the base types in a
-     different comdat).  jason 8/28/00 */
+  /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
+     we do for stabs.  The advantage is a greater likelihood of sharing between
+     objects that don't include headers in the same order (and therefore would
+     put the base types in a different comdat).  jason 8/28/00 */
+
   if (c->die_tag == DW_TAG_base_type)
     return 0;
 
@@ -5429,9 +5937,9 @@ is_comdat_die (c)
       || c->die_tag == DW_TAG_volatile_type)
     {
       dw_die_ref t = get_AT_ref (c, DW_AT_type);
+
       return t ? is_comdat_die (t) : 0;
     }
-#endif
 
   return is_type_die (c);
 }
@@ -5443,20 +5951,18 @@ static int
 is_symbol_die (c)
      dw_die_ref c;
 {
-  if (is_type_die (c))
-    return 1;
-  if (get_AT (c, DW_AT_declaration) 
-      && ! get_AT (c, DW_AT_specification))
-    return 1;
-  return 0;
+  return (is_type_die (c)
+         || (get_AT (c, DW_AT_declaration)
+             && !get_AT (c, DW_AT_specification)));
 }
 
 static char *
 gen_internal_sym (prefix)
-       const char *prefix;
+     const char *prefix;
 {
   char buf[256];
   static int label_num;
+
   ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
   return xstrdup (buf);
 }
@@ -5474,6 +5980,7 @@ assign_symbol_names (die)
       if (comdat_symbol_id)
        {
          char *p = alloca (strlen (comdat_symbol_id) + 64);
+
          sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
                   comdat_symbol_id, comdat_symbol_number++);
          die->die_symbol = xstrdup (p);
@@ -5486,6 +5993,104 @@ assign_symbol_names (die)
     assign_symbol_names (c);
 }
 
+struct cu_hash_table_entry
+{
+  dw_die_ref cu;
+  unsigned min_comdat_num, max_comdat_num;
+  struct cu_hash_table_entry *next;
+};
+
+/* Routines to manipulate hash table of CUs.  */
+static hashval_t
+htab_cu_hash (of)
+     const void *of;
+{
+  const struct cu_hash_table_entry *entry = of;
+
+  return htab_hash_string (entry->cu->die_symbol);
+}
+
+static int
+htab_cu_eq (of1, of2)
+     const void *of1;
+     const void *of2;
+{
+  const struct cu_hash_table_entry *entry1 = of1;
+  const struct die_struct *entry2 = of2;
+
+  return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
+}
+
+static void
+htab_cu_del (what)
+     void *what;
+{
+  struct cu_hash_table_entry *next, *entry = what;
+
+  while (entry)
+    {
+      next = entry->next;
+      free (entry);
+      entry = next;
+    }
+}
+
+/* Check whether we have already seen this CU and set up SYM_NUM
+   accordingly.  */
+static int
+check_duplicate_cu (cu, htable, sym_num)
+     dw_die_ref cu;
+     htab_t htable;
+     unsigned *sym_num;
+{
+  struct cu_hash_table_entry dummy;
+  struct cu_hash_table_entry **slot, *entry, *last = &dummy;
+
+  dummy.max_comdat_num = 0;
+
+  slot = (struct cu_hash_table_entry **)
+    htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
+       INSERT);
+  entry = *slot;
+
+  for (; entry; last = entry, entry = entry->next)
+    {
+      if (same_die_p_wrap (cu, entry->cu))
+       break;
+    }
+
+  if (entry)
+    {
+      *sym_num = entry->min_comdat_num;
+      return 1;
+    }
+
+  entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
+  entry->cu = cu;
+  entry->min_comdat_num = *sym_num = last->max_comdat_num;
+  entry->next = *slot;
+  *slot = entry;
+
+  return 0;
+}
+
+/* Record SYM_NUM to record of CU in HTABLE.  */
+static void
+record_comdat_symbol_number (cu, htable, sym_num)
+     dw_die_ref cu;
+     htab_t htable;
+     unsigned sym_num;
+{
+  struct cu_hash_table_entry **slot, *entry;
+
+  slot = (struct cu_hash_table_entry **)
+    htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
+       NO_INSERT);
+  entry = *slot;
+
+  entry->max_comdat_num = sym_num;
+}
+
 /* Traverse the DIE (which is always comp_unit_die), and set up
    additional compilation units for each of the include files we see
    bracketed by BINCL/EINCL.  */
@@ -5496,14 +6101,14 @@ break_out_includes (die)
 {
   dw_die_ref *ptr;
   dw_die_ref unit = NULL;
-  limbo_die_node *node;
+  limbo_die_node *node, **pnode;
+  htab_t cu_hash_table;
 
-  for (ptr = &(die->die_child); *ptr; )
+  for (ptr = &(die->die_child); *ptr;)
     {
       dw_die_ref c = *ptr;
 
-      if (c->die_tag == DW_TAG_GNU_BINCL
-         || c->die_tag == DW_TAG_GNU_EINCL
+      if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
          || (unit && is_comdat_die (c)))
        {
          /* This DIE is for a secondary CU; remove it from the main one.  */
@@ -5538,11 +6143,27 @@ break_out_includes (die)
 #endif
 
   assign_symbol_names (die);
-  for (node = limbo_die_list; node; node = node->next)
+  cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
+  for (node = limbo_die_list, pnode = &limbo_die_list;
+       node;
+       node = node->next)
     {
+      int is_dupl;
+
       compute_section_prefix (node->die);
+      is_dupl = check_duplicate_cu (node->die, cu_hash_table,
+                       &comdat_symbol_number);
       assign_symbol_names (node->die);
+      if (is_dupl)
+       *pnode = node->next;
+      else
+       {
+         pnode = &node->next;
+         record_comdat_symbol_number (node->die, cu_hash_table,
+               comdat_symbol_number);
+       }
     }
+  htab_delete (cu_hash_table);
 }
 
 /* Traverse the DIE and add a sibling attribute if it may have the
@@ -5564,29 +6185,28 @@ add_sibling_attributes (die)
     add_sibling_attributes (c);
 }
 
-/* Output all location lists for the DIE and it's children */
+/* Output all location lists for the DIE and its children.  */
+
 static void
 output_location_lists (die)
      dw_die_ref die;
 {
   dw_die_ref c;
   dw_attr_ref d_attr;
+
   for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
-    {
-      if (AT_class (d_attr) == dw_val_class_loc_list)
-       {
-         output_loc_list (AT_loc_list (d_attr));
-       }
-    }
+    if (AT_class (d_attr) == dw_val_class_loc_list)
+      output_loc_list (AT_loc_list (d_attr));
+
   for (c = die->die_child; c != NULL; c = c->die_sib)
     output_location_lists (c);
 
 }
-/* The format of each DIE (and its attribute value pairs)
-   is encoded in an abbreviation table.  This routine builds the
-   abbreviation table and assigns a unique abbreviation id for
-   each abbreviation entry.  The children of each die are visited
-   recursively.  */
+
+/* The format of each DIE (and its attribute value pairs) is encoded in an
+   abbreviation table.  This routine builds the abbreviation table and assigns
+   a unique abbreviation id for each abbreviation entry.  The children of each
+   die are visited recursively.  */
 
 static void
 build_abbrev_table (die)
@@ -5600,15 +6220,14 @@ build_abbrev_table (die)
   /* Scan the DIE references, and mark as external any that refer to
      DIEs from other CUs (i.e. those which are not marked).  */
   for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
-    {
-      if (AT_class (d_attr) == dw_val_class_die_ref
-         && AT_ref (d_attr)->die_mark == 0)
-       {
-         if (AT_ref (d_attr)->die_symbol == 0)
-           abort ();
-         set_AT_ref_external (d_attr, 1);
-       }
-    }
+    if (AT_class (d_attr) == dw_val_class_die_ref
+       && AT_ref (d_attr)->die_mark == 0)
+      {
+       if (AT_ref (d_attr)->die_symbol == 0)
+         abort ();
+
+       set_AT_ref_external (d_attr, 1);
+      }
 
   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
     {
@@ -5642,9 +6261,8 @@ build_abbrev_table (die)
       if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
        {
          n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
-         abbrev_die_table
-           = (dw_die_ref *) xrealloc (abbrev_die_table,
-                                      sizeof (dw_die_ref) * n_alloc);
+         abbrev_die_table = ggc_realloc (abbrev_die_table,
+                                         sizeof (dw_die_ref) * n_alloc);
 
          memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
                 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
@@ -5660,20 +6278,6 @@ build_abbrev_table (die)
     build_abbrev_table (c);
 }
 \f
-/* Return the size of a string, including the null byte.
-
-   This used to treat backslashes as escapes, and hence they were not included
-   in the count.  However, that conflicts with what ASM_OUTPUT_ASCII does,
-   which treats a backslash as a backslash, escaping it if necessary, and hence
-   we must include them in the count.  */
-
-static unsigned long
-size_of_string (str)
-     const char *str;
-{
-  return strlen (str) + 1;
-}
-
 /* Return the power-of-two number of bytes necessary to represent VALUE.  */
 
 static int
@@ -5693,7 +6297,7 @@ constant_size (value)
   return log;
 }
 
-/* Return the size of a DIE, as it is represented in the
+/* Return the size of a DIE as it is represented in the
    .debug_info section.  */
 
 static unsigned long
@@ -5726,6 +6330,9 @@ size_of_die (die)
        case dw_val_class_loc_list:
          size += DWARF_OFFSET_SIZE;
          break;
+       case dw_val_class_range_list:
+         size += DWARF_OFFSET_SIZE;
+         break;
        case dw_val_class_const:
          size += size_of_sleb128 (AT_int (a));
          break;
@@ -5742,7 +6349,10 @@ size_of_die (die)
          size += 1;
          break;
        case dw_val_class_die_ref:
-         size += DWARF_OFFSET_SIZE;
+         if (AT_ref_external (a))
+           size += DWARF2_ADDR_SIZE;
+         else
+           size += DWARF_OFFSET_SIZE;
          break;
        case dw_val_class_fde_ref:
          size += DWARF_OFFSET_SIZE;
@@ -5754,7 +6364,10 @@ size_of_die (die)
          size += DWARF_OFFSET_SIZE;
          break;
        case dw_val_class_str:
-         size += size_of_string (AT_string (a));
+         if (AT_string_form (a) == DW_FORM_strp)
+           size += DWARF_OFFSET_SIZE;
+         else
+           size += strlen (a->dw_attr_val.v.val_str->str) + 1;
          break;
        default:
          abort ();
@@ -5764,17 +6377,17 @@ size_of_die (die)
   return size;
 }
 
-/* Size the debugging information associated with a given DIE.
-   Visits the DIE's children recursively.  Updates the global
-   variable next_die_offset, on each time through.  Uses the
-   current value of next_die_offset to update the die_offset
-   field in each DIE.  */
+/* Size the debugging information associated with a given DIE.  Visits the
+   DIE's children recursively.  Updates the global variable next_die_offset, on
+   each time through.  Uses the current value of next_die_offset to update the
+   die_offset field in each DIE.  */
 
 static void
 calc_die_sizes (die)
      dw_die_ref die;
 {
   dw_die_ref c;
+
   die->die_offset = next_die_offset;
   next_die_offset += size_of_die (die);
 
@@ -5796,6 +6409,10 @@ mark_dies (die)
      dw_die_ref die;
 {
   dw_die_ref c;
+
+  if (die->die_mark)
+    abort ();
+  
   die->die_mark = 1;
   for (c = die->die_child; c; c = c->die_sib)
     mark_dies (c);
@@ -5808,11 +6425,36 @@ unmark_dies (die)
      dw_die_ref die;
 {
   dw_die_ref c;
+
+  if (!die->die_mark)
+    abort ();
+  
   die->die_mark = 0;
   for (c = die->die_child; c; c = c->die_sib)
     unmark_dies (c);
 }
 
+/* Clear the marks for a die, its children and referred dies.  */
+
+static void
+unmark_all_dies (die)
+     dw_die_ref die;
+{
+  dw_die_ref c;
+  dw_attr_ref a;
+
+  if (!die->die_mark)
+    return;
+  die->die_mark = 0;
+
+  for (c = die->die_child; c; c = c->die_sib)
+    unmark_all_dies (c);
+
+  for (a = die->die_attr; a; a = a->dw_attr_next)
+    if (AT_class (a) == dw_val_class_die_ref)
+      unmark_all_dies (AT_ref (a));
+}
+
 /* Return the size of the .debug_pubnames table  generated for the
    compilation unit.  */
 
@@ -5823,10 +6465,10 @@ size_of_pubnames ()
   unsigned i;
 
   size = DWARF_PUBNAMES_HEADER_SIZE;
-  for (i = 0; i < pubname_table_in_use; ++i)
+  for (i = 0; i < pubname_table_in_use; i++)
     {
       pubname_ref p = &pubname_table[i];
-      size += DWARF_OFFSET_SIZE + size_of_string (p->name);
+      size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
     }
 
   size += DWARF_OFFSET_SIZE;
@@ -5861,6 +6503,7 @@ value_format (a)
     {
     case dw_val_class_addr:
       return DW_FORM_addr;
+    case dw_val_class_range_list:
     case dw_val_class_offset:
       if (DWARF_OFFSET_SIZE == 4)
        return DW_FORM_data4;
@@ -5915,7 +6558,7 @@ value_format (a)
     case dw_val_class_lbl_offset:
       return DW_FORM_data;
     case dw_val_class_str:
-      return DW_FORM_string;
+      return AT_string_form (a);
 
     default:
       abort ();
@@ -5929,6 +6572,7 @@ output_value_format (a)
      dw_attr_ref a;
 {
   enum dwarf_form form = value_format (a);
+
   dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
 }
 
@@ -5941,12 +6585,12 @@ output_abbrev_section ()
   unsigned long abbrev_id;
 
   dw_attr_ref a_attr;
+
   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
     {
       dw_die_ref abbrev = abbrev_die_table[abbrev_id];
 
       dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
-
       dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
                                   dwarf_tag_name (abbrev->die_tag));
 
@@ -5986,14 +6630,15 @@ output_die_symbol (die)
     /* We make these global, not weak; if the target doesn't support
        .linkonce, it doesn't support combining the sections, so debugging
        will break.  */
-    ASM_GLOBALIZE_LABEL (asm_out_file, sym);
+    (*targetm.asm_out.globalize_label) (asm_out_file, sym);
+
   ASM_OUTPUT_LABEL (asm_out_file, sym);
 }
 
 /* Return a new location list, given the begin and end range, and the
-   expression. gensym tells us whether to generate a new internal
-   symbol for this location list node, which is done for the head of
-   the list only.  */ 
+   expression. gensym tells us whether to generate a new internal symbol for
+   this location list node, which is done for the head of the list only.  */
+
 static inline dw_loc_list_ref
 new_loc_list (expr, begin, end, section, gensym)
      dw_loc_descr_ref expr;
@@ -6002,18 +6647,20 @@ new_loc_list (expr, begin, end, section, gensym)
      const char *section;
      unsigned gensym;
 {
-  dw_loc_list_ref retlist
-    = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
+  dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
+
   retlist->begin = begin;
   retlist->end = end;
   retlist->expr = expr;
   retlist->section = section;
-  if (gensym) 
+  if (gensym)
     retlist->ll_symbol = gen_internal_sym ("LLST");
+
   return retlist;
 }
 
 /* Add a location description expression to a location list */
+
 static inline void
 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
      dw_loc_list_ref *list_head;
@@ -6023,20 +6670,23 @@ add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
      const char *section;
 {
   dw_loc_list_ref *d;
-  
+
   /* Find the end of the chain.  */
   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
     ;
+
   /* Add a new location list node to the list */
   *d = new_loc_list (descr, begin, end, section, 0);
 }
 
 /* Output the location list given to us */
+
 static void
 output_loc_list (list_head)
      dw_loc_list_ref list_head;
 {
-  dw_loc_list_ref curr=list_head;
+  dw_loc_list_ref curr = list_head;
+
   ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
 
   /* ??? This shouldn't be needed now that we've forced the
@@ -6045,14 +6695,16 @@ output_loc_list (list_head)
   if (strcmp (curr->section, ".text") == 0)
     {
       /* dw2_asm_output_data will mask off any extra bits in the ~0.  */
-      dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
+      dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
                           "Location list base address specifier fake entry");
       dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
                             "Location list base address specifier base");
     }
-  for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
+
+  for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
     {
-      int size;
+      unsigned long size;
+
       dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
                            "Location list begin address (%s)",
                            list_head->ll_symbol);
@@ -6060,13 +6712,15 @@ output_loc_list (list_head)
                            "Location list end address (%s)",
                            list_head->ll_symbol);
       size = size_of_locs (curr->expr);
-      
+
       /* Output the block length for this list of location operations.  */
-      dw2_asm_output_data (constant_size (size), size, "%s",
-                          "Location expression size");
-      
+      if (size > 0xffff)
+       abort ();
+      dw2_asm_output_data (2, size, "%s", "Location expression size");
+
       output_loc_sequence (curr->expr);
     }
+
   dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
                       "Location list terminator begin (%s)",
                       list_head->ll_symbol);
@@ -6074,6 +6728,7 @@ output_loc_list (list_head)
                       "Location list terminator end (%s)",
                       list_head->ll_symbol);
 }
+
 /* Output the DIE and its attributes.  Called recursively to generate
    the definitions of each child DIE.  */
 
@@ -6108,6 +6763,17 @@ output_die (die)
                               "%s", name);
          break;
 
+       case dw_val_class_range_list:
+         {
+           char *p = strchr (ranges_section_label, '\0');
+
+           sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
+           dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
+                                  "%s", name);
+           *p = '\0';
+         }
+         break;
+
        case dw_val_class_loc:
          size = size_of_locs (AT_loc (a));
 
@@ -6133,8 +6799,9 @@ output_die (die)
          {
            unsigned HOST_WIDE_INT first, second;
 
-           dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
-                                "%s", name);
+           dw2_asm_output_data (1,
+                                2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
+                                "%s", name);
 
            if (WORDS_BIG_ENDIAN)
              {
@@ -6146,9 +6813,10 @@ output_die (die)
                first = a->dw_attr_val.v.val_long_long.low;
                second = a->dw_attr_val.v.val_long_long.hi;
              }
-           dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
+
+           dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
                                 first, "long long constant");
-           dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
+           dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
                                 second, NULL);
          }
          break;
@@ -6158,9 +6826,9 @@ output_die (die)
            unsigned int i;
 
            dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
-                                "%s", name);
+                                "%s", name);
 
-           for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
+           for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
              dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
                                   "fp constant word %u", i);
            break;
@@ -6170,11 +6838,12 @@ output_die (die)
          dw2_asm_output_data (1, AT_flag (a), "%s", name);
          break;
 
-        case dw_val_class_loc_list:
+       case dw_val_class_loc_list:
          {
            char *sym = AT_loc_list (a)->ll_symbol;
+
            if (sym == 0)
-             abort();
+             abort ();
            dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
                                  loc_section_label, "%s", name);
          }
@@ -6184,6 +6853,7 @@ output_die (die)
          if (AT_ref_external (a))
            {
              char *sym = AT_ref (a)->die_symbol;
+
              if (sym == 0)
                abort ();
              dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
@@ -6198,6 +6868,7 @@ output_die (die)
        case dw_val_class_fde_ref:
          {
            char l1[20];
+
            ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
                                         a->dw_attr_val.v.val_fde_index * 2);
            dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
@@ -6213,7 +6884,12 @@ output_die (die)
          break;
 
        case dw_val_class_str:
-         dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
+         if (AT_string_form (a) == DW_FORM_strp)
+           dw2_asm_output_offset (DWARF_OFFSET_SIZE,
+                                  a->dw_attr_val.v.val_str->label,
+                                  "%s: \"%s\"", name, AT_string (a));
+         else
+           dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
          break;
 
        default:
@@ -6224,12 +6900,10 @@ output_die (die)
   for (c = die->die_child; c != NULL; c = c->die_sib)
     output_die (c);
 
+  /* Add null byte to terminate sibling list.  */
   if (die->die_child != NULL)
-    {
-      /* Add null byte to terminate sibling list.  */
-      dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
-                          die->die_offset);
-    }
+    dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
+                        die->die_offset);
 }
 
 /* Output the compilation unit that appears at the beginning of the
@@ -6240,30 +6914,31 @@ output_compilation_unit_header ()
 {
   dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
                       "Length of Compilation Unit Info");
-
   dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
-
   dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
                         "Offset Into Abbrev. Section");
-
   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
 }
 
 /* Output the compilation unit DIE and its children.  */
 
 static void
-output_comp_unit (die)
+output_comp_unit (die, output_if_empty)
      dw_die_ref die;
+     int output_if_empty;
 {
   const char *secname;
+  char *oldsym, *tmp;
 
-  /* Even if there are no children of this DIE, we must output the
-     information about the compilation unit.  Otherwise, on an empty
-     translation unit, we will generate a present, but empty,
-     .debug_info section.  IRIX 6.5 `nm' will then complain when
-     examining the file.
-     
-     Mark all the DIEs in this CU so we know which get local refs.  */
+  /* Unless we are outputting main CU, we may throw away empty ones.  */
+  if (!output_if_empty && die->die_child == NULL)
+    return;
+
+  /* Even if there are no children of this DIE, we must output the information
+     about the compilation unit.  Otherwise, on an empty translation unit, we
+     will generate a present, but empty, .debug_info section.  IRIX 6.5 `nm'
+     will then complain when examining the file.  First mark all the DIEs in
+     this CU so we know which get local refs.  */
   mark_dies (die);
 
   build_abbrev_table (die);
@@ -6272,10 +6947,12 @@ output_comp_unit (die)
   next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
   calc_die_sizes (die);
 
-  if (die->die_symbol)
+  oldsym = die->die_symbol;
+  if (oldsym)
     {
-      char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
-      sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
+      tmp = (char *) alloca (strlen (oldsym) + 24);
+
+      sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
       secname = tmp;
       die->die_symbol = NULL;
     }
@@ -6289,20 +6966,23 @@ output_comp_unit (die)
 
   /* Leave the marks on the main CU, so we can check them in
      output_pubnames.  */
-  if (die->die_symbol)
-    unmark_dies (die);
+  if (oldsym)
+    {
+      unmark_dies (die);
+      die->die_symbol = oldsym;
+    }
 }
 
-/* The DWARF2 pubname for a nested thingy looks like "A::f".  The output
-   of decl_printable_name for C++ looks like "A::f(int)".  Let's drop the
-   argument list, and maybe the scope.  */
+/* The DWARF2 pubname for a nested thingy looks like "A::f".  The
+   output of lang_hooks.decl_printable_name for C++ looks like
+   "A::f(int)".  Let's drop the argument list, and maybe the scope.  */
 
 static const char *
 dwarf2_name (decl, scope)
      tree decl;
      int scope;
 {
-  return (*decl_printable_name) (decl, scope ? 1 : 0);
+  return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
 }
 
 /* Add a new entry to .debug_pubnames if appropriate.  */
@@ -6320,13 +7000,16 @@ add_pubname (decl, die)
   if (pubname_table_in_use == pubname_table_allocated)
     {
       pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
-      pubname_table = (pubname_ref) xrealloc
-       (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
+      pubname_table
+       = (pubname_ref) ggc_realloc (pubname_table,
+                                    (pubname_table_allocated
+                                     * sizeof (pubname_entry)));
+      memset (pubname_table + pubname_table_in_use, 0,
+             PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
     }
 
   p = &pubname_table[pubname_table_in_use++];
   p->die = die;
-
   p->name = xstrdup (dwarf2_name (decl, 1));
 }
 
@@ -6342,16 +7025,13 @@ output_pubnames ()
 
   dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
                       "Length of Public Names Info");
-
   dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
-
   dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
                         "Offset of Compilation Unit Info");
-
   dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
                       "Compilation Unit Length");
 
-  for (i = 0; i < pubname_table_in_use; ++i)
+  for (i = 0; i < pubname_table_in_use; i++)
     {
       pubname_ref pub = &pubname_table[i];
 
@@ -6381,8 +7061,11 @@ add_arange (decl, die)
   if (arange_table_in_use == arange_table_allocated)
     {
       arange_table_allocated += ARANGE_TABLE_INCREMENT;
-      arange_table = (dw_die_ref *)
-       xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
+      arange_table = ggc_realloc (arange_table, 
+                                 (arange_table_allocated 
+                                  * sizeof (dw_die_ref)));
+      memset (arange_table + arange_table_in_use, 0,
+             ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
     }
 
   arange_table[arange_table_in_use++] = die;
@@ -6400,21 +7083,17 @@ output_aranges ()
 
   dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
                       "Length of Address Ranges Info");
-
   dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
-
   dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
                         "Offset of Compilation Unit Info");
-
   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
-
   dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
 
   /* We need to align to twice the pointer size here.  */
   if (DWARF_ARANGES_PAD_SIZE)
     {
       /* Pad using a 2 byte words so that padding is correct for any
-         pointer size.  */
+        pointer size.  */
       dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
                           2 * DWARF2_ADDR_SIZE);
       for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
@@ -6425,7 +7104,7 @@ output_aranges ()
   dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
                        text_section_label, "Length");
 
-  for (i = 0; i < arange_table_in_use; ++i)
+  for (i = 0; i < arange_table_in_use; i++)
     {
       dw_die_ref die = arange_table[i];
 
@@ -6436,7 +7115,7 @@ output_aranges ()
       if (die->die_tag == DW_TAG_subprogram)
        {
          dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
-                                "Address");
+                              "Address");
          dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
                                get_AT_low_pc (die), "Length");
        }
@@ -6445,9 +7124,9 @@ output_aranges ()
          /* A static variable; extract the symbol from DW_AT_location.
             Note that this code isn't currently hit, as we only emit
             aranges for functions (jason 9/23/99).  */
-
          dw_attr_ref a = get_AT (die, DW_AT_location);
          dw_loc_descr_ref loc;
+
          if (! a || AT_class (a) != dw_val_class_loc)
            abort ();
 
@@ -6481,8 +7160,10 @@ add_ranges (block)
     {
       ranges_table_allocated += RANGES_TABLE_INCREMENT;
       ranges_table = (dw_ranges_ref)
-       xrealloc (ranges_table, (ranges_table_allocated
-                                * sizeof (struct dw_ranges_struct)));
+       ggc_realloc (ranges_table, (ranges_table_allocated
+                                   * sizeof (struct dw_ranges_struct)));
+      memset (ranges_table + ranges_table_in_use, 0,
+             RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
     }
 
   ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
@@ -6498,7 +7179,7 @@ output_ranges ()
   static const char *const start_fmt = "Offset 0x%x";
   const char *fmt = start_fmt;
 
-  for (i = 0; i < ranges_table_in_use; ++i)
+  for (i = 0; i < ranges_table_in_use; i++)
     {
       int block_num = ranges_table[i].block_num;
 
@@ -6521,6 +7202,7 @@ output_ranges ()
              dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
                                    text_section_label, NULL);
            }
+
          /* Otherwise, we add a DW_AT_entry_pc attribute to force the
             compilation unit base address to zero, which allows us to
             use absolute addresses, and not worry about whether the
@@ -6567,6 +7249,7 @@ struct dir_info
 
 /* Callback function for file_info comparison.  We sort by looking at
    the directories in the path.  */
+
 static int
 file_info_cmp (p1, p2)
      const void *p1;
@@ -6577,11 +7260,13 @@ file_info_cmp (p1, p2)
   unsigned char *cp1;
   unsigned char *cp2;
 
-  /* Take care of file names without directories.  */
-  if (s1->path == s1->fname)
-    return -1;
-  else if (s2->path == s2->fname)
-    return 1;
+  /* Take care of file names without directories.  We need to make sure that
+     we return consistent values to qsort since some will get confused if
+     we return the same value when identical operands are passed in opposite
+     orders.  So if neither has a directory, return 0 and otherwise return
+     1 or -1 depending on which one has the directory.  */
+  if ((s1->path == s1->fname || s2->path == s2->fname))
+    return (s2->path == s2->fname) - (s1->path == s1->fname);
 
   cp1 = (unsigned char *) s1->path;
   cp2 = (unsigned char *) s2->path;
@@ -6590,17 +7275,14 @@ file_info_cmp (p1, p2)
     {
       ++cp1;
       ++cp2;
-      /* Reached the end of the first path?  */
-      if (cp1 == (unsigned char *) s1->fname)
-       /* It doesn't really matter in which order files from the
-          same directory are sorted in.  Therefore don't test for
-          the second path reaching the end.  */
-       return -1;
-      else if (cp2 == (unsigned char *) s2->fname)
-       return 1;
+      /* Reached the end of the first path?  If so, handle like above.  */
+      if ((cp1 == (unsigned char *) s1->fname)
+         || (cp2 == (unsigned char *) s2->fname))
+       return ((cp2 == (unsigned char *) s2->fname)
+               - (cp1 == (unsigned char *) s1->fname));
 
       /* Character of current path component the same?  */
-      if (*cp1 != *cp2)
+      else if (*cp1 != *cp2)
        return *cp1 - *cp2;
     }
 }
@@ -6608,6 +7290,7 @@ file_info_cmp (p1, p2)
 /* Output the directory table and the file name table.  We try to minimize
    the total amount of memory needed.  A heuristic is used to avoid large
    slowdowns with many input files.  */
+
 static void
 output_file_names ()
 {
@@ -6616,24 +7299,32 @@ output_file_names ()
   int *saved;
   int *savehere;
   int *backmap;
-  int ndirs;
+  size_t ndirs;
   int idx_offset;
-  int i;
+  size_t i;
   int idx;
 
+  /* Handle the case where file_table is empty.  */
+  if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
+    {
+      dw2_asm_output_data (1, 0, "End directory table");
+      dw2_asm_output_data (1, 0, "End file name table");
+      return;
+    }
+
   /* Allocate the various arrays we need.  */
-  files = (struct file_info *) alloca (file_table.in_use
+  files = (struct file_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
                                       * sizeof (struct file_info));
-  dirs = (struct dir_info *) alloca (file_table.in_use
+  dirs = (struct dir_info *) alloca (VARRAY_ACTIVE_SIZE (file_table)
                                     * sizeof (struct dir_info));
 
   /* Sort the file names.  */
-  for (i = 1; i < (int) file_table.in_use; ++i)
+  for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
     {
       char *f;
 
       /* Skip all leading "./".  */
-      f = file_table.table[i];
+      f = VARRAY_CHAR_PTR (file_table, i);
       while (f[0] == '.' && f[1] == '/')
        f += 2;
 
@@ -6646,7 +7337,9 @@ output_file_names ()
       f = strrchr (f, '/');
       files[i].fname = f == NULL ? files[i].path : f + 1;
     }
-  qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
+
+  qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
+        sizeof (files[0]), file_info_cmp);
 
   /* Find all the different directories used.  */
   dirs[0].path = files[1].path;
@@ -6658,7 +7351,7 @@ output_file_names ()
   files[1].dir_idx = 0;
   ndirs = 1;
 
-  for (i = 2; i < (int) file_table.in_use; ++i)
+  for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
     if (files[i].fname - files[i].path == dirs[ndirs - 1].length
        && memcmp (dirs[ndirs - 1].path, files[i].path,
                   dirs[ndirs - 1].length) == 0)
@@ -6669,7 +7362,7 @@ output_file_names ()
       }
     else
       {
-       int j;
+       size_t j;
 
        /* This is a new directory.  */
        dirs[ndirs].path = files[i].path;
@@ -6681,7 +7374,7 @@ output_file_names ()
 
        /* Search for a prefix.  */
        dirs[ndirs].prefix = -1;
-       for (j = 0; j < ndirs; ++j)
+       for (j = 0; j < ndirs; j++)
          if (dirs[j].length < dirs[ndirs].length
              && dirs[j].length > 1
              && (dirs[ndirs].prefix == -1
@@ -6692,32 +7385,29 @@ output_file_names ()
        ++ndirs;
       }
 
-  /* Now to the actual work.  We have to find a subset of the
-     directories which allow expressing the file name using references
-     to the directory table with the least amount of characters.  We
-     do not do an exhaustive search where we would have to check out
-     every combination of every single possible prefix.  Instead we
-     use a heuristic which provides nearly optimal results in most
-     cases and never is much off.  */
+  /* Now to the actual work.  We have to find a subset of the directories which
+     allow expressing the file name using references to the directory table
+     with the least amount of characters.  We do not do an exhaustive search
+     where we would have to check out every combination of every single
+     possible prefix.  Instead we use a heuristic which provides nearly optimal
+     results in most cases and never is much off.  */
   saved = (int *) alloca (ndirs * sizeof (int));
   savehere = (int *) alloca (ndirs * sizeof (int));
 
   memset (saved, '\0', ndirs * sizeof (saved[0]));
-  for (i = 0; i < ndirs; ++i)
+  for (i = 0; i < ndirs; i++)
     {
-      int j;
+      size_t j;
       int total;
 
-      /* We can always save some space for the current directory.  But
-        this does not mean it will be enough to justify adding the
-        directory.  */
+      /* We can always save some space for the current directory.  But this
+        does not mean it will be enough to justify adding the directory.  */
       savehere[i] = dirs[i].length;
       total = (savehere[i] - saved[i]) * dirs[i].count;
 
-      for (j = i + 1; j < ndirs; ++j)
+      for (j = i + 1; j < ndirs; j++)
        {
          savehere[j] = 0;
-
          if (saved[j] < dirs[i].length)
            {
              /* Determine whether the dirs[i] path is a prefix of the
@@ -6725,10 +7415,10 @@ output_file_names ()
              int k;
 
              k = dirs[j].prefix;
-             while (k != -1 && k != i)
+             while (k != -1 && k != (int) i)
                k = dirs[k].prefix;
 
-             if (k == i)
+             if (k == (int) i)
                {
                  /* Yes it is.  We can possibly safe some memory but
                     writing the filenames in dirs[j] relative to
@@ -6744,7 +7434,7 @@ output_file_names ()
       if (total > dirs[i].length + 1)
        {
          /* It's worthwhile adding.  */
-          for (j = i; j < ndirs; ++j)
+         for (j = i; j < ndirs; j++)
            if (savehere[j] > 0)
              {
                /* Remember how much we saved for this directory so far.  */
@@ -6756,33 +7446,33 @@ output_file_names ()
        }
     }
 
-  /* We have to emit them in the order they appear in the file_table
-     array since the index is used in the debug info generation.  To
-     do this efficiently we generate a back-mapping of the indices
-     first.  */
-  backmap = (int *) alloca (file_table.in_use * sizeof (int));
-  for (i = 1; i < (int) file_table.in_use; ++i)
+  /* We have to emit them in the order they appear in the file_table array
+     since the index is used in the debug info generation.  To do this
+     efficiently we generate a back-mapping of the indices first.  */
+  backmap = (int *) alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
+  for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
     {
       backmap[files[i].file_idx] = i;
+
       /* Mark this directory as used.  */
       dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
     }
 
-  /* That was it.  We are ready to emit the information.  First the
-     directory name table.  Here we have to make sure that the first
-     actually emitted directory name has the index one.  Zero is
-     reserved for the current working directory.  Make sure we do not
-     confuse these indices with the one for the constructed table
-     (even though most of the time they are identical).  */
+  /* That was it.  We are ready to emit the information.  First emit the
+     directory name table.  We have to make sure the first actually emitted
+     directory name has index one; zero is reserved for the current working
+     directory.  Make sure we do not confuse these indices with the one for the
+     constructed table (even though most of the time they are identical).  */
   idx = 1;
   idx_offset = dirs[0].length > 0 ? 1 : 0;
-  for (i = 1 - idx_offset; i < ndirs; ++i)
+  for (i = 1 - idx_offset; i < ndirs; i++)
     if (dirs[i].used != 0)
       {
        dirs[i].used = idx++;
        dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
                                "Directory Entry: 0x%x", dirs[i].used);
       }
+
   dw2_asm_output_data (1, 0, "End directory table");
 
   /* Correct the index for the current working directory entry if it
@@ -6791,7 +7481,7 @@ output_file_names ()
     dirs[0].used = 0;
 
   /* Now write all the file names.  */
-  for (i = 1; i < (int) file_table.in_use; ++i)
+  for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
     {
       int file_idx = backmap[i];
       int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
@@ -6808,6 +7498,7 @@ output_file_names ()
       /* File length in bytes.  */
       dw2_asm_output_data_uleb128 (0, NULL);
     }
+
   dw2_asm_output_data (1, 0, "End file name table");
 }
 
@@ -6840,26 +7531,30 @@ output_line_info ()
   ASM_OUTPUT_LABEL (asm_out_file, l1);
 
   dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
-
   dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
   ASM_OUTPUT_LABEL (asm_out_file, p1);
 
-  dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
+  /* Define the architecture-dependent minimum instruction length (in
+   bytes).  In this implementation of DWARF, this field is used for
+   information purposes only.  Since GCC generates assembly language,
+   we have no a priori knowledge of how many instruction bytes are
+   generated for each source line, and therefore can use only the
+   DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
+   commands.  Accordingly, we fix this as `1', which is "correct
+   enough" for all architectures, and don't let the target override.  */
+  dw2_asm_output_data (1, 1,
                       "Minimum Instruction Length");
 
   dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
                       "Default is_stmt_start flag");
-
   dw2_asm_output_data (1, DWARF_LINE_BASE,
                       "Line Base Value (Special Opcodes)");
-
   dw2_asm_output_data (1, DWARF_LINE_RANGE,
                       "Line Range Value (Special Opcodes)");
-
   dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
                       "Special Opcode Base");
 
-  for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
+  for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
     {
       switch (opc)
        {
@@ -6902,8 +7597,8 @@ output_line_info ()
         prologue.  */
 
       /* Don't emit anything for redundant notes.  Just updating the
-         address doesn't accomplish anything, because we already assume
-         that anything after the last address is this line.  */
+        address doesn't accomplish anything, because we already assume
+        that anything after the last address is this line.  */
       if (line_info->dw_line_num == current_line
          && line_info->dw_file_num == current_file)
        continue;
@@ -6912,7 +7607,7 @@ output_line_info ()
       /* Emit debug info for the address of the current line.
 
         Unfortunately, we have little choice here currently, and must always
-        use the most general form.  Gcc does not know the address delta
+        use the most general form.  GCC does not know the address delta
         itself, so we can't use DW_LNS_advance_pc.  Many ports do have length
         attributes which will give an upper bound on the address range.  We
         could perhaps use length attributes to determine when it is safe to
@@ -6929,12 +7624,13 @@ output_line_info ()
       else
        {
          /* This can handle any delta.  This takes
-             4+DWARF2_ADDR_SIZE bytes.  */
+            4+DWARF2_ADDR_SIZE bytes.  */
          dw2_asm_output_data (1, 0, "DW_LNE_set_address");
          dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
          dw2_asm_output_data (1, DW_LNE_set_address, NULL);
          dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
        }
+
       strcpy (prev_line_label, line_label);
 
       /* Emit debug info for the source file of the current line, if
@@ -6944,7 +7640,8 @@ output_line_info ()
          current_file = line_info->dw_file_num;
          dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
          dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
-                                      file_table.table[current_file]);
+                                      VARRAY_CHAR_PTR (file_table,
+                                                       current_file));
        }
 
       /* Emit debug info for the current line number, choosing the encoding
@@ -6955,13 +7652,11 @@ output_line_info ()
          line_delta = line_offset - DWARF_LINE_BASE;
          current_line = line_info->dw_line_num;
          if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
-           {
-             /* This can handle deltas from -10 to 234, using the current
-                definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.  This
-                takes 1 byte.  */
-             dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
-                                  "line %lu", current_line);
-           }
+           /* This can handle deltas from -10 to 234, using the current
+              definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.  This
+              takes 1 byte.  */
+           dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
+                                "line %lu", current_line);
          else
            {
              /* This can handle any delta.  This takes at least 4 bytes,
@@ -6973,10 +7668,8 @@ output_line_info ()
            }
        }
       else
-       {
-         /* We still need to start a new row, so output a copy insn.  */
-         dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
-       }
+       /* We still need to start a new row, so output a copy insn.  */
+       dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
     }
 
   /* Emit debug info for the address of the end of the function.  */
@@ -7046,6 +7739,7 @@ output_line_info ()
              dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
            }
        }
+
       strcpy (prev_line_label, line_label);
 
       /* Emit debug info for the source file of the current line, if
@@ -7055,7 +7749,8 @@ output_line_info ()
          current_file = line_info->dw_file_num;
          dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
          dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
-                                      file_table.table[current_file]);
+                                      VARRAY_CHAR_PTR (file_table,
+                                                       current_file));
        }
 
       /* Emit debug info for the current line number, choosing the encoding
@@ -7082,7 +7777,8 @@ output_line_info ()
 #if 0
     cont:
 #endif
-      ++lt_index;
+
+      lt_index++;
 
       /* If we're done with a function, end its sequence.  */
       if (lt_index == separate_line_info_table_in_use
@@ -7133,8 +7829,7 @@ base_type_die (type)
   enum dwarf_type encoding;
   tree name = TYPE_NAME (type);
 
-  if (TREE_CODE (type) == ERROR_MARK
-      || TREE_CODE (type) == VOID_TYPE)
+  if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
     return 0;
 
   if (name)
@@ -7151,9 +7846,9 @@ base_type_die (type)
     {
     case INTEGER_TYPE:
       /* Carefully distinguish the C character types, without messing
-         up if the language is not C. Note that we check only for the names
-         that contain spaces; other names might occur by coincidence in other
-         languages.  */
+        up if the language is not C. Note that we check only for the names
+        that contain spaces; other names might occur by coincidence in other
+        languages.  */
       if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
             && (type == char_type_node
                 || ! strcmp (type_name, "signed char")
@@ -7194,10 +7889,11 @@ base_type_die (type)
       break;
 
     default:
-      abort (); /* No other TREE_CODEs are Dwarf fundamental types.  */
+      /* No other TREE_CODEs are Dwarf fundamental types.  */
+      abort ();
     }
 
-  base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
+  base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
   if (demangle_name_func)
     type_name = (*demangle_name_func) (type_name);
 
@@ -7239,7 +7935,7 @@ root_type (type)
     }
 }
 
-/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
+/* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
    given input type is a Dwarf "fundamental" type.  Otherwise return null.  */
 
 static inline int
@@ -7280,6 +7976,27 @@ is_base_type (type)
   return 0;
 }
 
+/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
+   node, return the size in bits for the type if it is a constant, or else
+   return the alignment for the type if the type's size is not constant, or
+   else return BITS_PER_WORD if the type actually turns out to be an
+   ERROR_MARK node.  */
+
+static inline unsigned HOST_WIDE_INT
+simple_type_size_in_bits (type)
+     tree type;
+{
+
+  if (TREE_CODE (type) == ERROR_MARK)
+    return BITS_PER_WORD;
+  else if (TYPE_SIZE (type) == NULL_TREE)
+    return 0;
+  else if (host_integerp (TYPE_SIZE (type), 1))
+    return tree_low_cst (TYPE_SIZE (type), 1);
+  else
+    return TYPE_ALIGN (type);
+}
+
 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
    entry that chains various modifiers in front of the given type.  */
 
@@ -7301,11 +8018,12 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
 
       /* See if we already have the appropriately qualified variant of
         this type.  */
-      qualified_type 
+      qualified_type
        = get_qualified_type (type,
                              ((is_const_type ? TYPE_QUAL_CONST : 0)
-                              | (is_volatile_type 
+                              | (is_volatile_type
                                  ? TYPE_QUAL_VOLATILE : 0)));
+
       /* If we do, then we can just use its DIE, if it exists.  */
       if (qualified_type)
        {
@@ -7315,19 +8033,19 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
        }
 
       /* Handle C typedef types.  */
-      if (qualified_type && TYPE_NAME (qualified_type) 
+      if (qualified_type && TYPE_NAME (qualified_type)
          && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
          && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
        {
          tree type_name = TYPE_NAME (qualified_type);
          tree dtype = TREE_TYPE (type_name);
+
          if (qualified_type == dtype)
            {
              /* For a named type, use the typedef.  */
              gen_type_die (qualified_type, context_die);
              mod_type_die = lookup_type_die (qualified_type);
            }
-
          else if (is_const_type < TYPE_READONLY (dtype)
                   || is_volatile_type < TYPE_VOLATILE (dtype))
            /* cv-unqualified version of named type.  Just use the unnamed
@@ -7336,6 +8054,7 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
              = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
                                   is_const_type, is_volatile_type,
                                   context_die);
+
          /* Else cv-qualified version of named type; fall through.  */
        }
 
@@ -7344,18 +8063,19 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
        ;
       else if (is_const_type)
        {
-         mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
+         mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
          sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
        }
       else if (is_volatile_type)
        {
-         mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
+         mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
          sub_die = modified_type_die (type, 0, 0, context_die);
        }
       else if (code == POINTER_TYPE)
        {
-         mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
-         add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+         mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
+         add_AT_unsigned (mod_type_die, DW_AT_byte_size,
+                          simple_type_size_in_bits (type) / BITS_PER_UNIT);
 #if 0
          add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
@@ -7363,8 +8083,9 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
        }
       else if (code == REFERENCE_TYPE)
        {
-         mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
-         add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+         mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
+         add_AT_unsigned (mod_type_die, DW_AT_byte_size,
+                          simple_type_size_in_bits (type) / BITS_PER_UNIT);
 #if 0
          add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
@@ -7382,17 +8103,22 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
             copy was created to help us keep track of typedef names) and
             that copy might have a different TYPE_UID from the original
             ..._TYPE node.  */
-         mod_type_die = lookup_type_die (type_main_variant (type));
+         if (TREE_CODE (type) != VECTOR_TYPE)
+           mod_type_die = lookup_type_die (type_main_variant (type));
+         else
+           /* Vectors have the debugging information in the type,
+              not the main variant.  */
+           mod_type_die = lookup_type_die (type);
          if (mod_type_die == NULL)
            abort ();
        }
 
       /* We want to equate the qualified type to the die below.  */
-      if (qualified_type)
-       type = qualified_type;
+      type = qualified_type;
     }
 
-  equate_type_number_to_die (type, mod_type_die);
+  if (type)
+    equate_type_number_to_die (type, mod_type_die);
   if (item_type)
     /* We must do this after the equate_type_number_to_die call, in case
        this is a recursive type.  This ensures that the modified_type_die
@@ -7428,29 +8154,96 @@ reg_number (rtl)
   unsigned regno = REGNO (rtl);
 
   if (regno >= FIRST_PSEUDO_REGISTER)
-    {
-      warning ("internal regno botch: regno = %d\n", regno);
-      regno = 0;
-    }
+    abort ();
+
+  return DBX_REGISTER_NUMBER (regno);
+}
+
+/* Return a location descriptor that designates a machine register or
+   zero if there is none.  */
+
+static dw_loc_descr_ref
+reg_loc_descriptor (rtl)
+     rtx rtl;
+{
+  unsigned reg;
+  rtx regs;
+
+  if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
+    return 0;
+
+  reg = reg_number (rtl);
+  regs = (*targetm.dwarf_register_span) (rtl);
+
+  if (HARD_REGNO_NREGS (reg, GET_MODE (rtl)) > 1
+      || regs)
+    return multiple_reg_loc_descriptor (rtl, regs);
+  else
+    return one_reg_loc_descriptor (reg);
+}
+
+/* Return a location descriptor that designates a machine register for
+   a given hard register number.  */
 
-  regno = DBX_REGISTER_NUMBER (regno);
-  return regno;
+static dw_loc_descr_ref
+one_reg_loc_descriptor (regno)
+     unsigned int regno;
+{
+  if (regno <= 31)
+    return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
+  else
+    return new_loc_descr (DW_OP_regx, regno, 0);
 }
 
-/* Return a location descriptor that designates a machine register.  */
+/* Given an RTL of a register, return a location descriptor that
+   designates a value that spans more than one register.  */
 
 static dw_loc_descr_ref
-reg_loc_descriptor (rtl)
-     rtx rtl;
+multiple_reg_loc_descriptor (rtl, regs)
+     rtx rtl, regs;
 {
+  int nregs, size, i;
+  unsigned reg;
   dw_loc_descr_ref loc_result = NULL;
-  unsigned reg = reg_number (rtl);
 
-  if (reg <= 31)
-    loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
-  else
-    loc_result = new_loc_descr (DW_OP_regx, reg, 0);
+  reg = reg_number (rtl);
+  nregs = HARD_REGNO_NREGS (reg, GET_MODE (rtl));
+
+  /* Simple, contiguous registers.  */
+  if (regs == NULL_RTX)
+    {
+      size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
+
+      loc_result = NULL;
+      while (nregs--)
+       {
+         dw_loc_descr_ref t;
+
+         t = one_reg_loc_descriptor (reg);
+         add_loc_descr (&loc_result, t);
+         add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
+         ++reg;
+       }
+      return loc_result;
+    }
+
+  /* Now onto stupid register sets in non contiguous locations.  */
+
+  if (GET_CODE (regs) != PARALLEL)
+    abort ();
 
+  size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
+  loc_result = NULL;
+
+  for (i = 0; i < XVECLEN (regs, 0); ++i)
+    {
+      dw_loc_descr_ref t;
+
+      t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
+      add_loc_descr (&loc_result, t);
+      size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
+      add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
+    }
   return loc_result;
 }
 
@@ -7525,9 +8318,10 @@ static inline int
 is_based_loc (rtl)
      rtx rtl;
 {
-    return (GET_CODE (rtl) == PLUS
-           && ((GET_CODE (XEXP (rtl, 0)) == REG
-                && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
+  return (GET_CODE (rtl) == PLUS
+         && ((GET_CODE (XEXP (rtl, 0)) == REG
+              && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
+              && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
 }
 
 /* The following routine converts the RTL for a variable or parameter
@@ -7541,7 +8335,9 @@ is_based_loc (rtl)
    it into Dwarf postfix code as it goes.
 
    MODE is the mode of the memory reference, needed to handle some
-   autoincrement addressing modes.  */
+   autoincrement addressing modes.
+
+   Return 0 if we can't represent the location.  */
 
 static dw_loc_descr_ref
 mem_loc_descriptor (rtl, mode)
@@ -7549,14 +8345,13 @@ mem_loc_descriptor (rtl, mode)
      enum machine_mode mode;
 {
   dw_loc_descr_ref mem_loc_result = NULL;
+
   /* Note that for a dynamically sized array, the location we will generate a
      description of here will be the lowest numbered location which is
      actually within the array.  That's *not* necessarily the same as the
      zeroth element of the array.  */
 
-#ifdef ASM_SIMPLIFY_DWARF_ADDR
-  rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
-#endif
+  rtl = (*targetm.delegitimize_address) (rtl);
 
   switch (GET_CODE (rtl))
     {
@@ -7566,38 +8361,40 @@ mem_loc_descriptor (rtl, mode)
       /* POST_INC and POST_DEC can be handled just like a SUBREG.  So we
         just fall into the SUBREG code.  */
 
-      /* Fall through.  */
+      /* ... fall through ...  */
 
     case SUBREG:
       /* The case of a subreg may arise when we have a local (register)
-         variable or a formal (register) parameter which doesn't quite fill
-         up an entire register.  For now, just assume that it is
-         legitimate to make the Dwarf info refer to the whole register which
-         contains the given subreg.  */
+        variable or a formal (register) parameter which doesn't quite fill
+        up an entire register.  For now, just assume that it is
+        legitimate to make the Dwarf info refer to the whole register which
+        contains the given subreg.  */
       rtl = SUBREG_REG (rtl);
 
-      /* Fall through.  */
+      /* ... fall through ...  */
 
     case REG:
       /* Whenever a register number forms a part of the description of the
-         method for calculating the (dynamic) address of a memory resident
-         object, DWARF rules require the register number be referred to as
-         a "base register".  This distinction is not based in any way upon
-         what category of register the hardware believes the given register
-         belongs to.  This is strictly DWARF terminology we're dealing with
-         here. Note that in cases where the location of a memory-resident
-         data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
-         OP_CONST (0)) the actual DWARF location descriptor that we generate
-         may just be OP_BASEREG (basereg).  This may look deceptively like
-         the object in question was allocated to a register (rather than in
-         memory) so DWARF consumers need to be aware of the subtle
-         distinction between OP_REG and OP_BASEREG.  */
-      mem_loc_result = based_loc_descr (reg_number (rtl), 0);
+        method for calculating the (dynamic) address of a memory resident
+        object, DWARF rules require the register number be referred to as
+        a "base register".  This distinction is not based in any way upon
+        what category of register the hardware believes the given register
+        belongs to.  This is strictly DWARF terminology we're dealing with
+        here. Note that in cases where the location of a memory-resident
+        data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
+        OP_CONST (0)) the actual DWARF location descriptor that we generate
+        may just be OP_BASEREG (basereg).  This may look deceptively like
+        the object in question was allocated to a register (rather than in
+        memory) so DWARF consumers need to be aware of the subtle
+        distinction between OP_REG and OP_BASEREG.  */
+      if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
+       mem_loc_result = based_loc_descr (reg_number (rtl), 0);
       break;
 
     case MEM:
       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
-      add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
+      if (mem_loc_result != 0)
+       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
       break;
 
     case LABEL_REF:
@@ -7608,22 +8405,37 @@ mem_loc_descriptor (rtl, mode)
     case SYMBOL_REF:
       /* Alternatively, the symbol in the constant pool might be referenced
         by a different symbol.  */
-      if (GET_CODE (rtl) == SYMBOL_REF
-         && CONSTANT_POOL_ADDRESS_P (rtl))
+      if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
        {
-         rtx tmp = get_pool_constant (rtl);
+         bool marked;
+         rtx tmp = get_pool_constant_mark (rtl, &marked);
+
          if (GET_CODE (tmp) == SYMBOL_REF)
-           rtl = tmp;
+           {
+             rtl = tmp;
+             if (CONSTANT_POOL_ADDRESS_P (tmp))
+               get_pool_constant_mark (tmp, &marked);
+             else
+               marked = true;
+           }
+
+         /* If all references to this pool constant were optimized away,
+            it was not output and thus we can't represent it.
+            FIXME: might try to use DW_OP_const_value here, though
+            DW_OP_piece complicates it.  */
+         if (!marked)
+           return 0;
        }
 
       mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
-      mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
+      mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
+      VARRAY_PUSH_RTX (used_rtx_varray, rtl);
       break;
 
     case PRE_MODIFY:
       /* Extract the PLUS expression nested inside and fall into
-         PLUS code below.  */
+        PLUS code below.  */
       rtl = XEXP (rtl, 1);
       goto plus;
 
@@ -7636,7 +8448,7 @@ mem_loc_descriptor (rtl, mode)
                                   ? GET_MODE_UNIT_SIZE (mode)
                                   : -GET_MODE_UNIT_SIZE (mode)));
 
-      /* Fall through.  */
+      /* ... fall through ...  */
 
     case PLUS:
     plus:
@@ -7646,14 +8458,14 @@ mem_loc_descriptor (rtl, mode)
       else
        {
          mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
+         if (mem_loc_result == 0)
+           break;
 
          if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
              && INTVAL (XEXP (rtl, 1)) >= 0)
-           {
-             add_loc_descr (&mem_loc_result,
-                            new_loc_descr (DW_OP_plus_uconst,
-                                           INTVAL (XEXP (rtl, 1)), 0));
-           }
+           add_loc_descr (&mem_loc_result,
+                          new_loc_descr (DW_OP_plus_uconst,
+                                         INTVAL (XEXP (rtl, 1)), 0));
          else
            {
              add_loc_descr (&mem_loc_result,
@@ -7665,19 +8477,33 @@ mem_loc_descriptor (rtl, mode)
       break;
 
     case MULT:
-      /* If a pseudo-reg is optimized away, it is possible for it to
-        be replaced with a MEM containing a multiply.  */
-      add_loc_descr (&mem_loc_result,
-                    mem_loc_descriptor (XEXP (rtl, 0), mode));
-      add_loc_descr (&mem_loc_result,
-                    mem_loc_descriptor (XEXP (rtl, 1), mode));
-      add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
-      break;
+      {
+       /* If a pseudo-reg is optimized away, it is possible for it to
+          be replaced with a MEM containing a multiply.  */
+       dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
+       dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
+
+       if (op0 == 0 || op1 == 0)
+         break;
+
+       mem_loc_result = op0;
+       add_loc_descr (&mem_loc_result, op1);
+       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
+       break;
+      }
 
     case CONST_INT:
       mem_loc_result = int_loc_descriptor (INTVAL (rtl));
       break;
 
+    case ADDRESSOF:
+      /* If this is a MEM, return its address.  Otherwise, we can't
+        represent this.  */
+      if (GET_CODE (XEXP (rtl, 0)) == MEM)
+       return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
+      else
+       return 0;
+
     default:
       abort ();
     }
@@ -7693,18 +8519,21 @@ concat_loc_descriptor (x0, x1)
      rtx x0, x1;
 {
   dw_loc_descr_ref cc_loc_result = NULL;
+  dw_loc_descr_ref x0_ref = loc_descriptor (x0);
+  dw_loc_descr_ref x1_ref = loc_descriptor (x1);
+
+  if (x0_ref == 0 || x1_ref == 0)
+    return 0;
 
-  if (!is_pseudo_reg (x0)
-      && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
-    add_loc_descr (&cc_loc_result, loc_descriptor (x0));
+  cc_loc_result = x0_ref;
   add_loc_descr (&cc_loc_result,
-                new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
+                new_loc_descr (DW_OP_piece,
+                               GET_MODE_SIZE (GET_MODE (x0)), 0));
 
-  if (!is_pseudo_reg (x1)
-      && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
-    add_loc_descr (&cc_loc_result, loc_descriptor (x1));
+  add_loc_descr (&cc_loc_result, x1_ref);
   add_loc_descr (&cc_loc_result,
-                new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
+                new_loc_descr (DW_OP_piece,
+                               GET_MODE_SIZE (GET_MODE (x1)), 0));
 
   return cc_loc_result;
 }
@@ -7713,24 +8542,27 @@ concat_loc_descriptor (x0, x1)
    which is either allocated in a register or in a memory location.  For a
    register, we just generate an OP_REG and the register number.  For a
    memory location we provide a Dwarf postfix expression describing how to
-   generate the (dynamic) address of the object onto the address stack.  */
+   generate the (dynamic) address of the object onto the address stack.
+
+   If we don't know how to describe it, return 0.  */
 
 static dw_loc_descr_ref
 loc_descriptor (rtl)
      rtx rtl;
 {
   dw_loc_descr_ref loc_result = NULL;
+
   switch (GET_CODE (rtl))
     {
     case SUBREG:
       /* The case of a subreg may arise when we have a local (register)
-         variable or a formal (register) parameter which doesn't quite fill
-         up an entire register.  For now, just assume that it is
-         legitimate to make the Dwarf info refer to the whole register which
-         contains the given subreg.  */
+        variable or a formal (register) parameter which doesn't quite fill
+        up an entire register.  For now, just assume that it is
+        legitimate to make the Dwarf info refer to the whole register which
+        contains the given subreg.  */
       rtl = SUBREG_REG (rtl);
 
-      /* Fall through.  */
+      /* ... fall through ...  */
 
     case REG:
       loc_result = reg_loc_descriptor (rtl);
@@ -7751,16 +8583,18 @@ loc_descriptor (rtl)
   return loc_result;
 }
 
-/* Similar, but generate the descriptor from trees instead of rtl.
-   This comes up particularly with variable length arrays.  */
+/* Similar, but generate the descriptor from trees instead of rtl.  This comes
+   up particularly with variable length arrays.  If ADDRESSP is nonzero, we are
+   looking for an address.  Otherwise, we return a value.  If we can't make a
+   descriptor, return 0.  */
 
 static dw_loc_descr_ref
 loc_descriptor_from_tree (loc, addressp)
      tree loc;
      int addressp;
 {
-  dw_loc_descr_ref ret = NULL;
-  int indirect_size = 0;
+  dw_loc_descr_ref ret, ret1;
+  int indirect_p = 0;
   int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
   enum dwarf_location_atom op;
 
@@ -7771,37 +8605,94 @@ loc_descriptor_from_tree (loc, addressp)
   switch (TREE_CODE (loc))
     {
     case ERROR_MARK:
-      break;
+      return 0;
 
     case WITH_RECORD_EXPR:
+    case PLACEHOLDER_EXPR:
       /* This case involves extracting fields from an object to determine the
         position of other fields.  We don't try to encode this here.  The
         only user of this is Ada, which encodes the needed information using
         the names of types.  */
-      return ret;
+      return 0;
+
+    case CALL_EXPR:
+      return 0;
+
+    case ADDR_EXPR:
+      /* We can support this only if we can look through conversions and
+        find an INDIRECT_EXPR.  */
+      for (loc = TREE_OPERAND (loc, 0);
+          TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
+          || TREE_CODE (loc) == NON_LVALUE_EXPR
+          || TREE_CODE (loc) == VIEW_CONVERT_EXPR
+          || TREE_CODE (loc) == SAVE_EXPR;
+          loc = TREE_OPERAND (loc, 0))
+       ;
+
+       return (TREE_CODE (loc) == INDIRECT_REF
+              ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
+              : 0);
 
     case VAR_DECL:
+      if (DECL_THREAD_LOCAL (loc))
+       {
+         rtx rtl;
+
+#ifndef ASM_OUTPUT_DWARF_DTPREL
+         /* If this is not defined, we have no way to emit the data.  */
+         return 0;
+#endif
+
+         /* The way DW_OP_GNU_push_tls_address is specified, we can only
+            look up addresses of objects in the current module.  */
+         if (DECL_EXTERNAL (loc))
+           return 0;
+
+         rtl = rtl_for_decl_location (loc);
+         if (rtl == NULL_RTX)
+           return 0;
+
+         if (GET_CODE (rtl) != MEM)
+           return 0;
+         rtl = XEXP (rtl, 0);
+         if (! CONSTANT_P (rtl))
+           return 0;
+
+         ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
+         ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
+         ret->dw_loc_oprnd1.v.val_addr = rtl;
+
+         ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
+         add_loc_descr (&ret, ret1);
+
+         indirect_p = 1;
+         break;
+       }
+      /* FALLTHRU */
+
     case PARM_DECL:
       {
        rtx rtl = rtl_for_decl_location (loc);
-       enum machine_mode mode = DECL_MODE (loc);
 
        if (rtl == NULL_RTX)
-         break;
+         return 0;
        else if (CONSTANT_P (rtl))
          {
            ret = new_loc_descr (DW_OP_addr, 0, 0);
            ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
            ret->dw_loc_oprnd1.v.val_addr = rtl;
-           indirect_size = GET_MODE_SIZE (mode);
+           indirect_p = 1;
          }
        else
          {
+           enum machine_mode mode = GET_MODE (rtl);
+
            if (GET_CODE (rtl) == MEM)
              {
-               indirect_size = GET_MODE_SIZE (mode);
+               indirect_p = 1;
                rtl = XEXP (rtl, 0);
              }
+
            ret = mem_loc_descriptor (rtl, mode);
          }
       }
@@ -7809,12 +8700,16 @@ loc_descriptor_from_tree (loc, addressp)
 
     case INDIRECT_REF:
       ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
-      indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
+      indirect_p = 1;
       break;
 
+    case COMPOUND_EXPR:
+      return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
+
     case NOP_EXPR:
     case CONVERT_EXPR:
     case NON_LVALUE_EXPR:
+    case VIEW_CONVERT_EXPR:
     case SAVE_EXPR:
       return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
 
@@ -7827,11 +8722,17 @@ loc_descriptor_from_tree (loc, addressp)
        HOST_WIDE_INT bitsize, bitpos, bytepos;
        enum machine_mode mode;
        int volatilep;
-       unsigned int alignment;
 
        obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
-                                  &unsignedp, &volatilep, &alignment);
+                                  &unsignedp, &volatilep);
+
+       if (obj == loc)
+         return 0;
+
        ret = loc_descriptor_from_tree (obj, 1);
+       if (ret == 0
+           || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
+         return 0;
 
        if (offset != NULL_TREE)
          {
@@ -7840,24 +8741,8 @@ loc_descriptor_from_tree (loc, addressp)
            add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
          }
 
-       if (addressp)
-         {
-           /* We cannot address anything not on a unit boundary.  */
-           if (bitpos % BITS_PER_UNIT != 0)
-             abort ();
-         }
-       else
-         {
-           if (bitpos % BITS_PER_UNIT != 0
-               || bitsize % BITS_PER_UNIT != 0)
-             {
-               /* ??? We could handle this by loading and shifting etc.
-                  Wait until someone needs it before expending the effort.  */
-               abort ();
-             }
-
-           indirect_size = bitsize / BITS_PER_UNIT;
-         }
+       if (!addressp)
+         indirect_p = 1;
 
        bytepos = bitpos / BITS_PER_UNIT;
        if (bytepos > 0)
@@ -7873,40 +8758,59 @@ loc_descriptor_from_tree (loc, addressp)
     case INTEGER_CST:
       if (host_integerp (loc, 0))
        ret = int_loc_descriptor (tree_low_cst (loc, 0));
+      else
+       return 0;
       break;
 
+    case TRUTH_AND_EXPR:
+    case TRUTH_ANDIF_EXPR:
     case BIT_AND_EXPR:
       op = DW_OP_and;
       goto do_binop;
+
+    case TRUTH_XOR_EXPR:
     case BIT_XOR_EXPR:
       op = DW_OP_xor;
       goto do_binop;
+
+    case TRUTH_OR_EXPR:
+    case TRUTH_ORIF_EXPR:
     case BIT_IOR_EXPR:
       op = DW_OP_or;
       goto do_binop;
+
     case TRUNC_DIV_EXPR:
       op = DW_OP_div;
       goto do_binop;
+
     case MINUS_EXPR:
       op = DW_OP_minus;
       goto do_binop;
+
     case TRUNC_MOD_EXPR:
       op = DW_OP_mod;
       goto do_binop;
+
     case MULT_EXPR:
       op = DW_OP_mul;
       goto do_binop;
+
     case LSHIFT_EXPR:
       op = DW_OP_shl;
       goto do_binop;
+
     case RSHIFT_EXPR:
       op = (unsignedp ? DW_OP_shr : DW_OP_shra);
       goto do_binop;
+
     case PLUS_EXPR:
       if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
          && host_integerp (TREE_OPERAND (loc, 1), 0))
        {
          ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
+         if (ret == 0)
+           return 0;
+
          add_loc_descr (&ret,
                         new_loc_descr (DW_OP_plus_uconst,
                                        tree_low_cst (TREE_OPERAND (loc, 1),
@@ -7914,53 +8818,74 @@ loc_descriptor_from_tree (loc, addressp)
                                        0));
          break;
        }
+
       op = DW_OP_plus;
       goto do_binop;
+
     case LE_EXPR:
       if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
-       break;
+       return 0;
+
       op = DW_OP_le;
       goto do_binop;
+
     case GE_EXPR:
       if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
-       break;
+       return 0;
+
       op = DW_OP_ge;
       goto do_binop;
+
     case LT_EXPR:
       if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
-       break;
+       return 0;
+
       op = DW_OP_lt;
       goto do_binop;
+
     case GT_EXPR:
       if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
-       break;
+       return 0;
+
       op = DW_OP_gt;
       goto do_binop;
+
     case EQ_EXPR:
       op = DW_OP_eq;
       goto do_binop;
+
     case NE_EXPR:
       op = DW_OP_ne;
       goto do_binop;
 
     do_binop:
       ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
-      add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
+      ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
+      if (ret == 0 || ret1 == 0)
+       return 0;
+
+      add_loc_descr (&ret, ret1);
       add_loc_descr (&ret, new_loc_descr (op, 0, 0));
       break;
 
+    case TRUTH_NOT_EXPR:
     case BIT_NOT_EXPR:
       op = DW_OP_not;
       goto do_unop;
+
     case ABS_EXPR:
       op = DW_OP_abs;
       goto do_unop;
+
     case NEGATE_EXPR:
       op = DW_OP_neg;
       goto do_unop;
 
     do_unop:
       ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
+      if (ret == 0)
+       return 0;
+
       add_loc_descr (&ret, new_loc_descr (op, 0, 0));
       break;
 
@@ -7969,25 +8894,31 @@ loc_descriptor_from_tree (loc, addressp)
                   build (LT_EXPR, integer_type_node,
                          TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
                   TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
-      /* FALLTHRU */
+
+      /* ... fall through ...  */
 
     case COND_EXPR:
       {
+       dw_loc_descr_ref lhs
+         = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
+       dw_loc_descr_ref rhs
+         = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
        dw_loc_descr_ref bra_node, jump_node, tmp;
 
        ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
+       if (ret == 0 || lhs == 0 || rhs == 0)
+         return 0;
+
        bra_node = new_loc_descr (DW_OP_bra, 0, 0);
        add_loc_descr (&ret, bra_node);
 
-       tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
-       add_loc_descr (&ret, tmp);
+       add_loc_descr (&ret, rhs);
        jump_node = new_loc_descr (DW_OP_skip, 0, 0);
        add_loc_descr (&ret, jump_node);
 
-       tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
-       add_loc_descr (&ret, tmp);
+       add_loc_descr (&ret, lhs);
        bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
-       bra_node->dw_loc_oprnd1.v.val_loc = tmp;
+       bra_node->dw_loc_oprnd1.v.val_loc = lhs;
 
        /* ??? Need a node to point the skip at.  Use a nop.  */
        tmp = new_loc_descr (DW_OP_nop, 0, 0);
@@ -8001,20 +8932,23 @@ loc_descriptor_from_tree (loc, addressp)
       abort ();
     }
 
-  /* If we can't fill the request for an address, die.  */
-  if (addressp && indirect_size == 0)
-    abort ();
+  /* Show if we can't fill the request for an address.  */
+  if (addressp && indirect_p == 0)
+    return 0;
 
   /* If we've got an address and don't want one, dereference.  */
-  if (!addressp && indirect_size > 0)
+  if (!addressp && indirect_p > 0)
     {
-      if (indirect_size > DWARF2_ADDR_SIZE)
-       abort ();
-      if (indirect_size == DWARF2_ADDR_SIZE)
+      HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
+
+      if (size > DWARF2_ADDR_SIZE || size == -1)
+       return 0;
+      else if (size == DWARF2_ADDR_SIZE)
        op = DW_OP_deref;
       else
        op = DW_OP_deref_size;
-      add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
+
+      add_loc_descr (&ret, new_loc_descr (op, size, 0));
     }
 
   return ret;
@@ -8070,35 +9004,12 @@ simple_decl_align_in_bits (decl)
   return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
 }
 
-/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
-   node, return the size in bits for the type if it is a constant, or else
-   return the alignment for the type if the type's size is not constant, or
-   else return BITS_PER_WORD if the type actually turns out to be an
-   ERROR_MARK node.  */
-
-static inline unsigned HOST_WIDE_INT
-simple_type_size_in_bits (type)
-     tree type;
-{
-  tree type_size_tree;
-
-  if (TREE_CODE (type) == ERROR_MARK)
-    return BITS_PER_WORD;
-  type_size_tree = TYPE_SIZE (type);
-
-  if (type_size_tree == NULL_TREE)
-    return 0;
-  if (! host_integerp (type_size_tree, 1))
-    return TYPE_ALIGN (type);
-  return tree_low_cst (type_size_tree, 1);
-}
-
-/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
-   return the byte offset of the lowest addressed byte of the "containing
-   object" for the given FIELD_DECL, or return 0 if we are unable to
-   determine what that offset is, either because the argument turns out to
-   be a pointer to an ERROR_MARK node, or because the offset is actually
-   variable.  (We can't handle the latter case just yet).  */
+/* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
+   lowest addressed byte of the "containing object" for the given FIELD_DECL,
+   or return 0 if we are unable to determine what that offset is, either
+   because the argument turns out to be a pointer to an ERROR_MARK node, or
+   because the offset is actually variable.  (We can't handle the latter case
+   just yet).  */
 
 static HOST_WIDE_INT
 field_byte_offset (decl)
@@ -8108,7 +9019,6 @@ field_byte_offset (decl)
   unsigned int decl_align_in_bits;
   unsigned HOST_WIDE_INT type_size_in_bits;
   HOST_WIDE_INT object_offset_in_bits;
-  HOST_WIDE_INT object_offset_in_bytes;
   tree type;
   tree field_size_tree;
   HOST_WIDE_INT bitpos_int;
@@ -8117,8 +9027,7 @@ field_byte_offset (decl)
 
   if (TREE_CODE (decl) == ERROR_MARK)
     return 0;
-
-  if (TREE_CODE (decl) != FIELD_DECL)
+  else if (TREE_CODE (decl) != FIELD_DECL)
     abort ();
 
   type = field_type (decl);
@@ -8147,44 +9056,44 @@ field_byte_offset (decl)
   type_align_in_bits = simple_type_align_in_bits (type);
   decl_align_in_bits = simple_decl_align_in_bits (decl);
 
-  /* Note that the GCC front-end doesn't make any attempt to keep track of
-     the starting bit offset (relative to the start of the containing
-     structure type) of the hypothetical "containing object" for a bit-
-     field.  Thus, when computing the byte offset value for the start of the
-     "containing object" of a bit-field, we must deduce this information on
-     our own. This can be rather tricky to do in some cases.  For example,
-     handling the following structure type definition when compiling for an
-     i386/i486 target (which only aligns long long's to 32-bit boundaries)
-     can be very tricky:
+  /* The GCC front-end doesn't make any attempt to keep track of the starting
+     bit offset (relative to the start of the containing structure type) of the
+     hypothetical "containing object" for a bit-field.  Thus, when computing
+     the byte offset value for the start of the "containing object" of a
+     bit-field, we must deduce this information on our own. This can be rather
+     tricky to do in some cases.  For example, handling the following structure
+     type definition when compiling for an i386/i486 target (which only aligns
+     long long's to 32-bit boundaries) can be very tricky:
 
         struct S { int field1; long long field2:31; };
 
-     Fortunately, there is a simple rule-of-thumb which can be
-     used in such cases.  When compiling for an i386/i486, GCC will allocate
-     8 bytes for the structure shown above.  It decides to do this based upon
-     one simple rule for bit-field allocation.  Quite simply, GCC allocates
-     each "containing object" for each bit-field at the first (i.e. lowest
-     addressed) legitimate alignment boundary (based upon the required
-     minimum alignment for the declared type of the field) which it can
-     possibly use, subject to the condition that there is still enough
-     available space remaining in the containing object (when allocated at
-     the selected point) to fully accommodate all of the bits of the
-     bit-field itself.  This simple rule makes it obvious why GCC allocates
-     8 bytes for each object of the structure type shown above.  When looking
-     for a place to allocate the "containing object" for `field2', the
-     compiler simply tries to allocate a 64-bit "containing object" at each
-     successive 32-bit boundary (starting at zero) until it finds a place to
-     allocate that 64- bit field such that at least 31 contiguous (and
-     previously unallocated) bits remain within that selected 64 bit field.
-     (As it turns out, for the example above, the compiler finds that it is
-     OK to allocate the "containing object" 64-bit field at bit-offset zero
-     within the structure type.) Here we attempt to work backwards from the
-     limited set of facts we're given, and we try to deduce from those facts,
-     where GCC must have believed that the containing object started (within
-     the structure type). The value we deduce is then used (by the callers of
-     this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
-     for fields (both bit-fields and, in the case of DW_AT_location, regular
-     fields as well).  */
+     Fortunately, there is a simple rule-of-thumb which can be used in such
+     cases.  When compiling for an i386/i486, GCC will allocate 8 bytes for the
+     structure shown above.  It decides to do this based upon one simple rule
+     for bit-field allocation.  GCC allocates each "containing object" for each
+     bit-field at the first (i.e. lowest addressed) legitimate alignment
+     boundary (based upon the required minimum alignment for the declared type
+     of the field) which it can possibly use, subject to the condition that
+     there is still enough available space remaining in the containing object
+     (when allocated at the selected point) to fully accommodate all of the
+     bits of the bit-field itself.
+
+     This simple rule makes it obvious why GCC allocates 8 bytes for each
+     object of the structure type shown above.  When looking for a place to
+     allocate the "containing object" for `field2', the compiler simply tries
+     to allocate a 64-bit "containing object" at each successive 32-bit
+     boundary (starting at zero) until it finds a place to allocate that 64-
+     bit field such that at least 31 contiguous (and previously unallocated)
+     bits remain within that selected 64 bit field.  (As it turns out, for the
+     example above, the compiler finds it is OK to allocate the "containing
+     object" 64-bit field at bit-offset zero within the structure type.)
+
+     Here we attempt to work backwards from the limited set of facts we're
+     given, and we try to deduce from those facts, where GCC must have believed
+     that the containing object started (within the structure type). The value
+     we deduce is then used (by the callers of this routine) to generate
+     DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
+     and, in the case of DW_AT_location, regular fields as well).  */
 
   /* Figure out the bit-distance from the start of the structure to the
      "deepest" bit of the bit-field.  */
@@ -8210,9 +9119,7 @@ field_byte_offset (decl)
       object_offset_in_bits *= decl_align_in_bits;
     }
 
-  object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
-
-  return object_offset_in_bytes;
+  return object_offset_in_bits / BITS_PER_UNIT;
 }
 \f
 /* The following routines define various Dwarf attributes and any data
@@ -8224,85 +9131,111 @@ field_byte_offset (decl)
    whole parameters.  Note that the location attributes for struct fields are
    generated by the routine `data_member_location_attribute' below.  */
 
-static void
-add_AT_location_description (die, attr_kind, rtl)
+static inline void
+add_AT_location_description (die, attr_kind, descr)
      dw_die_ref die;
      enum dwarf_attribute attr_kind;
-     rtx rtl;
+     dw_loc_descr_ref descr;
 {
-  /* Handle a special case.  If we are about to output a location descriptor
-     for a variable or parameter which has been optimized out of existence,
-     don't do that.  A variable which has been optimized out
-     of existence will have a DECL_RTL value which denotes a pseudo-reg.
-     Currently, in some rare cases, variables can have DECL_RTL values which
-     look like (MEM (REG pseudo-reg#)).  These cases are due to bugs
-     elsewhere in the compiler.  We treat such cases as if the variable(s) in
-     question had been optimized out of existence.  */
-
-  if (is_pseudo_reg (rtl)
-      || (GET_CODE (rtl) == MEM
-         && is_pseudo_reg (XEXP (rtl, 0)))
-      /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
-        references the internal argument pointer (a pseudo) in a function
-        where all references to the internal argument pointer were
-        eliminated via the optimizers.  */
-      || (GET_CODE (rtl) == MEM
-         && GET_CODE (XEXP (rtl, 0)) == PLUS
-         && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
-      || (GET_CODE (rtl) == CONCAT
-         && is_pseudo_reg (XEXP (rtl, 0))
-         && is_pseudo_reg (XEXP (rtl, 1))))
-    return;
-
-  add_AT_loc (die, attr_kind, loc_descriptor (rtl));
-}
-
-/* Attach the specialized form of location attribute used for data
-   members of struct and union types.  In the special case of a
-   FIELD_DECL node which represents a bit-field, the "offset" part
-   of this special location descriptor must indicate the distance
-   in bytes from the lowest-addressed byte of the containing struct
-   or union type to the lowest-addressed byte of the "containing
-   object" for the bit-field.  (See the `field_byte_offset' function
-   above).. For any given bit-field, the "containing object" is a
-   hypothetical object (of some integral or enum type) within which
-   the given bit-field lives.  The type of this hypothetical
-   "containing object" is always the same as the declared type of
-   the individual bit-field itself (for GCC anyway... the DWARF
-   spec doesn't actually mandate this).  Note that it is the size
-   (in bytes) of the hypothetical "containing object" which will
-   be given in the DW_AT_byte_size attribute for this bit-field.
-   (See the `byte_size_attribute' function below.)  It is also used
-   when calculating the value of the DW_AT_bit_offset attribute.
-   (See the `bit_offset_attribute' function below).  */
+  if (descr != 0)
+    add_AT_loc (die, attr_kind, descr);
+}
+
+/* Attach the specialized form of location attribute used for data members of
+   struct and union types.  In the special case of a FIELD_DECL node which
+   represents a bit-field, the "offset" part of this special location
+   descriptor must indicate the distance in bytes from the lowest-addressed
+   byte of the containing struct or union type to the lowest-addressed byte of
+   the "containing object" for the bit-field.  (See the `field_byte_offset'
+   function above).
+
+   For any given bit-field, the "containing object" is a hypothetical object
+   (of some integral or enum type) within which the given bit-field lives.  The
+   type of this hypothetical "containing object" is always the same as the
+   declared type of the individual bit-field itself (for GCC anyway... the
+   DWARF spec doesn't actually mandate this).  Note that it is the size (in
+   bytes) of the hypothetical "containing object" which will be given in the
+   DW_AT_byte_size attribute for this bit-field.  (See the
+   `byte_size_attribute' function below.)  It is also used when calculating the
+   value of the DW_AT_bit_offset attribute.  (See the `bit_offset_attribute'
+   function below.)  */
 
 static void
 add_data_member_location_attribute (die, decl)
      dw_die_ref die;
      tree decl;
 {
-  unsigned long offset;
-  dw_loc_descr_ref loc_descr;
-  enum dwarf_location_atom op;
+  long offset;
+  dw_loc_descr_ref loc_descr = 0;
 
   if (TREE_CODE (decl) == TREE_VEC)
-    offset = tree_low_cst (BINFO_OFFSET (decl), 0);
+    {
+      /* We're working on the TAG_inheritance for a base class.  */
+      if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
+       {
+         /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
+            aren't at a fixed offset from all (sub)objects of the same
+            type.  We need to extract the appropriate offset from our
+            vtable.  The following dwarf expression means
+
+              BaseAddr = ObAddr + *((*ObAddr) - Offset)
+
+            This is specific to the V3 ABI, of course.  */
+
+         dw_loc_descr_ref tmp;
+
+         /* Make a copy of the object address.  */
+         tmp = new_loc_descr (DW_OP_dup, 0, 0);
+         add_loc_descr (&loc_descr, tmp);
+
+         /* Extract the vtable address.  */
+         tmp = new_loc_descr (DW_OP_deref, 0, 0);
+         add_loc_descr (&loc_descr, tmp);
+
+         /* Calculate the address of the offset.  */
+         offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
+         if (offset >= 0)
+           abort ();
+
+         tmp = int_loc_descriptor (-offset);
+         add_loc_descr (&loc_descr, tmp);
+         tmp = new_loc_descr (DW_OP_minus, 0, 0);
+         add_loc_descr (&loc_descr, tmp);
+
+         /* Extract the offset.  */
+         tmp = new_loc_descr (DW_OP_deref, 0, 0);
+         add_loc_descr (&loc_descr, tmp);
+
+         /* Add it to the object address.  */
+         tmp = new_loc_descr (DW_OP_plus, 0, 0);
+         add_loc_descr (&loc_descr, tmp);
+       }
+      else
+       offset = tree_low_cst (BINFO_OFFSET (decl), 0);
+    }
   else
     offset = field_byte_offset (decl);
 
-  /* The DWARF2 standard says that we should assume that the structure address
-     is already on the stack, so we can specify a structure field address
-     by using DW_OP_plus_uconst.  */
+  if (! loc_descr)
+    {
+      enum dwarf_location_atom op;
+
+      /* The DWARF2 standard says that we should assume that the structure
+        address is already on the stack, so we can specify a structure field
+        address by using DW_OP_plus_uconst.  */
 
 #ifdef MIPS_DEBUGGING_INFO
-  /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
-     correctly.  It works only if we leave the offset on the stack.  */
-  op = DW_OP_constu;
+      /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
+        operator correctly.  It works only if we leave the offset on the
+        stack.  */
+      op = DW_OP_constu;
 #else
-  op = DW_OP_plus_uconst;
+      op = DW_OP_plus_uconst;
 #endif
 
-  loc_descr = new_loc_descr (op, offset, 0);
+      loc_descr = new_loc_descr (op, offset, 0);
+    }
+
   add_AT_loc (die, DW_AT_data_member_location, loc_descr);
 }
 
@@ -8327,35 +9260,36 @@ add_const_value_attribute (die, rtl)
         out, and the CONST_INT rtx is assigned VOIDmode.  */
       {
        HOST_WIDE_INT val = INTVAL (rtl);
-       
+
        /* ??? We really should be using HOST_WIDE_INT throughout.  */
-       if (val < 0)
-         {
-           if ((long) val != val)
-             abort ();
-           add_AT_int (die, DW_AT_const_value, (long) val);
-         }
+       if (val < 0 && (long) val == val)
+         add_AT_int (die, DW_AT_const_value, (long) val);
+       else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
+         add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
        else
          {
-           if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
-             abort ();
-           add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
+#if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
+           add_AT_long_long (die, DW_AT_const_value,
+                             val >> HOST_BITS_PER_LONG, val);
+#else
+           abort ();
+#endif
          }
       }
       break;
 
     case CONST_DOUBLE:
       /* Note that a CONST_DOUBLE rtx could represent either an integer or a
-         floating-point constant.  A CONST_DOUBLE is used whenever the
-         constant requires more than one word in order to be adequately
-         represented.  We output CONST_DOUBLEs as blocks.  */
+        floating-point constant.  A CONST_DOUBLE is used whenever the
+        constant requires more than one word in order to be adequately
+        represented.  We output CONST_DOUBLEs as blocks.  */
       {
        enum machine_mode mode = GET_MODE (rtl);
 
        if (GET_MODE_CLASS (mode) == MODE_FLOAT)
          {
            unsigned length = GET_MODE_SIZE (mode) / 4;
-           long *array = (long *) xmalloc (sizeof (long) * length);
+           long *array = (long *) ggc_alloc (sizeof (long) * length);
            REAL_VALUE_TYPE rv;
 
            REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
@@ -8385,6 +9319,7 @@ add_const_value_attribute (die, rtl)
            /* ??? We really should be using HOST_WIDE_INT throughout.  */
            if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
              abort ();
+
            add_AT_long_long (die, DW_AT_const_value,
                              CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
          }
@@ -8398,21 +9333,22 @@ add_const_value_attribute (die, rtl)
     case SYMBOL_REF:
     case LABEL_REF:
     case CONST:
-      add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
+      add_AT_addr (die, DW_AT_const_value, rtl);
+      VARRAY_PUSH_RTX (used_rtx_varray, rtl);
       break;
 
     case PLUS:
       /* In cases where an inlined instance of an inline function is passed
-         the address of an `auto' variable (which is local to the caller) we
-         can get a situation where the DECL_RTL of the artificial local
-         variable (for the inlining) which acts as a stand-in for the
-         corresponding formal parameter (of the inline function) will look
-         like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).  This is not
-         exactly a compile-time constant expression, but it isn't the address
-         of the (artificial) local variable either.  Rather, it represents the
-         *value* which the artificial local variable always has during its
-         lifetime.  We currently have no way to represent such quasi-constant
-         values in Dwarf, so for now we just punt and generate nothing.  */
+        the address of an `auto' variable (which is local to the caller) we
+        can get a situation where the DECL_RTL of the artificial local
+        variable (for the inlining) which acts as a stand-in for the
+        corresponding formal parameter (of the inline function) will look
+        like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).  This is not
+        exactly a compile-time constant expression, but it isn't the address
+        of the (artificial) local variable either.  Rather, it represents the
+        *value* which the artificial local variable always has during its
+        lifetime.  We currently have no way to represent such quasi-constant
+        values in Dwarf, so for now we just punt and generate nothing.  */
       break;
 
     default:
@@ -8477,36 +9413,52 @@ rtl_for_decl_location (decl)
      the correct data, so we allow for such exceptional cases below.
 
      Note that our goal here is to describe the place where the given formal
-     parameter lives during most of the function's activation (i.e. between
-     the end of the prologue and the start of the epilogue).  We'll do that
-     as best as we can. Note however that if the given formal parameter is
-     modified sometime during the execution of the function, then a stack
-     backtrace (at debug-time) will show the function as having been
-     called with the *new* value rather than the value which was
-     originally passed in.  This happens rarely enough that it is not
-     a major problem, but it *is* a problem, and I'd like to fix it.
-
-     A future version of dwarf2out.c may generate two additional
-     attributes for any given DW_TAG_formal_parameter DIE which will
-     describe the "passed type" and the "passed location" for the
-     given formal parameter in addition to the attributes we now
-     generate to indicate the "declared type" and the "active
-     location" for each parameter.  This additional set of attributes
-     could be used by debuggers for stack backtraces. Separately, note
-     that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
-     NULL also.  This happens (for example) for inlined-instances of
-     inline function formal parameters which are never referenced.
-     This really shouldn't be happening.  All PARM_DECL nodes should
-     get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
-     doesn't currently generate these values for inlined instances of
-     inline function parameters, so when we see such cases, we are
-     just out-of-luck for the time being (until integrate.c
+     parameter lives during most of the function's activation (i.e. between the
+     end of the prologue and the start of the epilogue).  We'll do that as best
+     as we can. Note however that if the given formal parameter is modified
+     sometime during the execution of the function, then a stack backtrace (at
+     debug-time) will show the function as having been called with the *new*
+     value rather than the value which was originally passed in.  This happens
+     rarely enough that it is not a major problem, but it *is* a problem, and
+     I'd like to fix it.
+
+     A future version of dwarf2out.c may generate two additional attributes for
+     any given DW_TAG_formal_parameter DIE which will describe the "passed
+     type" and the "passed location" for the given formal parameter in addition
+     to the attributes we now generate to indicate the "declared type" and the
+     "active location" for each parameter.  This additional set of attributes
+     could be used by debuggers for stack backtraces. Separately, note that
+     sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
+     This happens (for example) for inlined-instances of inline function formal
+     parameters which are never referenced.  This really shouldn't be
+     happening.  All PARM_DECL nodes should get valid non-NULL
+     DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
+     values for inlined instances of inline function parameters, so when we see
+     such cases, we are just out-of-luck for the time being (until integrate.c
      gets fixed).  */
 
   /* Use DECL_RTL as the "location" unless we find something better.  */
   rtl = DECL_RTL_IF_SET (decl);
 
-  if (TREE_CODE (decl) == PARM_DECL)
+  /* When generating abstract instances, ignore everything except
+     constants, symbols living in memory, and symbols living in
+     fixed registers.  */
+  if (! reload_completed)
+    {
+      if (rtl
+         && (CONSTANT_P (rtl)
+             || (GET_CODE (rtl) == MEM
+                 && CONSTANT_P (XEXP (rtl, 0)))
+             || (GET_CODE (rtl) == REG
+                 && TREE_CODE (decl) == VAR_DECL
+                 && TREE_STATIC (decl))))
+       {
+         rtl = (*targetm.delegitimize_address) (rtl);
+         return rtl;
+       }
+      rtl = NULL_RTX;
+    }
+  else if (TREE_CODE (decl) == PARM_DECL)
     {
       if (rtl == NULL_RTX || is_pseudo_reg (rtl))
        {
@@ -8515,7 +9467,7 @@ rtl_for_decl_location (decl)
 
          /* This decl represents a formal parameter which was optimized out.
             Note that DECL_INCOMING_RTL may be NULL in here, but we handle
-            all* cases where (rtl == NULL_RTX) just below.  */
+            all cases where (rtl == NULL_RTX) just below.  */
          if (declared_type == passed_type)
            rtl = DECL_INCOMING_RTL (decl);
          else if (! BYTES_BIG_ENDIAN
@@ -8553,6 +9505,7 @@ rtl_for_decl_location (decl)
        {
          int offset = (UNITS_PER_WORD
                        - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
+
          rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
                             plus_constant (XEXP (rtl, 0), offset));
        }
@@ -8567,6 +9520,54 @@ rtl_for_decl_location (decl)
 #endif
     }
 
+  /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
+     and will have been substituted directly into all expressions that use it.
+     C does not have such a concept, but C++ and other languages do.  */
+  else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
+    {
+      /* If a variable is initialized with a string constant without embedded
+        zeros, build CONST_STRING.  */
+      if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
+         && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
+       {
+         tree arrtype = TREE_TYPE (decl);
+         tree enttype = TREE_TYPE (arrtype);
+         tree domain = TYPE_DOMAIN (arrtype);
+         tree init = DECL_INITIAL (decl);
+         enum machine_mode mode = TYPE_MODE (enttype);
+
+         if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
+             && domain
+             && integer_zerop (TYPE_MIN_VALUE (domain))
+             && compare_tree_int (TYPE_MAX_VALUE (domain),
+                                  TREE_STRING_LENGTH (init) - 1) == 0
+             && ((size_t) TREE_STRING_LENGTH (init)
+                 == strlen (TREE_STRING_POINTER (init)) + 1))
+           rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
+       }
+      /* If the initializer is something that we know will expand into an
+        immediate RTL constant, expand it now.  Expanding anything else
+        tends to produce unresolved symbols; see debug/5770 and c++/6381.  */
+      else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
+              || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
+       {
+         rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
+                            EXPAND_INITIALIZER);
+         /* If expand_expr returns a MEM, it wasn't immediate.  */
+         if (rtl && GET_CODE (rtl) == MEM)
+           abort ();
+       }
+    }
+
+  if (rtl)
+    rtl = (*targetm.delegitimize_address) (rtl);
+
+  /* If we don't look past the constant pool, we risk emitting a
+     reference to a constant pool entry that isn't referenced from
+     code, and thus is not emitted.  */
+  if (rtl)
+    rtl = avoid_constant_pool_reference (rtl);
+
   return rtl;
 }
 
@@ -8587,27 +9588,22 @@ add_location_or_const_value_attribute (die, decl)
      tree decl;
 {
   rtx rtl;
+  dw_loc_descr_ref descr;
 
   if (TREE_CODE (decl) == ERROR_MARK)
     return;
-
-  if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
+  else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
     abort ();
 
   rtl = rtl_for_decl_location (decl);
   if (rtl == NULL_RTX)
     return;
 
-  /* If we don't look past the constant pool, we risk emitting a
-     reference to a constant pool entry that isn't referenced from
-     code, and thus is not emitted.  */
-  rtl = avoid_constant_pool_reference (rtl);
-
   switch (GET_CODE (rtl))
     {
     case ADDRESSOF:
-      /* The address of a variable that was optimized away; don't emit
-        anything.  */
+      /* The address of a variable that was optimized away;
+        don't emit anything.  */
       break;
 
     case CONST_INT:
@@ -8622,12 +9618,24 @@ add_location_or_const_value_attribute (die, decl)
       break;
 
     case MEM:
-    case REG:
-    case SUBREG:
-    case CONCAT:
-      add_AT_location_description (die, DW_AT_location, rtl);
+      if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
+       {
+         /* Need loc_descriptor_from_tree since that's where we know
+            how to handle TLS variables.  Want the object's address
+            since the top-level DW_AT_location assumes such.  See
+            the confusion in loc_descriptor for reference.  */
+         descr = loc_descriptor_from_tree (decl, 1);
+       }
+      else
+       {
+       case REG:
+       case SUBREG:
+       case CONCAT:
+         descr = loc_descriptor (rtl);
+       }
+      add_AT_location_description (die, DW_AT_location, descr);
       break;
-
+       
     default:
       abort ();
     }
@@ -8656,7 +9664,7 @@ tree_add_const_value_attribute (var_die, decl)
     case INTEGER_TYPE:
       if (host_integerp (init, 0))
        add_AT_unsigned (var_die, DW_AT_const_value,
-                        TREE_INT_CST_LOW (init));
+                        tree_low_cst (init, 0));
       else
        add_AT_long_long (var_die, DW_AT_const_value,
                          TREE_INT_CST_HIGH (init),
@@ -8670,7 +9678,7 @@ tree_add_const_value_attribute (var_die, decl)
 /* Generate an DW_AT_name attribute given some string value to be included as
    the value of the attribute.  */
 
-static inline void
+static void
 add_name_attribute (die, name_string)
      dw_die_ref die;
      const char *name_string;
@@ -8684,6 +9692,17 @@ add_name_attribute (die, name_string)
     }
 }
 
+/* Generate an DW_AT_comp_dir attribute for DIE.  */
+
+static void
+add_comp_dir_attribute (die)
+     dw_die_ref die;
+{
+  const char *wd = getpwd ();
+  if (wd != NULL)
+    add_AT_string (die, DW_AT_comp_dir, wd);
+}
+
 /* Given a tree node describing an array bound (either lower or upper) output
    a representation for that bound.  */
 
@@ -8693,18 +9712,12 @@ add_bound_info (subrange_die, bound_attr, bound)
      enum dwarf_attribute bound_attr;
      tree bound;
 {
-  /* If this is an Ada unconstrained array type, then don't emit any debug
-     info because the array bounds are unknown.  They are parameterized when
-     the type is instantiated.  */
-  if (contains_placeholder_p (bound))
-    return;
-
   switch (TREE_CODE (bound))
     {
     case ERROR_MARK:
       return;
 
-    /* All fixed-bounds are represented by INTEGER_CST nodes.        */
+    /* All fixed-bounds are represented by INTEGER_CST nodes.  */
     case INTEGER_CST:
       if (! host_integerp (bound, 0)
          || (bound_attr == DW_AT_lower_bound
@@ -8719,28 +9732,29 @@ add_bound_info (subrange_die, bound_attr, bound)
     case CONVERT_EXPR:
     case NOP_EXPR:
     case NON_LVALUE_EXPR:
+    case VIEW_CONVERT_EXPR:
       add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
       break;
 
     case SAVE_EXPR:
       /* If optimization is turned on, the SAVE_EXPRs that describe how to
-         access the upper bound values may be bogus.  If they refer to a
-         register, they may only describe how to get at these values at the
-         points in the generated code right after they have just been
-         computed.  Worse yet, in the typical case, the upper bound values
-         will not even *be* computed in the optimized code (though the
-         number of elements will), so these SAVE_EXPRs are entirely
-         bogus. In order to compensate for this fact, we check here to see
-         if optimization is enabled, and if so, we don't add an attribute
-         for the (unknown and unknowable) upper bound.  This should not
-         cause too much trouble for existing (stupid?)  debuggers because
-         they have to deal with empty upper bounds location descriptions
-         anyway in order to be able to deal with incomplete array types.
-         Of course an intelligent debugger (GDB?)  should be able to
-         comprehend that a missing upper bound specification in an array
-         type used for a storage class `auto' local array variable
-         indicates that the upper bound is both unknown (at compile- time)
-         and unknowable (at run-time) due to optimization.
+        access the upper bound values may be bogus.  If they refer to a
+        register, they may only describe how to get at these values at the
+        points in the generated code right after they have just been
+        computed.  Worse yet, in the typical case, the upper bound values
+        will not even *be* computed in the optimized code (though the
+        number of elements will), so these SAVE_EXPRs are entirely
+        bogus. In order to compensate for this fact, we check here to see
+        if optimization is enabled, and if so, we don't add an attribute
+        for the (unknown and unknowable) upper bound.  This should not
+        cause too much trouble for existing (stupid?)  debuggers because
+        they have to deal with empty upper bounds location descriptions
+        anyway in order to be able to deal with incomplete array types.
+        Of course an intelligent debugger (GDB?)  should be able to
+        comprehend that a missing upper bound specification in an array
+        type used for a storage class `auto' local array variable
+        indicates that the upper bound is both unknown (at compile- time)
+        and unknowable (at run-time) due to optimization.
 
         We assume that a MEM rtx is safe because gcc wouldn't put the
         value there unless it was going to be used repeatedly in the
@@ -8749,12 +9763,11 @@ add_bound_info (subrange_die, bound_attr, bound)
          && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
        {
          dw_die_ref ctx = lookup_decl_die (current_function_decl);
-         dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
+         dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
          rtx loc = SAVE_EXPR_RTL (bound);
 
          /* If the RTL for the SAVE_EXPR is memory, handle the case where
             it references an outer function's frame.  */
-
          if (GET_CODE (loc) == MEM)
            {
              rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
@@ -8765,7 +9778,8 @@ add_bound_info (subrange_die, bound_attr, bound)
 
          add_AT_flag (decl_die, DW_AT_artificial, 1);
          add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
-         add_AT_location_description (decl_die, DW_AT_location, loc);
+         add_AT_location_description (decl_die, DW_AT_location,
+                                      loc_descriptor (loc));
          add_AT_die_ref (subrange_die, bound_attr, decl_die);
        }
 
@@ -8799,9 +9813,21 @@ add_bound_info (subrange_die, bound_attr, bound)
        if (loc == NULL)
          break;
 
-       ctx = lookup_decl_die (current_function_decl);
-
-       decl_die = new_die (DW_TAG_variable, ctx);
+       if (current_function_decl == 0)
+         ctx = comp_unit_die;
+       else
+         ctx = lookup_decl_die (current_function_decl);
+
+       /* If we weren't able to find a context, it's most likely the case
+          that we are processing the return type of the function.  So
+          make a SAVE_EXPR to point to it and have the limbo DIE code
+          find the proper die.  The save_expr function doesn't always
+          make a SAVE_EXPR, so do it ourselves.  */
+       if (ctx == 0)
+         bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
+                        current_function_decl, NULL_TREE);
+
+       decl_die = new_die (DW_TAG_variable, ctx, bound);
        add_AT_flag (decl_die, DW_AT_artificial, 1);
        add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
        add_AT_loc (decl_die, DW_AT_location, loc);
@@ -8843,14 +9869,14 @@ add_subscript_info (type_die, type)
   for (dimension_number = 0;
        TREE_CODE (type) == ARRAY_TYPE;
        type = TREE_TYPE (type), dimension_number++)
-    {
 #endif
+    {
       tree domain = TYPE_DOMAIN (type);
 
       /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
         and (in GNU C only) variable bounds.  Handle all three forms
-         here.  */
-      subrange_die = new_die (DW_TAG_subrange_type, type_die);
+        here.  */
+      subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
       if (domain)
        {
          /* We have an array type with specified bounds.  */
@@ -8884,15 +9910,11 @@ add_subscript_info (type_die, type)
          if (upper)
            add_bound_info (subrange_die, DW_AT_upper_bound, upper);
        }
-      else
-       /* We have an array type with an unspecified length.  The DWARF-2
-            spec does not say how to handle this; let's just leave out the
-            bounds.  */
-        {;}
 
-#ifndef MIPS_DEBUGGING_INFO
+      /* Otherwise we have an array type with an unspecified length.  The
+        DWARF-2 spec does not say how to handle this; let's just leave out the
+        bounds.  */
     }
-#endif
 }
 
 static void
@@ -8915,9 +9937,9 @@ add_byte_size_attribute (die, tree_node)
       break;
     case FIELD_DECL:
       /* For a data member of a struct or union, the DW_AT_byte_size is
-         generally given as the number of bytes normally allocated for an
-         object of the *declared* type of the member itself.  This is true
-         even for bit-fields.  */
+        generally given as the number of bytes normally allocated for an
+        object of the *declared* type of the member itself.  This is true
+        even for bit-fields.  */
       size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
       break;
     default:
@@ -8928,7 +9950,6 @@ add_byte_size_attribute (die, tree_node)
      indicates that the byte size of the entity in question is variable.  We
      have no good way of expressing this fact in Dwarf at the present time,
      so just let the -1 pass on through.  */
-
   add_AT_unsigned (die, DW_AT_byte_size, size);
 }
 
@@ -8937,13 +9958,12 @@ add_byte_size_attribute (die, tree_node)
    "containing object" for the bit-field to the highest order bit of the
    bit-field itself.
 
-   For any given bit-field, the "containing object" is a hypothetical
-   object (of some integral or enum type) within which the given bit-field
-   lives.  The type of this hypothetical "containing object" is always the
-   same as the declared type of the individual bit-field itself.  The
-   determination of the exact location of the "containing object" for a
-   bit-field is rather complicated.  It's handled by the
-   `field_byte_offset' function (above).
+   For any given bit-field, the "containing object" is a hypothetical object
+   (of some integral or enum type) within which the given bit-field lives.  The
+   type of this hypothetical "containing object" is always the same as the
+   declared type of the individual bit-field itself.  The determination of the
+   exact location of the "containing object" for a bit-field is rather
+   complicated.  It's handled by the `field_byte_offset' function (above).
 
    Note that it is the size (in bytes) of the hypothetical "containing object"
    which will be given in the DW_AT_byte_size attribute for this bit-field.
@@ -9044,11 +10064,13 @@ add_abstract_origin_attribute (die, origin)
         function, if we're in an exception handler or some such; make
         sure that the abstract function has been written out.
 
-         Doing this for nested functions is wrong, however; functions are
+        Doing this for nested functions is wrong, however; functions are
         distinct units, and our context might not even be inline.  */
       tree fn = origin;
+
       if (TYPE_P (fn))
        fn = TYPE_STUB_DECL (fn);
+
       fn = decl_function_context (fn);
       if (fn)
        dwarf2out_abstract_function (fn);
@@ -9126,6 +10148,17 @@ add_name_and_src_coords_attributes (die, decl)
        add_AT_string (die, DW_AT_MIPS_linkage_name,
                       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
     }
+
+#ifdef VMS_DEBUGGING_INFO
+  /* Get the function's name, as described by its RTL.  This may be different
+     from the DECL_NAME name used in the source file.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
+    {
+      add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
+                  XEXP (DECL_RTL (decl), 0));
+      VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
+    }
+#endif
 }
 
 /* Push a new declaration scope.  */
@@ -9138,11 +10171,13 @@ push_decl_scope (scope)
 }
 
 /* Pop a declaration scope.  */
+
 static inline void
 pop_decl_scope ()
 {
   if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
     abort ();
+
   VARRAY_POP (decl_scope_table);
 }
 
@@ -9184,7 +10219,6 @@ scope_die_for (t, context_die)
       /* For types, we can just look up the appropriate DIE.  But
         first we check to see if we're in the middle of emitting it
         so we know where the new DIE should go.  */
-
       for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
        if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
          break;
@@ -9207,9 +10241,8 @@ scope_die_for (t, context_die)
   return scope_die;
 }
 
-/* Returns nonzero iff CONTEXT_DIE is internal to a function.  */
+/* Returns nonzero if CONTEXT_DIE is internal to a function.  */
 
-static inline int local_scope_p PARAMS ((dw_die_ref));
 static inline int
 local_scope_p (context_die)
      dw_die_ref context_die;
@@ -9218,12 +10251,12 @@ local_scope_p (context_die)
     if (context_die->die_tag == DW_TAG_inlined_subroutine
        || context_die->die_tag == DW_TAG_subprogram)
       return 1;
+
   return 0;
 }
 
-/* Returns nonzero iff CONTEXT_DIE is a class.  */
+/* Returns nonzero if CONTEXT_DIE is a class.  */
 
-static inline int class_scope_p PARAMS ((dw_die_ref));
 static inline int
 class_scope_p (context_die)
      dw_die_ref context_die;
@@ -9256,19 +10289,18 @@ add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
       && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
     type = TREE_TYPE (type), code = TREE_CODE (type);
 
-  if (code == ERROR_MARK)
-    return;
-
-  /* Handle a special case.  For functions whose return type is void, we
-     generate *no* type attribute.  (Note that no object may have type
-     `void', so this only applies to function return types).  */
-  if (code == VOID_TYPE)
+  if (code == ERROR_MARK
+      /* Handle a special case.  For functions whose return type is void, we
+        generate *no* type attribute.  (Note that no object may have type
+        `void', so this only applies to function return types).  */
+      || code == VOID_TYPE)
     return;
 
   type_die = modified_type_die (type,
                                decl_const || TYPE_READONLY (type),
                                decl_volatile || TYPE_VOLATILE (type),
                                context_die);
+
   if (type_die != NULL)
     add_AT_die_ref (object_die, DW_AT_type, type_die);
 }
@@ -9292,8 +10324,8 @@ type_tag (type)
        t = TYPE_NAME (type);
 
       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
-         a TYPE_DECL node, regardless of whether or not a `typedef' was
-         involved.  */
+        a TYPE_DECL node, regardless of whether or not a `typedef' was
+        involved.  */
       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
               && ! DECL_IGNORED_P (TYPE_NAME (type)))
        t = DECL_NAME (TYPE_NAME (type));
@@ -9314,8 +10346,7 @@ member_declared_type (member)
      tree member;
 {
   return (DECL_BIT_FIELD_TYPE (member)
-         ? DECL_BIT_FIELD_TYPE (member)
-         : TREE_TYPE (member));
+         ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
 }
 
 /* Get the decl's label, as described by its RTL. This may be different
@@ -9328,6 +10359,7 @@ decl_start_label (decl)
 {
   rtx x;
   const char *fnname;
+
   x = DECL_RTL (decl);
   if (GET_CODE (x) != MEM)
     abort ();
@@ -9361,7 +10393,17 @@ gen_array_type_die (type, context_die)
   gen_type_die (TREE_TYPE (type), context_die);
 #endif
 
-  array_die = new_die (DW_TAG_array_type, scope_die);
+  array_die = new_die (DW_TAG_array_type, scope_die, type);
+  add_name_attribute (array_die, type_tag (type));
+  equate_type_number_to_die (type, array_die);
+
+  if (TREE_CODE (type) == VECTOR_TYPE)
+    {
+      /* The frontend feeds us a representation for the vector as a struct
+        containing an array.  Pull out the array type.  */
+      type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
+      add_AT_flag (array_die, DW_AT_GNU_vector, 1);
+    }
 
 #if 0
   /* We default the array ordering.  SDB will probably do
@@ -9383,9 +10425,6 @@ gen_array_type_die (type, context_die)
 #endif
     add_subscript_info (array_die, type);
 
-  add_name_attribute (array_die, type_tag (type));
-  equate_type_number_to_die (type, array_die);
-
   /* Add representation of the type of the elements of this array type.  */
   element_type = TREE_TYPE (type);
 
@@ -9409,7 +10448,7 @@ gen_set_type_die (type, context_die)
      dw_die_ref context_die;
 {
   dw_die_ref type_die
-    = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, type_die);
   add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
@@ -9422,7 +10461,8 @@ gen_entry_point_die (decl, context_die)
      dw_die_ref context_die;
 {
   tree origin = decl_ultimate_origin (decl);
-  dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
+  dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
+
   if (origin != NULL)
     add_abstract_origin_attribute (decl_die, origin);
   else
@@ -9439,14 +10479,6 @@ gen_entry_point_die (decl, context_die)
 }
 #endif
 
-/* Remember a type in the incomplete_types_list.  */
-static void
-add_incomplete_type (type)
-     tree type;
-{
-  VARRAY_PUSH_TREE (incomplete_types, type);
-}
-
 /* Walk through the list of incomplete types again, trying once more to
    emit full debugging info for them.  */
 
@@ -9454,10 +10486,9 @@ static void
 retry_incomplete_types ()
 {
   int i;
+
   for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
-    {
-      gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
-    }
+    gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
 }
 
 /* Generate a DIE to represent an inlined instance of an enumeration type.  */
@@ -9467,7 +10498,8 @@ gen_inlined_enumeration_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
-  dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die);
+  dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
+
   /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
      be incomplete and such types are not marked.  */
   add_abstract_origin_attribute (type_die, type);
@@ -9480,7 +10512,7 @@ gen_inlined_structure_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
-  dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
+  dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
 
   /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
      be incomplete and such types are not marked.  */
@@ -9494,7 +10526,7 @@ gen_inlined_union_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
-  dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
+  dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
 
   /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
      be incomplete and such types are not marked.  */
@@ -9516,7 +10548,7 @@ gen_enumeration_type_die (type, context_die)
   if (type_die == NULL)
     {
       type_die = new_die (DW_TAG_enumeration_type,
-                         scope_die_for (type, context_die));
+                         scope_die_for (type, context_die), type);
       equate_type_number_to_die (type, type_die);
       add_name_attribute (type_die, type_tag (type));
     }
@@ -9545,7 +10577,7 @@ gen_enumeration_type_die (type, context_die)
       for (link = TYPE_FIELDS (type);
           link != NULL; link = TREE_CHAIN (link))
        {
-         dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
+         dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
 
          add_name_attribute (enum_die,
                              IDENTIFIER_POINTER (TREE_PURPOSE (link)));
@@ -9584,7 +10616,7 @@ gen_formal_parameter_die (node, context_die)
      dw_die_ref context_die;
 {
   dw_die_ref parm_die
-    = new_die (DW_TAG_formal_parameter, context_die);
+    = new_die (DW_TAG_formal_parameter, context_die, node);
   tree origin;
 
   switch (TREE_CODE_CLASS (TREE_CODE (node)))
@@ -9627,10 +10659,10 @@ gen_formal_parameter_die (node, context_die)
 
 static void
 gen_unspecified_parameters_die (decl_or_type, context_die)
-     tree decl_or_type ATTRIBUTE_UNUSED;
+     tree decl_or_type;
      dw_die_ref context_die;
 {
-  new_die (DW_TAG_unspecified_parameters, context_die);
+  new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
 }
 
 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
@@ -9655,7 +10687,7 @@ gen_formal_types_die (function_or_method_type, context_die)
     }
   else
     arg = NULL_TREE;
-  
+
   first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
 
   /* Make our first pass over the list of formal parameter types and output a
@@ -9688,15 +10720,9 @@ gen_formal_types_die (function_or_method_type, context_die)
   /* Make our second (and final) pass over the list of formal parameter types
      and output DIEs to represent those types (as necessary).  */
   for (link = TYPE_ARG_TYPES (function_or_method_type);
-       link;
+       link && TREE_VALUE (link);
        link = TREE_CHAIN (link))
-    {
-      formal_type = TREE_VALUE (link);
-      if (formal_type == void_type_node)
-       break;
-
-      gen_type_die (formal_type, context_die);
-    }
+    gen_type_die (TREE_VALUE (link), context_die);
 }
 
 /* We want to generate the DIE for TYPE so that we can generate the
@@ -9725,13 +10751,13 @@ gen_type_die_for_member (type, member, context_die)
        gen_subprogram_die (member, lookup_type_die (type));
       else
        gen_variable_die (member, lookup_type_die (type));
+
       pop_decl_scope ();
     }
 }
 
-/* Generate the DWARF2 info for the "abstract" instance
-   of a function which we may later generate inlined and/or
-   out-of-line instances of.  */
+/* Generate the DWARF2 info for the "abstract" instance of a function which we
+   may later generate inlined and/or out-of-line instances of.  */
 
 static void
 dwarf2out_abstract_function (decl)
@@ -9745,7 +10771,7 @@ dwarf2out_abstract_function (decl)
   /* Make sure we have the actual abstract inline, not a clone.  */
   decl = DECL_ORIGIN (decl);
 
-  old_die = lookup_decl_die (decl);  
+  old_die = lookup_decl_die (decl);
   if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
     /* We've already generated the abstract instance.  */
     return;
@@ -9759,7 +10785,7 @@ dwarf2out_abstract_function (decl)
        gen_type_die_for_member
          (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
     }
+
   /* Pretend we've just finished compiling this function.  */
   save_fn = current_function_decl;
   current_function_decl = decl;
@@ -9790,12 +10816,11 @@ gen_subprogram_die (decl, context_die)
   int declaration = (current_function_decl != decl
                     || class_scope_p (context_die));
 
-  /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
-     be true, if we started to generate the abstract instance of an inline,
-     decided to output its containing class, and proceeded to emit the
-     declaration of the inline from the member list for the class.  In that
-     case, `declaration' takes priority; we'll get back to the abstract
-     instance when we're done with the class.  */
+  /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
+     started to generate the abstract instance of an inline, decided to output
+     its containing class, and proceeded to emit the declaration of the inline
+     from the member list for the class.  If so, DECLARATION takes priority;
+     we'll get back to the abstract instance when done with the class.  */
 
   /* The class-scope declaration DIE must be the primary DIE.  */
   if (origin && declaration && class_scope_p (context_die))
@@ -9815,7 +10840,7 @@ gen_subprogram_die (decl, context_die)
       if (old_die && old_die->die_parent == NULL)
        add_child_die (context_die, old_die);
 
-      subr_die = new_die (DW_TAG_subprogram, context_die);
+      subr_die = new_die (DW_TAG_subprogram, context_die, decl);
       add_abstract_origin_attribute (subr_die, origin);
     }
   else if (old_die)
@@ -9859,7 +10884,7 @@ gen_subprogram_die (decl, context_die)
        }
       else
        {
-         subr_die = new_die (DW_TAG_subprogram, context_die);
+         subr_die = new_die (DW_TAG_subprogram, context_die, decl);
          add_AT_die_ref (subr_die, DW_AT_specification, old_die);
          if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
            add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
@@ -9871,7 +10896,7 @@ gen_subprogram_die (decl, context_die)
     }
   else
     {
-      subr_die = new_die (DW_TAG_subprogram, context_die);
+      subr_die = new_die (DW_TAG_subprogram, context_die, decl);
 
       if (TREE_PUBLIC (decl))
        add_AT_flag (subr_die, DW_AT_external, 1);
@@ -9879,15 +10904,15 @@ gen_subprogram_die (decl, context_die)
       add_name_and_src_coords_attributes (subr_die, decl);
       if (debug_info_level > DINFO_LEVEL_TERSE)
        {
-         tree type = TREE_TYPE (decl);
-
-         add_prototyped_attribute (subr_die, type);
-         add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
+         add_prototyped_attribute (subr_die, TREE_TYPE (decl));
+         add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
+                             0, 0, context_die);
        }
 
       add_pure_or_virtual_attribute (subr_die, decl);
       if (DECL_ARTIFICIAL (decl))
        add_AT_flag (subr_die, DW_AT_artificial, 1);
+
       if (TREE_PROTECTED (decl))
        add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
       else if (TREE_PRIVATE (decl))
@@ -9896,7 +10921,7 @@ gen_subprogram_die (decl, context_die)
 
   if (declaration)
     {
-      if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
+      if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
        {
          add_AT_flag (subr_die, DW_AT_declaration, 1);
 
@@ -9929,14 +10954,14 @@ gen_subprogram_die (decl, context_die)
     }
   else if (!DECL_EXTERNAL (decl))
     {
-      if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
+      if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
        equate_decl_number_to_die (decl, subr_die);
 
       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
-                                  current_funcdef_number);
+                                  current_function_funcdef_no);
       add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
-                                  current_funcdef_number);
+                                  current_function_funcdef_no);
       add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
 
       add_pubname (decl, subr_die);
@@ -9948,8 +10973,8 @@ gen_subprogram_die (decl, context_die)
 #endif
 
       /* Define the "frame base" location for this routine.  We use the
-         frame pointer or stack pointer registers, since the RTL for local
-         variables is relative to one of them.  */
+        frame pointer or stack pointer registers, since the RTL for local
+        variables is relative to one of them.  */
       fp_reg
        = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
       add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
@@ -9959,7 +10984,7 @@ gen_subprogram_die (decl, context_die)
         is not part of the state saved/restored for inline functions.  */
       if (current_function_needs_context)
        add_AT_location_description (subr_die, DW_AT_static_link,
-                                    lookup_static_chain (decl));
+                            loc_descriptor (lookup_static_chain (decl)));
 #endif
     }
 
@@ -9987,7 +11012,7 @@ gen_subprogram_die (decl, context_die)
       tree parm;
 
       /* When generating DIEs, generate the unspecified_parameters DIE
-         instead if we come across the arg "__builtin_va_alist" */
+        instead if we come across the arg "__builtin_va_alist" */
       for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
        if (TREE_CODE (parm) == PARM_DECL)
          {
@@ -10000,11 +11025,11 @@ gen_subprogram_die (decl, context_die)
          }
 
       /* Decide whether we need an unspecified_parameters DIE at the end.
-         There are 2 more cases to do this for: 1) the ansi ... declaration -
-         this is detectable when the end of the arg list is not a
-         void_type_node 2) an unprototyped function declaration (not a
-         definition).  This just means that we have no info about the
-         parameters at all.  */
+        There are 2 more cases to do this for: 1) the ansi ... declaration -
+        this is detectable when the end of the arg list is not a
+        void_type_node 2) an unprototyped function declaration (not a
+        definition).  This just means that we have no info about the
+        parameters at all.  */
       fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
       if (fn_arg_types != NULL)
        {
@@ -10020,19 +11045,19 @@ gen_subprogram_die (decl, context_die)
      (if it has one - it may be just a declaration).  */
   outer_scope = DECL_INITIAL (decl);
 
-  /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
-     node created to represent a function. This outermost BLOCK actually
-     represents the outermost binding contour for the function, i.e. the
-     contour in which the function's formal parameters and labels get
-     declared. Curiously, it appears that the front end doesn't actually
-     put the PARM_DECL nodes for the current function onto the BLOCK_VARS
-     list for this outer scope.  (They are strung off of the DECL_ARGUMENTS
-     list for the function instead.) The BLOCK_VARS list for the
-     `outer_scope' does provide us with a list of the LABEL_DECL nodes for
-     the function however, and we output DWARF info for those in
-     decls_for_scope.  Just within the `outer_scope' there will be a BLOCK
-     node representing the function's outermost pair of curly braces, and
-     any blocks used for the base and member initializers of a C++
+  /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
+     a function.  This BLOCK actually represents the outermost binding contour
+     for the function, i.e. the contour in which the function's formal
+     parameters and labels get declared. Curiously, it appears that the front
+     end doesn't actually put the PARM_DECL nodes for the current function onto
+     the BLOCK_VARS list for this outer scope, but are strung off of the
+     DECL_ARGUMENTS list for the function instead.
+
+     The BLOCK_VARS list for the `outer_scope' does provide us with a list of
+     the LABEL_DECL nodes for the function however, and we output DWARF info
+     for those in decls_for_scope.  Just within the `outer_scope' there will be
+     a BLOCK node representing the function's outermost pair of curly braces,
+     and any blocks used for the base and member initializers of a C++
      constructor function.  */
   if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
     {
@@ -10061,7 +11086,7 @@ gen_variable_die (decl, context_die)
      dw_die_ref context_die;
 {
   tree origin = decl_ultimate_origin (decl);
-  dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
+  dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
 
   dw_die_ref old_die = lookup_decl_die (decl);
   int declaration = (DECL_EXTERNAL (decl)
@@ -10069,14 +11094,17 @@ gen_variable_die (decl, context_die)
 
   if (origin != NULL)
     add_abstract_origin_attribute (var_die, origin);
+
   /* Loop unrolling can create multiple blocks that refer to the same
-     static variable, so we must test for the DW_AT_declaration flag.  */
-  /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
+     static variable, so we must test for the DW_AT_declaration flag.
+
+     ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
      copy decls and set the DECL_ABSTRACT flag on them instead of
-     sharing them.  */
-  /* ??? Duplicated blocks have been rewritten to use .debug_ranges.  */
+     sharing them.
+
+     ??? Duplicated blocks have been rewritten to use .debug_ranges.  */
   else if (old_die && TREE_STATIC (decl)
-          && get_AT_flag (old_die, DW_AT_declaration) == 1)
+          && get_AT_flag (old_die, DW_AT_declaration) == 1)
     {
       /* This is a definition of a C++ class level static.  */
       add_AT_die_ref (var_die, DW_AT_specification, old_die);
@@ -10097,8 +11125,7 @@ gen_variable_die (decl, context_die)
   else
     {
       add_name_and_src_coords_attributes (var_die, decl);
-      add_type_attribute (var_die, TREE_TYPE (decl),
-                         TREE_READONLY (decl),
+      add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
                          TREE_THIS_VOLATILE (decl), context_die);
 
       if (TREE_PUBLIC (decl))
@@ -10109,7 +11136,6 @@ gen_variable_die (decl, context_die)
 
       if (TREE_PROTECTED (decl))
        add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
-
       else if (TREE_PRIVATE (decl))
        add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
     }
@@ -10137,7 +11163,7 @@ gen_label_die (decl, context_die)
      dw_die_ref context_die;
 {
   tree origin = decl_ultimate_origin (decl);
-  dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
+  dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
   rtx insn;
   char label[MAX_ARTIFICIAL_LABEL_BYTES];
 
@@ -10181,7 +11207,7 @@ gen_lexical_block_die (stmt, context_die, depth)
      dw_die_ref context_die;
      int depth;
 {
-  dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
+  dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
   char label[MAX_ARTIFICIAL_LABEL_BYTES];
 
   if (! BLOCK_ABSTRACT (stmt))
@@ -10190,7 +11216,7 @@ gen_lexical_block_die (stmt, context_die, depth)
        {
          tree chain;
 
-         add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
+         add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
 
          chain = BLOCK_FRAGMENT_CHAIN (stmt);
          do
@@ -10226,7 +11252,7 @@ gen_inlined_subroutine_die (stmt, context_die, depth)
   if (! BLOCK_ABSTRACT (stmt))
     {
       dw_die_ref subr_die
-       = new_die (DW_TAG_inlined_subroutine, context_die);
+       = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
       tree decl = block_ultimate_origin (stmt);
       char label[MAX_ARTIFICIAL_LABEL_BYTES];
 
@@ -10243,6 +11269,20 @@ gen_inlined_subroutine_die (stmt, context_die, depth)
       decls_for_scope (stmt, subr_die, depth);
       current_function_has_inlines = 1;
     }
+  else
+    /* We may get here if we're the outer block of function A that was
+       inlined into function B that was inlined into function C.  When
+       generating debugging info for C, dwarf2out_abstract_function(B)
+       would mark all inlined blocks as abstract, including this one.
+       So, we wouldn't (and shouldn't) expect labels to be generated
+       for this one.  Instead, just emit debugging info for
+       declarations within the block.  This is particularly important
+       in the case of initializers of arguments passed from B to us:
+       if they're statement expressions containing declarations, we
+       wouldn't generate dies for their abstract variables, and then,
+       when generating dies for the real variables, we'd die (pun
+       intended :-)  */
+    gen_lexical_block_die (stmt, context_die, depth);
 }
 
 /* Generate a DIE for a field in a record, or structure.  */
@@ -10252,14 +11292,13 @@ gen_field_die (decl, context_die)
      tree decl;
      dw_die_ref context_die;
 {
-  dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
+  dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
 
   add_name_and_src_coords_attributes (decl_die, decl);
   add_type_attribute (decl_die, member_declared_type (decl),
                      TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
                      context_die);
 
-  /* If this is a bit field...  */
   if (DECL_BIT_FIELD_TYPE (decl))
     {
       add_byte_size_attribute (decl_die, decl);
@@ -10275,7 +11314,6 @@ gen_field_die (decl, context_die)
 
   if (TREE_PROTECTED (decl))
     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
-
   else if (TREE_PRIVATE (decl))
     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
 }
@@ -10285,13 +11323,14 @@ gen_field_die (decl, context_die)
    Use modified_type_die instead.
    We keep this code here just in case these types of DIEs may be needed to
    represent certain things in other languages (e.g. Pascal) someday.  */
+
 static void
 gen_pointer_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
   dw_die_ref ptr_die
-    = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, ptr_die);
   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
@@ -10302,13 +11341,14 @@ gen_pointer_type_die (type, context_die)
    Use modified_type_die instead.
    We keep this code here just in case these types of DIEs may be needed to
    represent certain things in other languages (e.g. Pascal) someday.  */
+
 static void
 gen_reference_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
   dw_die_ref ref_die
-    = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, ref_die);
   add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
@@ -10317,13 +11357,15 @@ gen_reference_type_die (type, context_die)
 #endif
 
 /* Generate a DIE for a pointer to a member type.  */
+
 static void
 gen_ptr_to_mbr_type_die (type, context_die)
      tree type;
      dw_die_ref context_die;
 {
   dw_die_ref ptr_die
-    = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_ptr_to_member_type,
+              scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, ptr_die);
   add_AT_die_ref (ptr_die, DW_AT_containing_type,
@@ -10339,14 +11381,17 @@ gen_compile_unit_die (filename)
 {
   dw_die_ref die;
   char producer[250];
-  const char *wd = getpwd ();
+  const char *language_string = lang_hooks.name;
   int language;
 
-  die = new_die (DW_TAG_compile_unit, NULL);
-  add_name_attribute (die, filename);
+  die = new_die (DW_TAG_compile_unit, NULL, NULL);
 
-  if (wd != NULL && filename[0] != DIR_SEPARATOR)
-    add_AT_string (die, DW_AT_comp_dir, wd);
+  if (filename)
+    {
+      add_name_attribute (die, filename);
+      if (filename[0] != DIR_SEPARATOR)
+       add_comp_dir_attribute (die);
+    }
 
   sprintf (producer, "%s %s", language_string, version_string);
 
@@ -10373,13 +11418,10 @@ gen_compile_unit_die (filename)
     language = DW_LANG_Pascal83;
   else if (strcmp (language_string, "GNU Java") == 0)
     language = DW_LANG_Java;
-  else if (flag_traditional)
-    language = DW_LANG_C;
   else
     language = DW_LANG_C89;
 
   add_AT_unsigned (die, DW_AT_language, language);
-
   return die;
 }
 
@@ -10391,34 +11433,36 @@ gen_string_type_die (type, context_die)
      dw_die_ref context_die;
 {
   dw_die_ref type_die
-    = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, type_die);
 
-  /* Fudge the string length attribute for now.  */
-
-  /* TODO: add string length info.
-   string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
-                             bound_representation (upper_bound, 0, 'u'); */
+  /* ??? Fudge the string length attribute for now.
+     TODO: add string length info.  */
+#if 0
+  string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
+  bound_representation (upper_bound, 0, 'u');
+#endif
 }
 
 /* Generate the DIE for a base class.  */
 
 static void
-gen_inheritance_die (binfo, context_die)
-     tree binfo;
+gen_inheritance_die (binfo, access, context_die)
+     tree binfo, access;
      dw_die_ref context_die;
 {
-  dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
+  dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
 
   add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
   add_data_member_location_attribute (die, binfo);
 
   if (TREE_VIA_VIRTUAL (binfo))
     add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
-  if (TREE_VIA_PUBLIC (binfo))
+
+  if (access == access_public_node)
     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
-  else if (TREE_VIA_PROTECTED (binfo))
+  else if (access == access_protected_node)
     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
 }
 
@@ -10430,6 +11474,7 @@ gen_member_die (type, context_die)
      dw_die_ref context_die;
 {
   tree member;
+  tree binfo = TYPE_BINFO (type);
   dw_die_ref child;
 
   /* If this is not an incomplete type, output descriptions of each of its
@@ -10437,23 +11482,25 @@ gen_member_die (type, context_die)
      members of this record or union type, we will also be trying to output
      DIEs to represent the *types* of those members. However the `type'
      function (above) will specifically avoid generating type DIEs for member
-     types *within* the list of member DIEs for this (containing) type execpt
+     types *within* the list of member DIEs for this (containing) type except
      for those types (of members) which are explicitly marked as also being
      members of this (containing) type themselves.  The g++ front- end can
-     force any given type to be treated as a member of some other
-     (containing) type by setting the TYPE_CONTEXT of the given (member) type
-     to point to the TREE node representing the appropriate (containing)
-     type.  */
+     force any given type to be treated as a member of some other (containing)
+     type by setting the TYPE_CONTEXT of the given (member) type to point to
+     the TREE node representing the appropriate (containing) type.  */
 
   /* First output info about the base classes.  */
-  if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
+  if (binfo && BINFO_BASETYPES (binfo))
     {
-      tree bases = TYPE_BINFO_BASETYPES (type);
+      tree bases = BINFO_BASETYPES (binfo);
+      tree accesses = BINFO_BASEACCESSES (binfo);
       int n_bases = TREE_VEC_LENGTH (bases);
       int i;
 
       for (i = 0; i < n_bases; i++)
-       gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
+       gen_inheritance_die (TREE_VEC_ELT (bases, i),
+                            (accesses ? TREE_VEC_ELT (accesses, i)
+                             : access_public_node), context_die);
     }
 
   /* Now output info about the data members and type members.  */
@@ -10518,7 +11565,7 @@ gen_struct_or_union_type_die (type, context_die)
 
       type_die = new_die (TREE_CODE (type) == RECORD_TYPE
                          ? DW_TAG_structure_type : DW_TAG_union_type,
-                         scope_die);
+                         scope_die, type);
       equate_type_number_to_die (type, type_die);
       if (old_die)
        add_AT_die_ref (type_die, DW_AT_specification, old_die);
@@ -10533,7 +11580,7 @@ gen_struct_or_union_type_die (type, context_die)
   if (complete)
     {
       /* Prevent infinite recursion in cases where the type of some member of
-         this type is expressed in terms of this type itself.  */
+        this type is expressed in terms of this type itself.  */
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
       if (TYPE_STUB_DECL (type) != NULL_TREE)
@@ -10563,8 +11610,9 @@ gen_struct_or_union_type_die (type, context_die)
       add_AT_flag (type_die, DW_AT_declaration, 1);
 
       /* We don't need to do this for function-local types.  */
-      if (! decl_function_context (TYPE_STUB_DECL (type)))
-       add_incomplete_type (type);
+      if (TYPE_STUB_DECL (type)
+         && ! decl_function_context (TYPE_STUB_DECL (type)))
+       VARRAY_PUSH_TREE (incomplete_types, type);
     }
 }
 
@@ -10577,7 +11625,8 @@ gen_subroutine_type_die (type, context_die)
 {
   tree return_type = TREE_TYPE (type);
   dw_die_ref subr_die
-    = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
+    = new_die (DW_TAG_subroutine_type,
+              scope_die_for (type, context_die), type);
 
   equate_type_number_to_die (type, subr_die);
   add_prototyped_attribute (subr_die, type);
@@ -10597,15 +11646,16 @@ gen_typedef_die (decl, context_die)
 
   if (TREE_ASM_WRITTEN (decl))
     return;
-  TREE_ASM_WRITTEN (decl) = 1;
 
-  type_die = new_die (DW_TAG_typedef, context_die);
+  TREE_ASM_WRITTEN (decl) = 1;
+  type_die = new_die (DW_TAG_typedef, context_die, decl);
   origin = decl_ultimate_origin (decl);
   if (origin != NULL)
     add_abstract_origin_attribute (type_die, origin);
   else
     {
       tree type;
+
       add_name_and_src_coords_attributes (type_die, decl);
       if (DECL_ORIGINAL_TYPE (decl))
        {
@@ -10618,6 +11668,7 @@ gen_typedef_die (decl, context_die)
        }
       else
        type = TREE_TYPE (decl);
+
       add_type_attribute (type_die, type, TREE_READONLY (decl),
                          TREE_THIS_VOLATILE (decl), context_die);
     }
@@ -10638,22 +11689,32 @@ gen_type_die (type, context_die)
   if (type == NULL_TREE || type == error_mark_node)
     return;
 
-  /* We are going to output a DIE to represent the unqualified version of
-     this type (i.e. without any const or volatile qualifiers) so get the
-     main variant (i.e. the unqualified version) of this type now.  */
-  type = type_main_variant (type);
-
-  if (TREE_ASM_WRITTEN (type))
-    return;
-
   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
     {
+      if (TREE_ASM_WRITTEN (type))
+       return;
+
+      /* Prevent broken recursion; we can't hand off to the same type.  */
+      if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
+       abort ();
+
       TREE_ASM_WRITTEN (type) = 1;
       gen_decl_die (TYPE_NAME (type), context_die);
       return;
     }
 
+  /* We are going to output a DIE to represent the unqualified version
+     of this type (i.e. without any const or volatile qualifiers) so
+     get the main variant (i.e. the unqualified version) of this type
+     now.  (Vectors are special because the debugging info is in the
+     cloned type itself).  */
+  if (TREE_CODE (type) != VECTOR_TYPE)
+    type = type_main_variant (type);
+
+  if (TREE_ASM_WRITTEN (type))
+    return;
+
   switch (TREE_CODE (type))
     {
     case ERROR_MARK:
@@ -10669,7 +11730,7 @@ gen_type_die (type, context_die)
       TREE_ASM_WRITTEN (type) = 1;
 
       /* For these types, all that is required is that we output a DIE (or a
-         set of DIEs) to represent the "basis" type.  */
+        set of DIEs) to represent the "basis" type.  */
       gen_type_die (TREE_TYPE (type), context_die);
       break;
 
@@ -10682,7 +11743,7 @@ gen_type_die (type, context_die)
       gen_type_die (TREE_TYPE (type), context_die);
 
       /* Now output a DIE to represent this pointer-to-data-member type
-         itself.  */
+        itself.  */
       gen_ptr_to_mbr_type_die (type, context_die);
       break;
 
@@ -10719,20 +11780,19 @@ gen_type_die (type, context_die)
       break;
 
     case VECTOR_TYPE:
-      gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
+      gen_array_type_die (type, context_die);
       break;
 
     case ENUMERAL_TYPE:
     case RECORD_TYPE:
     case UNION_TYPE:
     case QUAL_UNION_TYPE:
-      /* If this is a nested type whose containing class hasn't been
-        written out yet, writing it out will cover this one, too.
-         This does not apply to instantiations of member class templates;
-        they need to be added to the containing class as they are
-        generated.  FIXME: This hurts the idea of combining type decls
-         from multiple TUs, since we can't predict what set of template
-         instantiations we'll get.  */
+      /* If this is a nested type whose containing class hasn't been written
+        out yet, writing it out will cover this one, too.  This does not apply
+        to instantiations of member class templates; they need to be added to
+        the containing class as they are generated.  FIXME: This hurts the
+        idea of combining type decls from multiple TUs, since we can't predict
+        what set of template instantiations we'll get.  */
       if (TYPE_CONTEXT (type)
          && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
          && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
@@ -10852,8 +11912,9 @@ gen_block_die (stmt, context_die, depth)
     {
       tree sub;
 
-      for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
+      for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
        gen_block_die (sub, context_die, depth + 1);
+
       return;
     }
 
@@ -10874,13 +11935,12 @@ gen_block_die (stmt, context_die, depth)
   else
     {
       /* In the case where the current block represents an inlining of the
-         "body block" of an inline function, we must *NOT* output any DIE for
-         this block because we have already output a DIE to represent the
-         whole inlined function scope and the "body block" of any function
-         doesn't really represent a different scope according to ANSI C
-         rules.  So we check here to make sure that this block does not
-         represent a "body block inlining" before trying to set the
-         `must_output_die' flag.  */
+        "body block" of an inline function, we must *NOT* output any DIE for
+        this block because we have already output a DIE to represent the whole
+        inlined function scope and the "body block" of any function doesn't
+        really represent a different scope according to ANSI C rules.  So we
+        check here to make sure that this block does not represent a "body
+        block inlining" before trying to set the MUST_OUTPUT_DIE flag.  */
       if (! is_body_block (origin ? origin : stmt))
        {
          /* Determine if this block directly contains any "significant"
@@ -10941,8 +12001,7 @@ decls_for_scope (stmt, context_die, depth)
      declared directly within this block but not within any nested
      sub-blocks.  Also, nested function and tag DIEs have been
      generated with a parent of NULL; fix that up now.  */
-  for (decl = BLOCK_VARS (stmt);
-       decl != NULL; decl = TREE_CHAIN (decl))
+  for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
     {
       dw_die_ref die;
 
@@ -10996,18 +12055,17 @@ gen_decl_die (decl, context_die)
 {
   tree origin;
 
-  if (TREE_CODE (decl) == ERROR_MARK)
-    return;
-
-  /* If this ..._DECL node is marked to be ignored, then ignore it.  */
-  if (DECL_IGNORED_P (decl))
+  if (DECL_P (decl) && DECL_IGNORED_P (decl))
     return;
 
   switch (TREE_CODE (decl))
     {
+    case ERROR_MARK:
+      break;
+
     case CONST_DECL:
       /* The individual enumerators of an enum type get output when we output
-         the Dwarf representation of the relevant enum type itself.  */
+        the Dwarf representation of the relevant enum type itself.  */
       break;
 
     case FUNCTION_DECL:
@@ -11020,6 +12078,7 @@ gen_decl_die (decl, context_die)
       /* If we're emitting a clone, emit info for the abstract instance.  */
       if (DECL_ORIGIN (decl) != decl)
        dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
+
       /* If we're emitting an out-of-line copy of an inline function,
         emit info for the abstract instance and set up to refer to it.  */
       else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
@@ -11032,6 +12091,7 @@ gen_decl_die (decl, context_die)
          dwarf2out_abstract_function (decl);
          set_decl_origin_self (decl);
        }
+
       /* Otherwise we're emitting the primary DIE for this decl.  */
       else if (debug_info_level > DINFO_LEVEL_TERSE)
        {
@@ -11055,17 +12115,16 @@ gen_decl_die (decl, context_die)
 
     case TYPE_DECL:
       /* If we are in terse mode, don't generate any DIEs to represent any
-         actual typedefs.  */
+        actual typedefs.  */
       if (debug_info_level <= DINFO_LEVEL_TERSE)
        break;
 
-      /* In the special case of a TYPE_DECL node representing the
-         declaration of some type tag, if the given TYPE_DECL is marked as
-         having been instantiated from some other (original) TYPE_DECL node
-         (e.g. one which was generated within the original definition of an
-         inline function) we have to generate a special (abbreviated)
-         DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
-         DIE here.  */
+      /* In the special case of a TYPE_DECL node representing the declaration
+        of some type tag, if the given TYPE_DECL is marked as having been
+        instantiated from some other (original) TYPE_DECL node (e.g. one which
+        was generated within the original definition of an inline function) we
+        have to generate a special (abbreviated) DW_TAG_structure_type,
+        DW_TAG_union_type, or DW_TAG_enumeration_type DIE here.  */
       if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
        {
          gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
@@ -11086,12 +12145,12 @@ gen_decl_die (decl, context_die)
 
     case VAR_DECL:
       /* If we are in terse mode, don't generate any DIEs to represent any
-         variable declarations or definitions.  */
+        variable declarations or definitions.  */
       if (debug_info_level <= DINFO_LEVEL_TERSE)
        break;
 
       /* Output any DIEs that are needed to specify the type of this data
-         object.  */
+        object.  */
       gen_type_die (TREE_TYPE (decl), context_die);
 
       /* And its containing type.  */
@@ -11100,9 +12159,9 @@ gen_decl_die (decl, context_die)
        gen_type_die_for_member (origin, decl, context_die);
 
       /* Now output the DIE to represent the data object itself.  This gets
-         complicated because of the possibility that the VAR_DECL really
-         represents an inlined instance of a formal parameter for an inline
-         function.  */
+        complicated because of the possibility that the VAR_DECL really
+        represents an inlined instance of a formal parameter for an inline
+        function.  */
       origin = decl_ultimate_origin (decl);
       if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
        gen_formal_parameter_die (decl, context_die);
@@ -11111,8 +12170,8 @@ gen_decl_die (decl, context_die)
       break;
 
     case FIELD_DECL:
-      /* Ignore the nameless fields that are used to skip bits, but
-        handle C++ anonymous unions.  */
+      /* Ignore the nameless fields that are used to skip bits but handle C++
+        anonymous unions.  */
       if (DECL_NAME (decl) != NULL_TREE
          || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
        {
@@ -11146,7 +12205,7 @@ dwarf2out_add_library_unit_info (filename, context_list)
 
   if (filename != NULL)
     {
-      dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
+      dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
       tree context_list_decl
        = build_decl (LABEL_DECL, get_identifier (context_list),
                      void_type_node);
@@ -11159,17 +12218,17 @@ dwarf2out_add_library_unit_info (filename, context_list)
     }
 }
 
-/* Debug information for a global DECL.  Called from toplev.c after
+/* Output debug information for global decl DECL.  Called from toplev.c after
    compilation proper has finished.  */
+
 static void
 dwarf2out_global_decl (decl)
      tree decl;
 {
   /* Output DWARF2 information for file-scope tentative data object
-     declarations, file-scope (extern) function declarations (which
-     had no corresponding body) and file-scope tagged type
-     declarations and definitions which have not yet been forced out.  */
-
+     declarations, file-scope (extern) function declarations (which had no
+     corresponding body) and file-scope tagged type declarations and
+     definitions which have not yet been forced out.  */
   if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
     dwarf2out_decl (decl);
 }
@@ -11182,47 +12241,45 @@ dwarf2out_decl (decl)
 {
   dw_die_ref context_die = comp_unit_die;
 
-  if (TREE_CODE (decl) == ERROR_MARK)
-    return;
-
-  /* If this ..._DECL node is marked to be ignored, then ignore it.  */
-  if (DECL_IGNORED_P (decl))
-    return;
-
   switch (TREE_CODE (decl))
     {
+    case ERROR_MARK:
+      return;
+
     case FUNCTION_DECL:
       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
-         builtin function.  Explicit programmer-supplied declarations of
-         these same functions should NOT be ignored however.  */
+        builtin function.  Explicit programmer-supplied declarations of
+        these same functions should NOT be ignored however.  */
       if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
        return;
 
       /* What we would really like to do here is to filter out all mere
-         file-scope declarations of file-scope functions which are never
-         referenced later within this translation unit (and keep all of ones
-         that *are* referenced later on) but we aren't clairvoyant, so we have
-         no idea which functions will be referenced in the future (i.e. later
-         on within the current translation unit). So here we just ignore all
-         file-scope function declarations which are not also definitions.  If
-         and when the debugger needs to know something about these functions,
-         it will have to hunt around and find the DWARF information associated
-         with the definition of the function.  Note that we can't just check
-         `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
-         definitions and which ones represent mere declarations.  We have to
-         check `DECL_INITIAL' instead. That's because the C front-end
-         supports some weird semantics for "extern inline" function
-         definitions.  These can get inlined within the current translation
-         unit (an thus, we need to generate DWARF info for their abstract
-         instances so that the DWARF info for the concrete inlined instances
-         can have something to refer to) but the compiler never generates any
-         out-of-lines instances of such things (despite the fact that they
-         *are* definitions).  The important point is that the C front-end
-         marks these "extern inline" functions as DECL_EXTERNAL, but we need
-         to generate DWARF for them anyway. Note that the C++ front-end also
-         plays some similar games for inline function definitions appearing
-         within include files which also contain
-        `#pragma interface' pragmas.  */
+        file-scope declarations of file-scope functions which are never
+        referenced later within this translation unit (and keep all of ones
+        that *are* referenced later on) but we aren't clairvoyant, so we have
+        no idea which functions will be referenced in the future (i.e. later
+        on within the current translation unit). So here we just ignore all
+        file-scope function declarations which are not also definitions.  If
+        and when the debugger needs to know something about these functions,
+        it will have to hunt around and find the DWARF information associated
+        with the definition of the function.
+
+        We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
+        nodes represent definitions and which ones represent mere
+        declarations.  We have to check DECL_INITIAL instead. That's because
+        the C front-end supports some weird semantics for "extern inline"
+        function definitions.  These can get inlined within the current
+        translation unit (an thus, we need to generate Dwarf info for their
+        abstract instances so that the Dwarf info for the concrete inlined
+        instances can have something to refer to) but the compiler never
+        generates any out-of-lines instances of such things (despite the fact
+        that they *are* definitions).
+
+        The important point is that the C front-end marks these "extern
+        inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
+        them anyway. Note that the C++ front-end also plays some similar games
+        for inline function definitions appearing within include files which
+        also contain `#pragma interface' pragmas.  */
       if (DECL_INITIAL (decl) == NULL_TREE)
        return;
 
@@ -11231,23 +12288,22 @@ dwarf2out_decl (decl)
         we're a method, it will be ignored, since we already have a DIE.  */
       if (decl_function_context (decl))
        context_die = NULL;
-
       break;
 
     case VAR_DECL:
       /* Ignore this VAR_DECL if it refers to a file-scope extern data object
-         declaration and if the declaration was never even referenced from
-         within this entire compilation unit.  We suppress these DIEs in
-         order to save space in the .debug section (by eliminating entries
-         which are probably useless).  Note that we must not suppress
-         block-local extern declarations (whether used or not) because that
-         would screw-up the debugger's name lookup mechanism and cause it to
-         miss things which really ought to be in scope at a given point.  */
+        declaration and if the declaration was never even referenced from
+        within this entire compilation unit.  We suppress these DIEs in
+        order to save space in the .debug section (by eliminating entries
+        which are probably useless).  Note that we must not suppress
+        block-local extern declarations (whether used or not) because that
+        would screw-up the debugger's name lookup mechanism and cause it to
+        miss things which really ought to be in scope at a given point.  */
       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
        return;
 
       /* If we are in terse mode, don't generate any DIEs to represent any
-         variable declarations or definitions.  */
+        variable declarations or definitions.  */
       if (debug_info_level <= DINFO_LEVEL_TERSE)
        return;
       break;
@@ -11258,14 +12314,15 @@ dwarf2out_decl (decl)
        return;
 
       /* Don't bother trying to generate any DIEs to represent any of the
-         normal built-in types for the language we are compiling.  */
+        normal built-in types for the language we are compiling.  */
       if (DECL_SOURCE_LINE (decl) == 0)
        {
          /* OK, we need to generate one for `bool' so GDB knows what type
-             comparisons have.  */
+            comparisons have.  */
          if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
               == DW_LANG_C_plus_plus)
-             && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
+             && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
+             && ! DECL_IGNORED_P (decl))
            modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
 
          return;
@@ -11325,29 +12382,32 @@ dwarf2out_ignore_block (block)
      tree block;
 {
   tree decl;
+
   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
     if (TREE_CODE (decl) == FUNCTION_DECL
        || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
       return 0;
+
   return 1;
 }
 
-/* Lookup a filename (in the list of filenames that we know about here in
+/* Lookup FILE_NAME (in the list of filenames that we know about here in
    dwarf2out.c) and return its "index".  The index of each (known) filename is
-   just a unique number which is associated with only that one filename.
-   We need such numbers for the sake of generating labels
-   (in the .debug_sfnames section) and references to those
-   files  numbers (in the .debug_srcinfo and.debug_macinfo sections).
-   If the filename given as an argument is not found in our current list,
-   add it to the list and assign it the next available unique index number.
-   In order to speed up searches, we remember the index of the filename
-   was looked up last.  This handles the majority of all searches.  */
+   just a unique number which is associated with only that one filename.  We
+   need such numbers for the sake of generating labels (in the .debug_sfnames
+   section) and references to those files numbers (in the .debug_srcinfo
+   and.debug_macinfo sections).  If the filename given as an argument is not
+   found in our current list, add it to the list and assign it the next
+   available unique index number.  In order to speed up searches, we remember
+   the index of the filename was looked up last.  This handles the majority of
+   all searches.  */
 
 static unsigned
 lookup_filename (file_name)
      const char *file_name;
 {
-  unsigned i;
+  size_t i, n;
+  char *save_file_name;
 
   /* ??? Why isn't DECL_SOURCE_FILE left null instead.  */
   if (strcmp (file_name, "<internal>") == 0
@@ -11356,48 +12416,65 @@ lookup_filename (file_name)
 
   /* Check to see if the file name that was searched on the previous
      call matches this file name.  If so, return the index.  */
-  if (file_table.last_lookup_index != 0)
-    if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
-      return file_table.last_lookup_index;
+  if (file_table_last_lookup_index != 0)
+    {
+      const char *last
+       = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
+      if (strcmp (file_name, last) == 0)
+       return file_table_last_lookup_index;
+    }
 
   /* Didn't match the previous lookup, search the table */
-  for (i = 1; i < file_table.in_use; ++i)
-    if (strcmp (file_name, file_table.table[i]) == 0)
+  n = VARRAY_ACTIVE_SIZE (file_table);
+  for (i = 1; i < n; i++)
+    if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
       {
-       file_table.last_lookup_index = i;
+       file_table_last_lookup_index = i;
        return i;
       }
 
-  /* Prepare to add a new table entry by making sure there is enough space in
-     the table to do so.  If not, expand the current table.  */
-  if (i == file_table.allocated)
-    {
-      file_table.allocated = i + FILE_TABLE_INCREMENT;
-      file_table.table = (char **)
-       xrealloc (file_table.table, file_table.allocated * sizeof (char *));
-    }
-
   /* Add the new entry to the end of the filename table.  */
-  file_table.table[i] = xstrdup (file_name);
-  file_table.in_use = i + 1;
-  file_table.last_lookup_index = i;
-
-  if (DWARF2_ASM_LINE_DEBUG_INFO)
-    fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
+  file_table_last_lookup_index = n;
+  save_file_name = (char *) ggc_strdup (file_name);
+  VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
+  VARRAY_PUSH_UINT (file_table_emitted, 0);
 
   return i;
 }
 
+static int
+maybe_emit_file (fileno)
+     int fileno;
+{
+  static int emitcount = 0;  
+  if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
+    {
+      if (!VARRAY_UINT (file_table_emitted, fileno))
+       {
+         VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
+         fprintf (asm_out_file, "\t.file %u ",
+                  VARRAY_UINT (file_table_emitted, fileno));
+         output_quoted_string (asm_out_file,
+                               VARRAY_CHAR_PTR (file_table, fileno));
+         fputc ('\n', asm_out_file);
+       }
+      return VARRAY_UINT (file_table_emitted, fileno);
+    }
+  else
+    return fileno;
+}
+
 static void
 init_file_table ()
 {
   /* Allocate the initial hunk of the file_table.  */
-  file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
-  file_table.allocated = FILE_TABLE_INCREMENT;
+  VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
+  VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
 
   /* Skip the first entry - file numbers begin at 1.  */
-  file_table.in_use = 1;
-  file_table.last_lookup_index = 0;
+  VARRAY_PUSH_CHAR_PTR (file_table, NULL);
+  VARRAY_PUSH_UINT (file_table_emitted, 0);
+  file_table_last_lookup_index = 0;
 }
 
 /* Output a label to mark the beginning of a source code line entry
@@ -11422,20 +12499,22 @@ dwarf2out_source_line (line, filename)
        {
          unsigned file_num = lookup_filename (filename);
 
+         file_num = maybe_emit_file (file_num);
+
          /* Emit the .loc directive understood by GNU as.  */
          fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
 
          /* Indicate that line number info exists.  */
-         ++line_info_table_in_use;
+         line_info_table_in_use++;
 
          /* Indicate that multiple line number tables exist.  */
          if (DECL_SECTION_NAME (current_function_decl))
-           ++separate_line_info_table_in_use;
+           separate_line_info_table_in_use++;
        }
       else if (DECL_SECTION_NAME (current_function_decl))
        {
          dw_separate_line_info_ref line_info;
-         ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
+         (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL,
                                     separate_line_info_table_in_use);
 
          /* expand the line info table if necessary */
@@ -11445,9 +12524,14 @@ dwarf2out_source_line (line, filename)
              separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
              separate_line_info_table
                = (dw_separate_line_info_ref)
-                 xrealloc (separate_line_info_table,
-                           separate_line_info_table_allocated
-                           * sizeof (dw_separate_line_info_entry));
+                 ggc_realloc (separate_line_info_table,
+                              separate_line_info_table_allocated
+                              * sizeof (dw_separate_line_info_entry));
+             memset ((separate_line_info_table 
+                      + separate_line_info_table_in_use), 
+                     0,
+                     (LINE_INFO_TABLE_INCREMENT 
+                      * sizeof (dw_separate_line_info_entry)));
            }
 
          /* Add the new entry at the end of the line_info_table.  */
@@ -11455,13 +12539,13 @@ dwarf2out_source_line (line, filename)
            = &separate_line_info_table[separate_line_info_table_in_use++];
          line_info->dw_file_num = lookup_filename (filename);
          line_info->dw_line_num = line;
-         line_info->function = current_funcdef_number;
+         line_info->function = current_function_funcdef_no;
        }
       else
        {
          dw_line_info_ref line_info;
 
-         ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
+         (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
                                     line_info_table_in_use);
 
          /* Expand the line info table if necessary.  */
@@ -11469,10 +12553,11 @@ dwarf2out_source_line (line, filename)
            {
              line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
              line_info_table
-               = (dw_line_info_ref)
-                 xrealloc (line_info_table,
-                           (line_info_table_allocated
-                            * sizeof (dw_line_info_entry)));
+               = ggc_realloc (line_info_table,
+                              (line_info_table_allocated
+                               * sizeof (dw_line_info_entry)));
+             memset (line_info_table + line_info_table_in_use, 0,
+                     LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
            }
 
          /* Add the new entry at the end of the line_info_table.  */
@@ -11490,18 +12575,24 @@ dwarf2out_start_source_file (lineno, filename)
      unsigned int lineno;
      const char *filename;
 {
-  if (flag_eliminate_dwarf2_dups)
+  if (flag_eliminate_dwarf2_dups && !is_main_source)
     {
       /* Record the beginning of the file for break_out_includes.  */
-      dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
+      dw_die_ref bincl_die;
+
+      bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
       add_AT_string (bincl_die, DW_AT_name, filename);
     }
+
+  is_main_source = 0;
+
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
       named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
       dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
                                   lineno);
+      maybe_emit_file (lookup_filename (filename));
       dw2_asm_output_data_uleb128 (lookup_filename (filename),
                                   "Filename we just started");
     }
@@ -11514,10 +12605,9 @@ dwarf2out_end_source_file (lineno)
      unsigned int lineno ATTRIBUTE_UNUSED;
 {
   if (flag_eliminate_dwarf2_dups)
-    {
-      /* Record the end of the file for break_out_includes.  */
-      new_die (DW_TAG_GNU_EINCL, comp_unit_die);
-    }
+    /* Record the end of the file for break_out_includes.  */
+    new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
+
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
       named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
@@ -11534,12 +12624,6 @@ dwarf2out_define (lineno, buffer)
      unsigned lineno ATTRIBUTE_UNUSED;
      const char *buffer ATTRIBUTE_UNUSED;
 {
-  static int initialized = 0;
-  if (!initialized)
-    {
-      dwarf2out_start_source_file (0, primary_filename);
-      initialized = 1;
-    }
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
       named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
@@ -11570,42 +12654,32 @@ dwarf2out_undef (lineno, buffer)
 /* Set up for Dwarf output at the start of compilation.  */
 
 static void
-dwarf2out_init (main_input_filename)
-     const char *main_input_filename;
+dwarf2out_init (input_filename)
+     const char *input_filename ATTRIBUTE_UNUSED;
 {
   init_file_table ();
 
-  /* Remember the name of the primary input file.  */
-  primary_filename = main_input_filename;
-
-  /* Add it to the file table first, under the assumption that we'll
-     be emitting line number data for it first, which avoids having
-     to add an initial DW_LNS_set_file.  */
-  lookup_filename (main_input_filename);
-
   /* Allocate the initial hunk of the decl_die_table.  */
-  decl_die_table
-    = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
+  decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT 
+                                     * sizeof (dw_die_ref));
   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
   decl_die_table_in_use = 0;
 
   /* Allocate the initial hunk of the decl_scope_table.  */
   VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
-  ggc_add_tree_varray_root (&decl_scope_table, 1);
 
   /* Allocate the initial hunk of the abbrev_die_table.  */
-  abbrev_die_table
-    = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
-                             sizeof (dw_die_ref));
+  abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
+                                       * sizeof (dw_die_ref));
   abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
   /* Zero-th entry is allocated, but unused */
   abbrev_die_table_in_use = 1;
 
   /* Allocate the initial hunk of the line_info_table.  */
-  line_info_table
-    = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
-                                 sizeof (dw_line_info_entry));
+  line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
+                                      * sizeof (dw_line_info_entry));
   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
+
   /* Zero-th entry is allocated, but unused */
   line_info_table_in_use = 1;
 
@@ -11613,14 +12687,14 @@ dwarf2out_init (main_input_filename)
      value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
      will (typically) be a relative pathname and that this pathname should be
      taken as being relative to the directory from which the compiler was
-     invoked when the given (base) source file was compiled.  */
-  comp_unit_die = gen_compile_unit_die (main_input_filename);
+     invoked when the given (base) source file was compiled.  We will fill
+     in this value in dwarf2out_finish.  */
+  comp_unit_die = gen_compile_unit_die (NULL);
+  is_main_source = 1;
 
   VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
-  ggc_add_tree_varray_root (&incomplete_types, 1);
 
   VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
-  ggc_add_rtx_varray_root (&used_rtx_varray, 1);
 
   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
@@ -11629,16 +12703,20 @@ dwarf2out_init (main_input_filename)
     ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
   else
     strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
+
   ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
                               DEBUG_INFO_SECTION_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
                               DEBUG_LINE_SECTION_LABEL, 0);
+  ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
+                              DEBUG_RANGES_SECTION_LABEL, 0);
   named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
   named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
   named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
+
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
     {
       named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
@@ -11654,16 +12732,261 @@ dwarf2out_init (main_input_filename)
     }
 }
 
+/* A helper function for dwarf2out_finish called through
+   ht_forall.  Emit one queued .debug_str string.  */
+
+static int
+output_indirect_string (h, v)
+     void **h;
+     void *v ATTRIBUTE_UNUSED;
+{
+  struct indirect_string_node *node = (struct indirect_string_node *) *h;
+
+  if (node->form == DW_FORM_strp)
+    {
+      named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
+      ASM_OUTPUT_LABEL (asm_out_file, node->label);
+      assemble_string (node->str, strlen (node->str) + 1);
+    }
+
+  return 1;
+}
+
+
+
+/* Clear the marks for a die and its children.
+   Be cool if the mark isn't set.  */
+
+static void
+prune_unmark_dies (die)
+     dw_die_ref die;
+{
+  dw_die_ref c;
+  die->die_mark = 0;
+  for (c = die->die_child; c; c = c->die_sib)
+    prune_unmark_dies (c);
+}
+
+
+/* Given DIE that we're marking as used, find any other dies
+   it references as attributes and mark them as used.  */
+
+static void
+prune_unused_types_walk_attribs (die)
+     dw_die_ref die;
+{
+  dw_attr_ref a;
+
+  for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
+    {
+      if (a->dw_attr_val.val_class == dw_val_class_die_ref)
+       {
+         /* A reference to another DIE.
+            Make sure that it will get emitted.  */
+         prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
+       }
+      else if (a->dw_attr == DW_AT_decl_file)
+       {
+         /* A reference to a file.  Make sure the file name is emitted.  */
+         a->dw_attr_val.v.val_unsigned =
+           maybe_emit_file (a->dw_attr_val.v.val_unsigned);
+       }
+    }
+}
+
+
+/* Mark DIE as being used.  If DOKIDS is true, then walk down
+   to DIE's children.  */
+
+static void
+prune_unused_types_mark (die, dokids)
+     dw_die_ref die;
+     int dokids;
+{
+  dw_die_ref c;
+
+  if (die->die_mark == 0)
+    {
+      /* We haven't done this node yet.  Mark it as used.  */
+      die->die_mark = 1;
+
+      /* We also have to mark its parents as used.
+        (But we don't want to mark our parents' kids due to this.)  */
+      if (die->die_parent)
+       prune_unused_types_mark (die->die_parent, 0);
+
+      /* Mark any referenced nodes.  */
+      prune_unused_types_walk_attribs (die);
+    }
+
+  if (dokids && die->die_mark != 2)
+    {
+      /* We need to walk the children, but haven't done so yet.
+        Remember that we've walked the kids.  */
+      die->die_mark = 2;
+
+      /* Walk them.  */
+      for (c = die->die_child; c; c = c->die_sib)
+       {
+         /* If this is an array type, we need to make sure our
+            kids get marked, even if they're types.  */
+         if (die->die_tag == DW_TAG_array_type)
+           prune_unused_types_mark (c, 1);
+         else
+           prune_unused_types_walk (c);
+       }
+    }
+}
+
+
+/* Walk the tree DIE and mark types that we actually use.  */
+
+static void
+prune_unused_types_walk (die)
+     dw_die_ref die;
+{
+  dw_die_ref c;
+
+  /* Don't do anything if this node is already marked.  */
+  if (die->die_mark)
+    return;
+
+  switch (die->die_tag) {
+  case DW_TAG_const_type:
+  case DW_TAG_packed_type:
+  case DW_TAG_pointer_type:
+  case DW_TAG_reference_type:
+  case DW_TAG_volatile_type:
+  case DW_TAG_typedef:
+  case DW_TAG_array_type:
+  case DW_TAG_structure_type:
+  case DW_TAG_union_type:
+  case DW_TAG_class_type:
+  case DW_TAG_friend:
+  case DW_TAG_variant_part:
+  case DW_TAG_enumeration_type:
+  case DW_TAG_subroutine_type:
+  case DW_TAG_string_type:
+  case DW_TAG_set_type:
+  case DW_TAG_subrange_type:
+  case DW_TAG_ptr_to_member_type:
+  case DW_TAG_file_type:
+    /* It's a type node --- don't mark it.  */
+    return;
+
+  default:
+    /* Mark everything else.  */
+    break;
+  }
+
+  die->die_mark = 1;
+
+  /* Now, mark any dies referenced from here.  */
+  prune_unused_types_walk_attribs (die);
+
+  /* Mark children.  */
+  for (c = die->die_child; c; c = c->die_sib)
+    prune_unused_types_walk (c);
+}
+
+
+/* Remove from the tree DIE any dies that aren't marked.  */
+
+static void
+prune_unused_types_prune (die)
+     dw_die_ref die;
+{
+  dw_die_ref c, p, n;
+  if (!die->die_mark)
+    abort();
+
+  p = NULL;
+  for (c = die->die_child; c; c = n)
+    {
+      n = c->die_sib;
+      if (c->die_mark)
+       {
+         prune_unused_types_prune (c);
+         p = c;
+       }
+      else
+       {
+         if (p)
+           p->die_sib = n;
+         else
+           die->die_child = n;
+         free_die (c);
+       }
+    }
+}
+
+
+/* Remove dies representing declarations that we never use.  */
+
+static void
+prune_unused_types ()
+{
+  unsigned int i;
+  limbo_die_node *node;
+
+  /* Clear all the marks.  */
+  prune_unmark_dies (comp_unit_die);
+  for (node = limbo_die_list; node; node = node->next)
+    prune_unmark_dies (node->die);
+
+  /* Set the mark on nodes that are actually used.  */
+  prune_unused_types_walk (comp_unit_die);
+  for (node = limbo_die_list; node; node = node->next)
+    prune_unused_types_walk (node->die);
+
+  /* Also set the mark on nodes referenced from the
+     pubname_table or arange_table.  */
+  for (i=0; i < pubname_table_in_use; i++)
+    {
+      prune_unused_types_mark (pubname_table[i].die, 1);
+    }
+  for (i=0; i < arange_table_in_use; i++)
+    {
+      prune_unused_types_mark (arange_table[i], 1);
+    }
+
+  /* Get rid of nodes that aren't marked.  */
+  prune_unused_types_prune (comp_unit_die);
+  for (node = limbo_die_list; node; node = node->next)
+    prune_unused_types_prune (node->die);
+
+  /* Leave the marks clear.  */
+  prune_unmark_dies (comp_unit_die);
+  for (node = limbo_die_list; node; node = node->next)
+    prune_unmark_dies (node->die);
+}
+
 /* Output stuff that dwarf requires at the end of every file,
    and generate the DWARF-2 debugging info.  */
 
 static void
 dwarf2out_finish (input_filename)
-     const char *input_filename ATTRIBUTE_UNUSED;
+     const char *input_filename;
 {
   limbo_die_node *node, *next_node;
   dw_die_ref die = 0;
 
+  /* Add the name for the main input file now.  We delayed this from
+     dwarf2out_init to avoid complications with PCH.  */
+  add_name_attribute (comp_unit_die, input_filename);
+  if (input_filename[0] != DIR_SEPARATOR)
+    add_comp_dir_attribute (comp_unit_die);
+  else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
+    {
+      size_t i;
+      for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
+       if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR)
+         {
+           add_comp_dir_attribute (comp_unit_die);
+           break;
+         }
+    }
+
   /* Traverse the limbo die list, and add parent/child links.  The only
      dies without parents that should be here are concrete instances of
      inline functions, and the comp_unit_die.  We can ignore the comp_unit_die.
@@ -11677,15 +13000,46 @@ dwarf2out_finish (input_filename)
       if (die->die_parent == NULL)
        {
          dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
+         tree context;
+
          if (origin)
            add_child_die (origin->die_parent, die);
          else if (die == comp_unit_die)
            ;
+         /* If this was an expression for a bound involved in a function
+            return type, it may be a SAVE_EXPR for which we weren't able
+            to find a DIE previously.  So try now.  */
+         else if (node->created_for
+                  && TREE_CODE (node->created_for) == SAVE_EXPR
+                  && 0 != (origin = (lookup_decl_die
+                                     (SAVE_EXPR_CONTEXT
+                                      (node->created_for)))))
+           add_child_die (origin, die);
+         else if (errorcount > 0 || sorrycount > 0)
+           /* It's OK to be confused by errors in the input.  */
+           add_child_die (comp_unit_die, die);
+         else if (node->created_for
+                  && ((DECL_P (node->created_for)
+                       && (context = DECL_CONTEXT (node->created_for)))
+                      || (TYPE_P (node->created_for)
+                          && (context = TYPE_CONTEXT (node->created_for))))
+                  && TREE_CODE (context) == FUNCTION_DECL)
+           {
+             /* In certain situations, the lexical block containing a
+                nested function can be optimized away, which results
+                in the nested function die being orphaned.  Likewise
+                with the return type of that nested function.  Force
+                this to be a child of the containing function.  */
+             origin = lookup_decl_die (context);
+             if (! origin)
+               abort ();
+             add_child_die (origin, die);
+           }
          else
            abort ();
        }
-      free (node);
     }
+
   limbo_die_list = NULL;
 
   /* Walk through the list of incomplete types again, trying once more to
@@ -11696,6 +13050,9 @@ dwarf2out_finish (input_filename)
      we'll see the end of an include file before the beginning.  */
   reverse_all_dies (comp_unit_die);
 
+  if (flag_eliminate_unused_debug_types)
+    prune_unused_types ();
+
   /* Generate separate CUs for each of the include files we've seen.
      They will go into limbo_die_list.  */
   if (flag_eliminate_dwarf2_dups)
@@ -11709,7 +13066,7 @@ dwarf2out_finish (input_filename)
 
   /* Output a terminator label for the .text section.  */
   text_section ();
-  ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
+  (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
 
   /* Output the source line correspondence table.  We must do this
      even if there is no line information.  Otherwise, on an empty
@@ -11741,9 +13098,9 @@ dwarf2out_finish (input_filename)
       add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
       add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
     }
-  /* And if it wasn't, we need to give .debug_loc and .debug_ranges
-     an appropriate "base address".  Use zero so that these addresses
-     become absolute.  */
+
+  /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
+     "base address".  Use zero so that these addresses become absolute.  */
   else if (have_location_lists || ranges_table_in_use)
     add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
 
@@ -11757,25 +13114,25 @@ dwarf2out_finish (input_filename)
   /* Output all of the compilation units.  We put the main one last so that
      the offsets are available to output_pubnames.  */
   for (node = limbo_die_list; node; node = node->next)
-    output_comp_unit (node->die);
-  output_comp_unit (comp_unit_die);
+    output_comp_unit (node->die, 0);
+
+  output_comp_unit (comp_unit_die, 0);
 
   /* Output the abbreviation table.  */
   named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
   output_abbrev_section ();
 
+  /* Output public names table if necessary.  */
   if (pubname_table_in_use)
     {
-      /* Output public names table.  */
       named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
       output_pubnames ();
     }
 
-  /* We only put functions in the arange table, so don't write it out if
-     we don't have any.  */
+  /* Output the address range information.  We only put functions in the arange
+     table, so don't write it out if we don't have any.  */
   if (fde_table_in_use)
     {
-      /* Output the address range information.  */
       named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
       output_aranges ();
     }
@@ -11784,14 +13141,28 @@ dwarf2out_finish (input_filename)
   if (ranges_table_in_use)
     {
       named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
+      ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
       output_ranges ();
     }
 
   /* Have to end the primary source file.  */
   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
-    { 
+    {
       named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
       dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
+      dw2_asm_output_data (1, 0, "End compilation unit");
     }
+
+  /* If we emitted any DW_FORM_strp form attribute, output the string
+     table too.  */
+  if (debug_str_hash)
+    htab_traverse (debug_str_hash, output_indirect_string, NULL);
 }
+#else
+
+/* This should never be used, but its address is needed for comparisons.  */
+const struct gcc_debug_hooks dwarf2_debug_hooks;
+
 #endif /* DWARF2_DEBUGGING_INFO */
+
+#include "gt-dwarf2out.h"