* [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
@ 2012-07-20 10:15 Julian Brown
2012-07-24 12:27 ` Julian Brown
0 siblings, 1 reply; 8+ messages in thread
From: Julian Brown @ 2012-07-20 10:15 UTC (permalink / raw)
To: gcc-patches; +Cc: ramana.radhakrishnan, rearnsha
[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]
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
text data bss dec hex filename
13120 2404 276 15800 3db8 div64
$ arm-none-eabi-size div64-unpatched
text data bss dec hex filename
20064 2404 276 22744 58d8 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.
[-- Attachment #2: div64.cc --]
[-- Type: text/x-c++src, Size: 396 bytes --]
#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;
}
[-- Attachment #3: no-unwinder-for-long-division-fsf-3.diff --]
[-- Type: text/x-patch, Size: 3574 bytes --]
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: libgcc/config/arm/t-divmod-ef
===================================================================
--- libgcc/config/arm/t-divmod-ef (revision 0)
+++ libgcc/config/arm/t-divmod-ef (revision 0)
@@ -0,0 +1,4 @@
+# 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);
+}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-07-20 10:15 [PATCH, ARM] Don't pull in unwinder for 64-bit division routines Julian Brown
@ 2012-07-24 12:27 ` Julian Brown
2012-07-30 9:29 ` Sebastian Huber
2012-08-16 18:57 ` Ramana Radhakrishnan
0 siblings, 2 replies; 8+ messages in thread
From: Julian Brown @ 2012-07-24 12:27 UTC (permalink / raw)
Cc: gcc-patches, ramana.radhakrishnan, rearnsha, Ye Joey
[-- Attachment #1: Type: text/plain, Size: 883 bytes --]
On Fri, 20 Jul 2012 11:15:27 +0100
Julian Brown <julian@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.
[-- Attachment #2: no-unwinder-for-long-division-fsf-4.diff --]
[-- Type: text/x-patch, Size: 2352 bytes --]
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);
+}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-07-24 12:27 ` Julian Brown
@ 2012-07-30 9:29 ` Sebastian Huber
2012-08-16 18:57 ` Ramana Radhakrishnan
1 sibling, 0 replies; 8+ messages in thread
From: Sebastian Huber @ 2012-07-30 9:29 UTC (permalink / raw)
To: gcc-patches
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.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-07-24 12:27 ` Julian Brown
2012-07-30 9:29 ` Sebastian Huber
@ 2012-08-16 18:57 ` Ramana Radhakrishnan
2012-08-16 19:30 ` Julian Brown
2012-08-17 1:13 ` Ian Lance Taylor
1 sibling, 2 replies; 8+ messages in thread
From: Ramana Radhakrishnan @ 2012-08-16 18:57 UTC (permalink / raw)
To: Julian Brown; +Cc: gcc-patches, ian, Richard Earnshaw, Ye Joey
On 07/24/12 13:27, Julian Brown wrote:
> On Fri, 20 Jul 2012 11:15:27 +0100
> Julian Brown <julian@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-08-16 18:57 ` Ramana Radhakrishnan
@ 2012-08-16 19:30 ` Julian Brown
2012-08-21 22:27 ` Michael Hope
2012-08-17 1:13 ` Ian Lance Taylor
1 sibling, 1 reply; 8+ messages in thread
From: Julian Brown @ 2012-08-16 19:30 UTC (permalink / raw)
To: ramrad01; +Cc: gcc-patches, ian, Richard Earnshaw, Ye Joey
On Thu, 16 Aug 2012 19:56:52 +0100
Ramana Radhakrishnan <ramrad01@arm.com> wrote:
> On 07/24/12 13:27, Julian Brown wrote:
> > On Fri, 20 Jul 2012 11:15:27 +0100
> > Julian Brown <julian@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-08-16 19:30 ` Julian Brown
@ 2012-08-21 22:27 ` Michael Hope
0 siblings, 0 replies; 8+ messages in thread
From: Michael Hope @ 2012-08-21 22:27 UTC (permalink / raw)
To: Julian Brown; +Cc: ramrad01, gcc-patches, ian, Richard Earnshaw, Ye Joey
On 17 August 2012 07:29, Julian Brown <julian@codesourcery.com> wrote:
> On Thu, 16 Aug 2012 19:56:52 +0100
> Ramana Radhakrishnan <ramrad01@arm.com> wrote:
>
>> On 07/24/12 13:27, Julian Brown wrote:
>> > On Fri, 20 Jul 2012 11:15:27 +0100
>> > Julian Brown <julian@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH, ARM] Don't pull in unwinder for 64-bit division routines
2012-08-16 18:57 ` Ramana Radhakrishnan
2012-08-16 19:30 ` Julian Brown
@ 2012-08-17 1:13 ` Ian Lance Taylor
2012-08-21 7:47 ` Ye Joey
1 sibling, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2012-08-17 1:13 UTC (permalink / raw)
To: ramrad01; +Cc: Julian Brown, gcc-patches, ian, Richard Earnshaw, Ye Joey
On Thu, Aug 16, 2012 at 11:56 AM, Ramana Radhakrishnan <ramrad01@arm.com> wrote:
> On 07/24/12 13:27, Julian Brown wrote:
>>
>> On Fri, 20 Jul 2012 11:15:27 +0100
>> Julian Brown <julian@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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-08-21 22:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-20 10:15 [PATCH, ARM] Don't pull in unwinder for 64-bit division routines Julian Brown
2012-07-24 12:27 ` Julian Brown
2012-07-30 9:29 ` Sebastian Huber
2012-08-16 18:57 ` Ramana Radhakrishnan
2012-08-16 19:30 ` Julian Brown
2012-08-21 22:27 ` Michael Hope
2012-08-17 1:13 ` Ian Lance Taylor
2012-08-21 7:47 ` Ye Joey
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).