This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH v2][MSP430] -Add fno-exceptions multilib
- From: Jozef Lawrynowicz <jozef dot l at mittosystems dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 27 Nov 2019 19:53:32 +0000
- Subject: [PATCH v2][MSP430] -Add fno-exceptions multilib
Original patch here: https://gcc.gnu.org/ml/gcc-patches/2019-11/msg00619.html
Late for stage 1 I know, but it's an iteration on a patch submitted before the
transition to stage 3 and the functional changes to the compiler are constrained
to the msp430 target.
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.
Since C++ libraries are built with exceptions enabled by default, there is
nothing the end user can do about this, even when they pass -fno-exceptions on
the command line.
So this patch adds a new -fno-exceptions multilib configuration for MSP430,
to reduce the code size linked executables when using C++ with -fno-exceptions.
Since building double the multilibs does significantly increase build time,
the patch also adds a configure option --disable-no-exceptions. This disables
the fno-exceptions multilibs from being built.
The changes from the original patch linked above are:
- Wrapped new gcc-dg-prune directives checking for disabled exception handling
in an if statement, so they are only used if exception handling has been
disabled in the global test configuration.
- Extended the spec strings used to check for when crt{begin,end}_no_eh.o can be
used. When linking a C program where exceptions are implicitly disabled,
crt{begin,end}_no_eh.o can always be used unless -fexceptions is explicitly
passed.
Successfully regtested for x86_64-pc-linux-gnu. There was no change in any of
the testresults (pass/fail/unsupported).
Regtested -fno-exceptions vs the default configuration for msp430-elf. There was
some fallout from exception handling tests not working, but nothing unexpected.
Ok to apply?
>From b74f34e5ae7f649296f7f6bcce35b75c34a2b0fd Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Mon, 25 Nov 2019 12:07:24 +0000
Subject: [PATCH] MSP430: Add fno-exceptions multilib
ChangeLog:
2019-11-27 Jozef Lawrynowicz <jozef.l@mittosystems.com>
* config-ml.in: Support --disable-no-exceptions configure flag.
gcc/ChangeLog:
2019-11-27 Jozef Lawrynowicz <jozef.l@mittosystems.com>
* config/msp430/msp430.h (STARTFILE_SPEC) [!fexceptions]: Use
crtbegin_no_eh.o if building for the C language.
[fno-exceptions]: Use crtbegin_no_eh.o if building for any language
except C.
(ENDFILE_SPEC) [!fexceptions]: Use crtend_no_eh.o if building for
the C language.
[fno-exceptions]: Use crtend_no_eh.o if building for any language
except C.
* config/msp430/t-msp430: Add -fno-exceptions multilib.
* doc/install.texi: Document --disable-no-exceptions multilib configure
option.
gcc/testsuite/ChangeLog:
2019-11-27 Jozef Lawrynowicz <jozef.l@mittosystems.com>
* lib/gcc-dg.exp: Add dg-prune messages for when exception handling is
disabled.
* lib/target-supports.exp (check_effective_target_exceptions_enabled):
New.
libgcc/ChangeLog:
2019-11-27 Jozef Lawrynowicz <jozef.l@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 | 11 +++++++++--
gcc/config/msp430/t-msp430 | 9 +++++----
gcc/doc/install.texi | 3 +++
gcc/testsuite/lib/gcc-dg.exp | 12 ++++++++++++
gcc/testsuite/lib/target-supports.exp | 18 ++++++++++++++++++
libgcc/config.host | 3 ++-
libgcc/config/msp430/t-msp430 | 6 ++++++
8 files changed, 68 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 0ea6b0a093e..7b94918a55d 100644
--- a/gcc/config/msp430/msp430.h
+++ b/gcc/config/msp430/msp430.h
@@ -44,13 +44,20 @@ extern bool msp430x;
} \
while (0)
+/* For the "c" language where exceptions are implicitly disabled, use
+ crt*_no_eh.o unless -fexceptions is passed. For other languages, only use
+ crt*_no_eh.o if -fno-exceptions is explicitly passed. */
#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:%{,c:%{!fexceptions:crtbegin_no_eh.o%s; :crtbegin.o%s}; " \
+ ":%{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:%{,c:%{!fexceptions:crtend_no_eh.o%s; :crtend.o%s}; " \
+ ":%{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 be203023da5..d926ca2e920 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1086,6 +1086,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..7396daa4a1d 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -417,6 +417,18 @@ 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 { ![check_effective_target_exceptions_enabled] } {
+ 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/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 5fe1e83492c..a5ced7980dc 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8960,6 +8960,24 @@ proc check_effective_target_exceptions {} {
return 1
}
+# Used to check if the testing configuration supports exceptions.
+# Returns 0 if exceptions are unsupported or disabled (e.g. by passing
+# -fno-exceptions). Returns 1 if exceptions are enabled.
+proc check_effective_target_exceptions_enabled {} {
+ return [check_cached_effective_target exceptions_enabled {
+ if { [check_effective_target_exceptions] } {
+ return [check_no_compiler_messages exceptions_enabled assembly {
+ void foo (void)
+ {
+ throw 1;
+ }
+ }]
+ } else {
+ # If exceptions aren't supported, then they're not enabled.
+ return 0
+ }
+ }]
+}
proc check_effective_target_tiny {} {
return [check_cached_effective_target tiny {
diff --git a/libgcc/config.host b/libgcc/config.host
index bc3e497739f..56868719fc8 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1045,7 +1045,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