public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix EH breakage in LTO mode
@ 2017-11-09 16:39 Eric Botcazou
  2017-11-09 16:51 ` Richard Biener
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Eric Botcazou @ 2017-11-09 16:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1893 bytes --]

Hi,

the patch

2017-07-06  Jan Hubicka  <hubicka@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  <ebotcazou@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

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 4181 bytes --]

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-11-09 23:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-09 16:39 [patch] Fix EH breakage in LTO mode Eric Botcazou
2017-11-09 16:51 ` Richard Biener
2017-11-09 17:17 ` Jan Hubicka
2017-11-09 17:20   ` Eric Botcazou
2017-11-09 18:12     ` Jan Hubicka
2017-11-09 20:03       ` Richard Biener
2017-11-09 23:43       ` Eric Botcazou
2017-11-09 18:03 ` Rainer Orth
2017-11-09 23:39   ` Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).