This fixes crashes on Darwin with -flto -g because we pass the wrong
(NULL) debug_line_section in

        case dw_val_class_lineptr:
          dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
                                 debug_line_section, "%s", name);

which is because for some reason I used debug_sekelton_line_section
and friends for the early LTO dwarf.  That looks mistaken in the
above light so the following reverts that to use debug_line_section
and friends.

I verified that -flto -g -gsplit-dwarf still "works" (though that combo
doesn't make much sense, if only because .dwo objects for the ltrans
objects end up in /tmp ...).

LTO bootstrap with -g[23] succeeded on x86_64-unknown-linux-gnu,
bootstrap for all languages as well, testing in progress.

Approved by Jakub on IRC so I'll go ahead with this after the above

Haven't yet found a convenient place to disable -gsplit-dwarf for
the non-fat part of LTO in a way the driver sees it.  Any hints
appreciated.  There's also the (unwanted) side-effect of
-gsplit-dwarf enabling -ggnu-pubnames.  Disabling on the LTRANS
side alone should be possible by massaging lto-wrapper to append
-gno-split-dwarf I guess.


2018-04-12  Richard Biener  <>

        PR lto/85371
        * dwarf2out.c (init_sections_and_labels): Use debug_line_section[_label]
        for the early LTO debug to properly generate references to it
        during DIE emission.  Do not re-use that for the skeleton for
        (dwarf2out_early_finish): Likewise.

Index: gcc/dwarf2out.c
--- gcc/dwarf2out.c     (revision 259337)
+++ gcc/dwarf2out.c     (working copy)
@@ -28405,14 +28406,6 @@ init_sections_and_labels (bool early_lto
          debug_macinfo_section = get_section (debug_macinfo_section_name,
                                               | SECTION_EXCLUDE, NULL);
-         /* For macro info we have to refer to a debug_line section, so
-            similar to split-dwarf emit a skeleton one for early debug.  */
-         debug_skeleton_line_section
-           = get_section (DEBUG_LTO_LINE_SECTION,
-                          SECTION_DEBUG | SECTION_EXCLUDE, NULL);
-         ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
-                                      DEBUG_SKELETON_LINE_SECTION_LABEL,
-                                      generation);
@@ -28459,6 +28452,13 @@ init_sections_and_labels (bool early_lto
                                               SECTION_DEBUG | SECTION_EXCLUDE,
+      /* For macro info and the file table we have to refer to a
+        debug_line section.  */
+      debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
+                                       SECTION_DEBUG | SECTION_EXCLUDE, NULL);
+      ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
+                                  DEBUG_LINE_SECTION_LABEL, generation);
       debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
                                       | SECTION_EXCLUDE, NULL);
@@ -31845,7 +31849,7 @@ dwarf2out_early_finish (const char *file
   /* AIX Assembler inserts the length, so adjust the reference to match the
      offset expected by debuggers.  */
-  strcpy (dl_section_ref, debug_skeleton_line_section_label);
+  strcpy (dl_section_ref, debug_line_section_label);
     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
@@ -31918,7 +31922,7 @@ dwarf2out_early_finish (const char *file
       switch_to_section (debug_macinfo_section);
       ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
-      output_macinfo (debug_skeleton_line_section_label, true);
+      output_macinfo (debug_line_section_label, true);
       dw2_asm_output_data (1, 0, "End compilation unit");
       if (flag_fat_lto_objects)
@@ -31929,8 +31933,8 @@ dwarf2out_early_finish (const char *file
   /* Emit a skeleton debug_line section.  */
-  switch_to_section (debug_skeleton_line_section);
-  ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
+  switch_to_section (debug_line_section);
+  ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   output_line_info (true);
   /* If we emitted any indirect strings, output the string table too.  */

Reply via email to