This seemingly innocuous change

2019-09-11  Richard Biener  <rguent...@suse.de>

* lto-opts.c (lto_write_options): Stream -g when debug is enabled.
* lto-wrapper.c (merge_and_complain): Pick up -g.
(append_compiler_options): Likewise.
(run_gcc): Re-instantiate handling -g0 at link-time.
* doc/invoke.texi (flto): Document debug info generation.

caused PR 91763, a test failure building Go code with -flto.  The
problem only arose when using the GNU assembler on Solaris.

The bug is that when emitting debug info but not exception info, and
when using gas, the DWARF code will emit
    .cfi_sections .debug_frame
This will direct gas to emit unwind info into .debug_frame but not .eh_frame.

Go code requires unwind info, and the Go library expects it to be in
.eh_frame.  The Go frontend always turns on exceptions, so this
.cfi_sections directive is not used.

However, when using -flto, the lto1 program decides whether it is
using exceptions based on what it reads from the input files.  Before
lto1 sees any input files, flag_exceptions will have its default value
of 0.  And lto1 initializes the debug info before seeing any input
files, so the debug initialization thinks that exceptions are not in
use, and emits the .cfi_sections directive.

This problem was uncovered by the above patch because Go code also
turns on debugging by default, and so lto1 now sees a -g option that
it did not see before.

This patch fixes the problem by moving the emission of .cfi_sections
from debug init to the first time that the debug info needs to know
whether CFI is supported.  This is only done when actually emitting
debug info, and therefore after some input files have been read.

Bootstrapped and ran full testsuite on x86_64-pc-linux-gnu.  Tested
that formerly failing case now passes on sparc-sun-solaris2.11.

OK for trunk?

Ian


2019-09-17  Ian Lance Taylor  <i...@golang.org>

PR go/91763
* dwarf2out.c (dwarf2out_assembly_start): Move ".cfi_sections
.debug_frame" output from here...
* dwarf2cfi.c (dwarf2out_do_cfi_asm): ...to here.
Index: gcc/dwarf2cfi.c
===================================================================
--- gcc/dwarf2cfi.c     (revision 275698)
+++ gcc/dwarf2cfi.c     (working copy)
@@ -3551,6 +3551,13 @@ dwarf2out_do_cfi_asm (void)
 
   /* Success!  */
   saved_do_cfi_asm = 1;
+
+  /* Emit .cfi_sections before any other .cfi directive.  We used to
+     do this in dwarf2out_assembly_start, but lto1 will call that
+     before setting flag_exceptions.  */
+  if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && !dwarf2out_do_eh_frame ())
+    fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
+
   return true;
 }
 
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 275698)
+++ gcc/dwarf2out.c     (working copy)
@@ -28901,11 +28901,6 @@ dwarf2out_assembly_start (void)
 #ifdef DWARF2_LINENO_DEBUGGING_INFO
   cur_line_info_table = text_section_line_info;
 #endif
-
-  if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
-      && dwarf2out_do_cfi_asm ()
-      && !dwarf2out_do_eh_frame ())
-    fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
 }
 
 /* A helper function for dwarf2out_finish called through

Reply via email to