Hi,

the patch

2017-07-06  Jan Hubicka  <hubi...@ucw.cz>

        * lto-wrapper.c (merge_and_complain): Do not merge
        fexceptions, fnon_call_exceptions, ftrapv, ffp_contract_, fmath_errno,
        fsigned_zeros, ftrapping_math, fwrapv.
        (append_compiler_options): Do not track these options.
        (append_linker_options): Likewie

has broken exception handling in LTO mode for targets which don't force either 
-funwind-tables or -fasynchronous-unwind-tables (i.e not x86) and do not 
default to -fdwarf2-cfi-asm (i.e. not Linux), for example SPARC/Solaris.

The problem is that the eh_frame section is no longer generated because it is 
emitted from compile_file:

    #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
      if (dwarf2out_do_frame ())
        dwarf2out_frame_finish ();
    #endif

and this requires that either flag_unwind_tables or flag_exceptions be set.

But both -funwind-tables and -fexceptions are optimization options defaulting 
to 0 and they are reset to 0 through optimization_default_node after the last 
function is processed by the cgraph machinery.

Note that flag_exceptions is generally set to 1 in lto_init_eh very early, but 
the above mechanism overrides it.  However, flag_exceptions may *never* be set 
to 1 for a specific partition if it contains only EH-neutral functions; that's 
why I think that there is no other way than restoring the build-wide handling 
of -fexceptions before Jan's patch (hopefully it's the only affected switch).

Tested (lightly for now) on x86-64/Linux and SPARC/Solaris, OK for mainline?


2017-11-09  Eric Botcazou  <ebotca...@adacore.com>

        * lto-opts.c (lto_write_options): Do not save -fnon-call-exceptions,
        -ffp-contract, -fmath-errno, -fsigned-zeros, -ftrapping-math, -ftrapv
        and -fwrapv.
        * lto-wrapper.c (merge_and_complain): Merge again -fexceptions.
        (append_compiler_options): Pass again -fexceptions.

-- 
Eric Botcazou
Index: lto-opts.c
===================================================================
--- lto-opts.c	(revision 254560)
+++ lto-opts.c	(working copy)
@@ -82,61 +82,10 @@ lto_write_options (void)
       && global_options.x_flag_exceptions)
     append_to_collect_gcc_options (&temporary_obstack, &first_p,
 				   "-fexceptions");
-  /* -fnon-call-exceptions changes the generation of exception
-      regions.  It is enabled implicitly by the Go frontend.  */
-  if (!global_options_set.x_flag_non_call_exceptions
-      && global_options.x_flag_non_call_exceptions)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				   "-fnon-call-exceptions");
-  /* The default -ffp-contract changes depending on the language
-     standard.  Pass thru conservative standard settings.  */
-  if (!global_options_set.x_flag_fp_contract_mode)
-    switch (global_options.x_flag_fp_contract_mode)
-      {
-      case FP_CONTRACT_OFF:
-	append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				       "-ffp-contract=off");
-	break;
-      case FP_CONTRACT_ON:
-	append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				       "-ffp-contract=on");
-	break;
-      case FP_CONTRACT_FAST:
-	/* Nothing.  That merges conservatively and is the default for LTO.  */
-	break;
-      default:
-	gcc_unreachable ();
-      }
-  /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
-     depending on the language (they can be disabled by the Ada front-end).
-     Pass thru conservative standard settings.  */
-  if (!global_options_set.x_flag_errno_math)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				   global_options.x_flag_errno_math
-				   ? "-fmath-errno"
-				   : "-fno-math-errno");
-  if (!global_options_set.x_flag_signed_zeros)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				   global_options.x_flag_signed_zeros
-				   ? "-fsigned-zeros"
-				   : "-fno-signed-zeros");
-  if (!global_options_set.x_flag_trapping_math)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p,
-				   global_options.x_flag_trapping_math
-				   ? "-ftrapping-math"
-				   : "-fno-trapping-math");
-  /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
-     conservatively, so stream out their defaults.  */
-  if (!global_options_set.x_flag_wrapv
-      && global_options.x_flag_wrapv)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv");
-  if (!global_options_set.x_flag_trapv
-      && !global_options.x_flag_trapv)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv");
-
   if (!global_options_set.x_flag_openmp
       && !global_options.x_flag_openmp)
-    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openmp");
+    append_to_collect_gcc_options (&temporary_obstack, &first_p,
+				   "-fno-openmp");
   if (!global_options_set.x_flag_openacc
       && !global_options.x_flag_openacc)
     append_to_collect_gcc_options (&temporary_obstack, &first_p,
Index: lto-wrapper.c
===================================================================
--- lto-wrapper.c	(revision 254560)
+++ lto-wrapper.c	(working copy)
@@ -280,6 +280,7 @@ merge_and_complain (struct cl_decoded_op
 	  pie_option = foption;
 	  break;
 
+	case OPT_fexceptions:
 	case OPT_fopenmp:
 	case OPT_fopenacc:
 	case OPT_fcilkplus:
@@ -290,10 +291,11 @@ merge_and_complain (struct cl_decoded_op
 	      break;
 	  if (j == *decoded_options_count)
 	    append_option (decoded_options, decoded_options_count, foption);
-	  /* -fopenmp > -fno-openmp,
+	  /* -fexceptions -> -fno-exceptions
+	     -fopenmp > -fno-openmp,
 	     -fopenacc > -fno-openacc,
 	     -fcilkplus > -fno-cilkplus,
-	     -fcheck_pointer_bounds > -fcheck_pointer_bounds  */
+	     -fcheck-pointer-bounds > -fno-check-pointer-bounds  */
 	  else if (foption->value > (*decoded_options)[j].value)
 	    (*decoded_options)[j] = *foption;
 	  break;
@@ -546,6 +548,7 @@ append_compiler_options (obstack *argv_o
 	case OPT_fpie:
 	case OPT_fcommon:
 	case OPT_fgnu_tm:
+	case OPT_fexceptions:
 	case OPT_fopenmp:
 	case OPT_fopenacc:
 	case OPT_fopenacc_dim_:

Reply via email to