This makes -g work again in LTO mode for Windows targets by kludging around 
the missing support for copying PE-COFF debug sections in the simple object 
module of libiberty, thus effectively disabling early debug in LTO mode.
The patch also contains a fixlet for a related oversight in the LTO wrapper.

Bootstrapped and tested on x86-64/Windows, approved by Richard B. in the audit 
trail and applied on the mainline.


2018-04-12  Eric Botcazou  <ebotca...@adacore.com>

        PR target/85238
        * lto-wrapper.c (debug_objcopy): Open the files in binary mode.
        * dwarf2out.c (dwarf2out_early_finish): Do not generate assembly in LTO
        mode for PE-COFF targets.
        * config/i386/i386-protos.h (i386_pe_asm_lto_start): Declare.
        (i386_pe_asm_lto_end): Likewise.
        * config/i386/cygming.h (TARGET_ASM_LTO_START): Define.
        (TARGET_ASM_LTO_END): Likewise.
        * config/i386/winnt.c (saved_debug_info_level): New static variable.
        (i386_pe_asm_lto_start): New function.
        (i386_pe_asm_lto_end): Likewise.

-- 
Eric Botcazou
Index: config/i386/cygming.h
===================================================================
--- config/i386/cygming.h	(revision 259205)
+++ config/i386/cygming.h	(working copy)
@@ -356,6 +356,12 @@ do {						\
 #undef TARGET_ASM_FILE_END
 #define TARGET_ASM_FILE_END i386_pe_file_end
 
+/* Kludge because of missing PE-COFF support for early LTO debug.  */
+#undef  TARGET_ASM_LTO_START
+#define TARGET_ASM_LTO_START i386_pe_asm_lto_start
+#undef  TARGET_ASM_LTO_END
+#define TARGET_ASM_LTO_END i386_pe_asm_lto_end
+
 #undef ASM_COMMENT_START
 #define ASM_COMMENT_START " #"
 
Index: config/i386/i386-protos.h
===================================================================
--- config/i386/i386-protos.h	(revision 259205)
+++ config/i386/i386-protos.h	(working copy)
@@ -254,6 +254,8 @@ extern void i386_pe_asm_output_aligned_d
 						    HOST_WIDE_INT,
 						    HOST_WIDE_INT);
 extern void i386_pe_file_end (void);
+extern void i386_pe_asm_lto_start (void);
+extern void i386_pe_asm_lto_end (void);
 extern void i386_pe_start_function (FILE *, const char *, tree);
 extern void i386_pe_end_function (FILE *, const char *, tree);
 extern void i386_pe_end_cold_function (FILE *, const char *, tree);
Index: config/i386/winnt.c
===================================================================
--- config/i386/winnt.c	(revision 259205)
+++ config/i386/winnt.c	(working copy)
@@ -808,6 +808,23 @@ i386_pe_file_end (void)
     }
 }
 
+/* Kludge because of missing PE-COFF support for early LTO debug.  */
+
+static enum debug_info_levels saved_debug_info_level;
+
+void
+i386_pe_asm_lto_start (void)
+{
+  saved_debug_info_level = debug_info_level;
+  debug_info_level = DINFO_LEVEL_NONE;
+}
+
+void
+i386_pe_asm_lto_end (void)
+{
+  debug_info_level = saved_debug_info_level;
+}
+
 
 /* x64 Structured Exception Handling unwind info.  */
 
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 259205)
+++ dwarf2out.c	(working copy)
@@ -31807,7 +31807,11 @@ dwarf2out_early_finish (const char *file
   early_dwarf_finished = true;
 
   /* Do not generate DWARF assembler now when not producing LTO bytecode.  */
-  if (!flag_generate_lto && !flag_generate_offload)
+  if ((!flag_generate_lto && !flag_generate_offload)
+      /* FIXME: Disable debug info generation for PE-COFF targets since the
+	 copy_lto_debug_sections operation of the simple object support in
+	 libiberty is not implemented for them yet.  */
+      || TARGET_PECOFF)
     return;
 
   /* Now as we are going to output for LTO initialize sections and labels
Index: lto-wrapper.c
===================================================================
--- lto-wrapper.c	(revision 259205)
+++ lto-wrapper.c	(working copy)
@@ -983,7 +983,7 @@ debug_objcopy (const char *infile)
       infile = fname;
       inoff = (off_t) loffset;
     }
-  int infd = open (infile, O_RDONLY);
+  int infd = open (infile, O_RDONLY | O_BINARY);
   if (infd == -1)
     return NULL;
   simple_object_read *inobj = simple_object_start_read (infd, inoff,

Reply via email to