Index: gcc-4.9.4/libgo/configure
===================================================================
--- gcc-4.9.4.orig/libgo/configure
+++ gcc-4.9.4/libgo/configure
@@ -14618,17 +14618,19 @@ void foo ()
 }
 
 _ACEOF
-CFLAGS_hold=$CFLAGS
-CFLAGS="--save-temps -fexceptions"
 libgo_cv_lib_sjlj_exceptions=unknown
-if ac_fn_c_try_compile; then :
+if { ac_try='${CC-cc} -fexceptions -S conftest.c -o conftest.s 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
   if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1; then
     libgo_cv_lib_sjlj_exceptions=yes
   elif grep _Unwind_Resume conftest.s >/dev/null 2>&1; then
     libgo_cv_lib_sjlj_exceptions=no
   fi
 fi
-CFLAGS=$CFLAGS_hold
 rm -f conftest*
 
 fi
Index: gcc-4.9.4/libgo/configure.ac
===================================================================
--- gcc-4.9.4.orig/libgo/configure.ac
+++ gcc-4.9.4/libgo/configure.ac
@@ -460,16 +460,14 @@ void foo ()
   bar();
 }
 ])])
-CFLAGS_hold=$CFLAGS
-CFLAGS="--save-temps -fexceptions"
 libgo_cv_lib_sjlj_exceptions=unknown
-AS_IF([ac_fn_c_try_compile],
-  [if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1; then
+if AC_TRY_COMMAND(${CC-cc} -fexceptions -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
+  if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1; then
     libgo_cv_lib_sjlj_exceptions=yes
   elif grep _Unwind_Resume conftest.s >/dev/null 2>&1; then
     libgo_cv_lib_sjlj_exceptions=no
-  fi])
-CFLAGS=$CFLAGS_hold
+  fi
+fi
 rm -f conftest*
 ])
 
