On Fri, 08 Nov 2019 09:07:39 +0900 Oleg Endo <oleg.e...@t-online.de> wrote:
> On Thu, 2019-11-07 at 21:37 +0000, Jozef Lawrynowicz wrote: > > The code size bloat added by building C++ programs using libraries > > containing > > support for exceptions is significant. When using simple constructs such as > > static variables, sometimes many kB from the libraries are unnecessarily > > pulled in. > > > > So this patch disable exceptions by default for MSP430 when compiling for > > C++, > > by implicitly passing -fno-exceptions unless -fexceptions is passed. > > It is extremely annoying when GCC's default standard behavior differs > across different targets. And as a consequence, you have to add a load > of workarounds and disable other things, like fiddling with the > testsuite. It's the same thing as setting "double = float" to get more > "speed" by default. > > I would strongly advice against making such non-standard behaviors the > default in the vanilla compiler. C++ normally has exceptions enabled. > If a user doesn't want them and is willing to deal with it all the > consequences, then we already have a mechanism to do that: > --fno-exceptions > > Perhaps it's generally more useful to add a global configure option for > GCC to disable exception handling by default. Then you can provide a > turn-key toolchain to your customers as well -- just add an option to > the configure line. > > Cheers, > Oleg > Fair point, I probably should have realised whilst implementing all the testsuite workarounds that this wasn't the best choice for upstream GCC and integrating nicely with the testsuite. So I've regtested and attached a revised patch to instead build -fno-exceptions multilibs, so the reduced code size can still be achieved by passing with -fno-exceptions. And the --disable-no-exceptions multilib option is added to reduce build time for developers. Thanks for providing your input, Jozef
>From fe67a5ff71bc48af05b086b2d495fbf77e1a070d Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz <joze...@mittosystems.com> Date: Fri, 8 Nov 2019 10:47:26 +0000 Subject: [PATCH 2/4] MSP430: Add -fno-exceptions multilib ChangeLog: 2019-11-08 Jozef Lawrynowicz <joze...@mittosystems.com> * config-ml.in: Support --disable-no-exceptions configure flag. gcc/ChangeLog: 2019-11-08 Jozef Lawrynowicz <joze...@mittosystems.com> * config/msp430/msp430.h (STARTFILE_SPEC) [fno-exceptions]: Use crtbegin_no_eh.o. (ENDFILE_SPEC) [fno-exceptions]: Use crtend_no_eh.o. * config/msp430/t-msp430: Add -fno-exceptions multilib. * doc/install.texi: Document --disable-no-exceptions multilib configure option. gcc/testsuite/ChangeLog: 2019-11-08 Jozef Lawrynowicz <joze...@mittosystems.com> * lib/gcc-dg.exp: Add dg-prune messages for when exception handling is disabled. libgcc/ChangeLog: 2019-11-08 Jozef Lawrynowicz <joze...@mittosystems.com> * config.host: Add crt{begin,end}_no_eh.o to "extra_parts". * config/msp430/t-msp430: Add rules to build crt{begin,end}_no_eh.o. --- config-ml.in | 13 +++++++++++++ gcc/config/msp430/msp430.h | 6 ++++-- gcc/config/msp430/t-msp430 | 9 +++++---- gcc/doc/install.texi | 3 +++ gcc/testsuite/lib/gcc-dg.exp | 10 ++++++++++ libgcc/config.host | 3 ++- libgcc/config/msp430/t-msp430 | 6 ++++++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/config-ml.in b/config-ml.in index 3e37f875c88..5720d38d23f 100644 --- a/config-ml.in +++ b/config-ml.in @@ -383,6 +383,19 @@ mips*-*-*) done fi ;; +msp430-*-*) + if [ x$enable_no_exceptions = xno ] + then + old_multidirs="${multidirs}" + multidirs="" + for x in ${old_multidirs}; do + case "$x" in + *no-exceptions* ) : ;; + *) multidirs="${multidirs} ${x}" ;; + esac + done + fi + ;; powerpc*-*-* | rs6000*-*-*) if [ x$enable_aix64 = xno ] then diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h index 73afe2e2d16..4d796f67d1b 100644 --- a/gcc/config/msp430/msp430.h +++ b/gcc/config/msp430/msp430.h @@ -46,11 +46,13 @@ extern bool msp430x; #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{pg:gcrt0.o%s}" \ - "%{!pg:%{minrt:crt0-minrt.o%s}%{!minrt:crt0.o%s}} %{!minrt:crtbegin.o%s}" + "%{!pg:%{minrt:crt0-minrt.o%s}%{!minrt:crt0.o%s}} " \ + "%{!minrt:%{fno-exceptions:crtbegin_no_eh.o%s; :crtbegin.o%s}}" /* -lgcc is included because crtend.o needs __mspabi_func_epilog_1. */ #undef ENDFILE_SPEC -#define ENDFILE_SPEC "%{!minrt:crtend.o%s} " \ +#define ENDFILE_SPEC \ + "%{!minrt:%{fno-exceptions:crtend_no_eh.o%s; :crtend.o%s}} " \ "%{minrt:%:if-exists(crtn-minrt.o%s)}%{!minrt:%:if-exists(crtn.o%s)} -lgcc" #define ASM_SPEC "-mP " /* Enable polymorphic instructions. */ \ diff --git a/gcc/config/msp430/t-msp430 b/gcc/config/msp430/t-msp430 index f8ba7751123..e180ce3efdb 100644 --- a/gcc/config/msp430/t-msp430 +++ b/gcc/config/msp430/t-msp430 @@ -28,8 +28,8 @@ msp430-devices.o: $(srcdir)/config/msp430/msp430-devices.c \ # Enable multilibs: -MULTILIB_OPTIONS = mcpu=msp430 mlarge mdata-region=none -MULTILIB_DIRNAMES = 430 large full-memory-range +MULTILIB_OPTIONS = mcpu=msp430 mlarge mdata-region=none fno-exceptions +MULTILIB_DIRNAMES = 430 large full-memory-range no-exceptions # Match -mcpu=430 MULTILIB_MATCHES = mcpu?msp430=mcpu?430 @@ -41,9 +41,10 @@ MULTILIB_MATCHES += mdata-region?none=mdata-region?either # hard-coded data here, because DRIVER_SELF_SPECS will place the correct # -mcpu option for a given mcu onto the command line. -MULTILIB_REQUIRED = mcpu=msp430 -MULTILIB_REQUIRED += mlarge +MULTILIB_REQUIRED = mcpu=msp430 mlarge +MULTILIB_REQUIRED += fno-exceptions mcpu=msp430/fno-exceptions mlarge/fno-exceptions MULTILIB_REQUIRED += mlarge/mdata-region=none +MULTILIB_REQUIRED += mlarge/mdata-region=none/fno-exceptions MULTILIB_EXTRA_OPTS = diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 563de705881..5250547f98e 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1087,6 +1087,9 @@ softfloat, m68881, m68000, m68020. @item mips*-*-* single-float, biendian, softfloat. +@item msp430-*-* +no-exceptions + @item powerpc*-*-*, rs6000*-*-* aix64, pthread, softfloat, powercpu, powerpccpu, powerpcos, biendian, sysv, aix. diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 1df645e283c..1ce449cb935 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -417,6 +417,16 @@ proc gcc-dg-prune { system text } { return "::unsupported::large return values" } + # If exceptions are disabled, mark tests expecting exceptions to be enabled + # as unsupported. + if [regexp "(^|\n)\[^\n\]*: error: exception handling disabled" $text] { + return "::unsupported::exception handling disabled" + } + + if [regexp "(^|\n)\[^\n\]*: error: #error .__cpp_exceptions." $text] { + return "::unsupported::exception handling disabled" + } + return $text } diff --git a/libgcc/config.host b/libgcc/config.host index 122113fc519..99cd5d3ae7c 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -1029,7 +1029,8 @@ moxie-*-elf | moxie-*-moxiebox* | moxie-*-uclinux* | moxie-*-rtems*) ;; msp430*-*-elf) tmake_file="$tm_file t-crtstuff t-fdpbit msp430/t-msp430" - extra_parts="$extra_parts libmul_none.a libmul_16.a libmul_32.a libmul_f5.a" + extra_parts="$extra_parts crtbegin_no_eh.o crtend_no_eh.o" + extra_parts="$extra_parts libmul_none.a libmul_16.a libmul_32.a libmul_f5.a" ;; nds32*-linux*) # Basic makefile fragment and extra_parts for crt stuff. diff --git a/libgcc/config/msp430/t-msp430 b/libgcc/config/msp430/t-msp430 index 17d85b6cb23..72ae93a8dae 100644 --- a/libgcc/config/msp430/t-msp430 +++ b/libgcc/config/msp430/t-msp430 @@ -42,6 +42,12 @@ LIB2ADD = \ HOST_LIBGCC2_CFLAGS += -Os -ffunction-sections -fdata-sections -mhwmult=none +crtbegin_no_eh.o: $(srcdir)/crtstuff.c + $(crt_compile) -U__LIBGCC_EH_FRAME_SECTION_NAME__ -c $< -DCRT_BEGIN + +crtend_no_eh.o: $(srcdir)/crtstuff.c + $(crt_compile) -U__LIBGCC_EH_FRAME_SECTION_NAME__ -c $< -DCRT_END + mpy.o: $(srcdir)/config/msp430/mpy.c $(gcc_compile) $< -c -- 2.17.1