On Fri, 20 Jul 2012 11:15:27 +0100
Julian Brown <jul...@codesourcery.com> wrote:

> Anyway: this revised version of the patch removes the strange libgcc
> Makefile-fragment changes, the equivalent of which have since been
> incorporated into mainline GCC now anyway, so the patch is somewhat
> more straightforward than it was previously.

Joey Ye contacted me offlist and suggested that the t-divmod-ef
fragment might be better integrated into t-bpabi instead. Doing that
makes the patch somewhat smaller/cleaner.

Minimally re-tested, looks OK.

Julian

ChangeLog

    libgcc/
    * Makefile.in (LIB2_DIVMOD_EXCEPTION_FLAGS): Default to
    -fexceptions -fnon-call-exceptions if not defined.
    ($(lib2-divmod-o), $(lib2-divmod-s-o)): Use above.
    * config/arm/t-bpabi (LIB2_DIVMOD_EXCEPTION_FLAGS): Define.

    gcc/testsuite/
    * gcc.target/arm/div64-unwinding.c: New test.
Index: libgcc/Makefile.in
===================================================================
--- libgcc/Makefile.in	(revision 189807)
+++ libgcc/Makefile.in	(working copy)
@@ -497,18 +497,24 @@ libgcc-s-objects += $(patsubst %,%_s$(ob
 endif
 endif
 
+ifeq ($(LIB2_DIVMOD_EXCEPTION_FLAGS),)
+# Provide default flags for compiling divmod functions, if they haven't been
+# set already by a target-specific Makefile fragment.
+LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions -fnon-call-exceptions
+endif
+
 # Build LIB2_DIVMOD_FUNCS.
 lib2-divmod-o = $(patsubst %,%$(objext),$(LIB2_DIVMOD_FUNCS))
 $(lib2-divmod-o): %$(objext): $(srcdir)/libgcc2.c
 	$(gcc_compile) -DL$* -c $< \
-	  -fexceptions -fnon-call-exceptions $(vis_hide)
+	  $(LIB2_DIVMOD_EXCEPTION_FLAGS) $(vis_hide)
 libgcc-objects += $(lib2-divmod-o)
 
 ifeq ($(enable_shared),yes)
 lib2-divmod-s-o = $(patsubst %,%_s$(objext),$(LIB2_DIVMOD_FUNCS))
 $(lib2-divmod-s-o): %_s$(objext): $(srcdir)/libgcc2.c
 	$(gcc_s_compile) -DL$* -c $< \
-	  -fexceptions -fnon-call-exceptions
+	  $(LIB2_DIVMOD_EXCEPTION_FLAGS)
 libgcc-s-objects += $(lib2-divmod-s-o)
 endif
 
Index: libgcc/config/arm/t-bpabi
===================================================================
--- libgcc/config/arm/t-bpabi	(revision 189807)
+++ libgcc/config/arm/t-bpabi	(working copy)
@@ -13,3 +13,8 @@ LIB2ADDEH = $(srcdir)/config/arm/unwind-
 
 # Add the BPABI names.
 SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver
+
+# On ARM, specifying -fnon-call-exceptions will needlessly pull in
+# the unwinder in simple programs which use 64-bit division.  Omitting
+# the option is safe.
+LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions
Index: gcc/testsuite/gcc.target/arm/div64-unwinding.c
===================================================================
--- gcc/testsuite/gcc.target/arm/div64-unwinding.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/div64-unwinding.c	(revision 0)
@@ -0,0 +1,24 @@
+/* Performing a 64-bit division should not pull in the unwinder.  */
+
+/* { dg-do run } */
+/* { dg-options "-O0" } */
+
+#include <stdlib.h>
+
+long long
+foo (long long c, long long d)
+{
+  return c/d;
+}
+
+long long x = 0;
+long long y = 1;
+
+extern int (*_Unwind_RaiseException) (void *) __attribute__((weak));
+
+int main(void)
+{
+  if (&_Unwind_RaiseException != NULL)
+    abort ();;
+  return foo (x, y);
+}

Reply via email to