Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
On Fri, Aug 17, 2012 at 9:13 AM, Ian Lance Taylor i...@google.com wrote: Looks fine to me. Ian Will backport to arm/embedded-4_7-branch. No sure if appropriate for 4.7 branch since it is not a stability problem. - Joey
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
On 17 August 2012 07:29, Julian Brown jul...@codesourcery.com wrote: On Thu, 16 Aug 2012 19:56:52 +0100 Ramana Radhakrishnan ramra...@arm.com wrote: On 07/24/12 13:27, Julian Brown wrote: 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. The original submission makes no mention of testing ? The ARM specific portions look OK to me modulo no regressions. Thanks -- I'm sure I did test the patch, but just omitted to mention that fact in the mail :-O. We've also been carrying a version of this patch in our local source base for many years now. Hi Julian. The test case fails on arm-linux-gnueabi: http://gcc.gnu.org/ml/gcc-testresults/2012-08/msg02100.html FAIL: gcc.target/arm/div64-unwinding.c execution test The test aborts as _Unwind_RaiseException is not null. _divdi3.o itself looks fine and no longer pulls in the unwinder so I assume something else in the environment is. I've put the binaries up at http://people.linaro.org/~michaelh/incoming/div64-unwinding.exe and http://people.linaro.org/~michaelh/incoming/_divdi3.o if that helps. -- Michael
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
On 07/24/12 13:27, Julian Brown wrote: 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. The original submission makes no mention of testing ? The ARM specific portions look OK to me modulo no regressions. Ian, can also take a quick look. regards, Ramana
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
On Thu, 16 Aug 2012 19:56:52 +0100 Ramana Radhakrishnan ramra...@arm.com wrote: On 07/24/12 13:27, Julian Brown wrote: 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. The original submission makes no mention of testing ? The ARM specific portions look OK to me modulo no regressions. Thanks -- I'm sure I did test the patch, but just omitted to mention that fact in the mail :-O. We've also been carrying a version of this patch in our local source base for many years now. Ian, can also take a quick look. Cheers, Julian
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
On Thu, Aug 16, 2012 at 11:56 AM, Ramana Radhakrishnan ramra...@arm.com wrote: On 07/24/12 13:27, Julian Brown wrote: 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. The original submission makes no mention of testing ? The ARM specific portions look OK to me modulo no regressions. Ian, can also take a quick look. Looks fine to me. Ian
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
Hello, with this move to t-bpabi other targets like RTEMS profit also from this change. This is very good since the unwinder pull-in for 64-bit divisions was pretty bad for small Cortex-M3 systems with internal flash only. -- Sebastian Huber, embedded brains GmbH Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany Phone : +49 89 18 90 80 79-6 Fax : +49 89 18 90 80 79-9 E-Mail : sebastian.hu...@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
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); +}
[PATCH, ARM] Don't pull in unwinder for 64-bit division routines
Hi, This (old!) patch avoids uselessly pulling in the unwinder for 64-bit division routines. I last posted it here: http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01618.html Other people have noticed the same issue, e.g.: http://gcc.gnu.org/ml/gcc-help/2011-03/msg00187.html Note that we take special care already for the case where division-by-zero throws an exception: we tailcall the division-by-zero handler at the head of the 64-bit division helper routines, so never create a stack frame which needs to be unwound. On ARM, division by zero can trapped by defining magic __aeabi_[il]div0 functions. See here: http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01661.html Unfortunately, despite that, throwing an exception from the division-by-zero handler functions doesn't appear to work at present -- either with or without the current patch. I'm not intending to tackle that now (see attached program -- which exits with terminate called after throwing an instance of 'int' for me). I'm no C++ expert, so I might have done something dumb :-). 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. The patch allows a trivial program using 64-bit division (on bare metal) to shrink quite considerably: $ arm-none-eabi-size div64 textdata bss dec hex filename 131202404 276 158003db8 div64 $ arm-none-eabi-size div64-unpatched textdata bss dec hex filename 200642404 276 2274458d8 div64-unpatched OK to apply? Thanks, Julian ChangeLog libgcc/ * config.host (arm*-*-linux-*eabi, arm*-*-uclinux*eabi) (arm*-*-eabi*, arm*-*-symbianelf*, arm*-*-rtemseabi*): Add arm/t-divmod-ef to tmake_file. * 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-divmod-ef: New file. gcc/testsuite/ * gcc.target/arm/div64-unwinding.c: New test. #include cstdio long long a = 100, b = 0; extern C long long __aeabi_ldiv0 (long long retval) { throw 0; } int bad_division (void) { return a / b; } int main(int argc, char *argv[]) { try { bad_division (); } catch (int e) { fprintf (stderr, caught division by zero\n); return 0; } fprintf (stderr, didn't catch exception\n); return 1; } Index: libgcc/config.host === --- libgcc/config.host (revision 189656) +++ libgcc/config.host (working copy) @@ -317,7 +317,7 @@ arm*-*-linux*) # ARM GNU/Linux with EL tmake_file=${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix case ${host} in arm*-*-linux-*eabi) - tmake_file=${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi t-slibgcc-libgcc + tmake_file=${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi arm/t-divmod-ef t-slibgcc-libgcc tm_file=$tm_file arm/bpabi-lib.h unwind_header=config/arm/unwind-arm.h ;; @@ -331,7 +331,7 @@ arm*-*-uclinux*) # ARM ucLinux tmake_file=${tmake_file} t-fixedpoint-gnu-prefix case ${host} in arm*-*-uclinux*eabi) - tmake_file=${tmake_file} arm/t-bpabi + tmake_file=${tmake_file} arm/t-bpabi arm/t-divmod-ef tm_file=$tm_file arm/bpabi-lib.h unwind_header=config/arm/unwind-arm.h ;; @@ -344,7 +344,7 @@ arm*-*-ecos-elf) extra_parts=$extra_parts crti.o crtn.o ;; arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtemseabi*) - tmake_file=${tmake_file} arm/t-arm arm/t-elf t-fixedpoint-gnu-prefix + tmake_file=${tmake_file} arm/t-arm arm/t-elf arm/t-divmod-ef t-fixedpoint-gnu-prefix tm_file=$tm_file arm/bpabi-lib.h case ${host} in arm*-*-eabi* | arm*-*-rtemseabi*) Index: libgcc/Makefile.in === --- libgcc/Makefile.in (revision 189656) +++ 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: