+ 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: