public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size
@ 2019-11-07 21:31 Jozef Lawrynowicz
  2019-11-07 21:34 ` [PATCH 1/4] MSP430: Disable TM clone registry by default Jozef Lawrynowicz
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-07 21:31 UTC (permalink / raw)
  To: gcc-patches

When building small programs for MSP430, the impact of the unused
functions pulled in from the CRT libraries is quite noticeable. Most of these
relates to feature that will never be used for MSP430 (Transactional memory,
supporting shared objects and dynamic linking), or rarely used (exception
handling).

The following patches change the default configuration for msp430-elf with the
aim of reducing code size by removing these unsupported features.

Related generic changes to GCC have been submitted here:
https://gcc.gnu.org/ml/gcc-patches/2019-11/msg00415.html
(But note that the first patch to disable eh frame registry has been retracted
as it's no longer necessary).

I picked random C and C++ programs from the testsuite to give an
indication of the size reduction:

$ msp430-elf-gcc testsuite/gcc.dg/20000108-1.c -Os -msim -ffunction-sections \
    -fdata-sections -Wl,-gc-sections
Before:
   text    data     bss     dec     hex filename
    708     242      28     978     3d2 20000108-1.exe
After:
   text    data     bss     dec     hex filename
    444     234       2     680     2a8 20000108-1.exe

$ msp430-elf-g++ -msim -Os testsuite/g++.dg/abi/covariant5.C \
    -ffunction-sections -fdata-sections -Wl,-gc-sections
Before:
   text    data     bss     dec     hex filename
   4090     396      18    4504    1198 covariant5.exe
Before (-fno-exceptions):
   text    data     bss     dec     hex filename
   3912     396      18    4326    10e6 a.out
After:
   text    data     bss     dec     hex filename
   3396     122       2    3520     dc0 covariant5.exe

The writeup for the -minrt patch has some more code size comparisons related to
that option.

Successfully regtested for msp430-elf.

Ok to apply?

Jozef Lawrynowicz (4):
  MSP430: Disable TM clone registry by default
  MSP430: Disable exception handling by default for C++
  MSP430: Disable __cxa_atexit
  MSP430: Remove -minrt option

 config-ml.in                                  | 13 +++++++++
 gcc/config.gcc                                |  7 +++++
 gcc/config/msp430/msp430.c                    |  9 +++++++
 gcc/config/msp430/msp430.h                    | 20 +++++++++++---
 gcc/config/msp430/msp430.opt                  |  4 +--
 gcc/config/msp430/t-msp430                    |  9 ++++---
 gcc/doc/install.texi                          |  3 +++
 gcc/doc/invoke.texi                           | 15 ++++-------
 gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C   |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit1.C        |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit2.C        |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit5.C        |  2 +-
 gcc/testsuite/g++.dg/dg.exp                   |  9 ++++++-
 gcc/testsuite/g++.dg/eh/array1.C              |  2 +-
 gcc/testsuite/g++.dg/eh/spec11.C              |  2 +-
 gcc/testsuite/g++.dg/eh/spec6.C               |  2 +-
 gcc/testsuite/g++.dg/ext/vla4.C               |  2 +-
 gcc/testsuite/g++.dg/init/dso_handle1.C       |  1 +
 gcc/testsuite/g++.dg/init/dso_handle2.C       |  1 +
 gcc/testsuite/g++.dg/ipa/pr64612.C            |  2 +-
 gcc/testsuite/g++.dg/other/cxa-atexit1.C      |  1 +
 gcc/testsuite/g++.dg/other/error32.C          |  2 +-
 gcc/testsuite/g++.dg/torture/dg-torture.exp   |  9 ++++++-
 gcc/testsuite/g++.dg/torture/pr34850.C        |  2 +-
 gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C      |  2 +-
 gcc/testsuite/g++.dg/tree-ssa/pr33615.C       |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-1.C    |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-2.C    |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-3.C    |  2 +-
 .../g++.dg/warn/Wstringop-truncation-2.C      |  2 +-
 gcc/testsuite/g++.dg/warn/Wterminate1.C       |  2 +-
 gcc/testsuite/g++.dg/warn/pr83054.C           |  2 +-
 gcc/testsuite/g++.old-deja/g++.other/cond5.C  |  2 +-
 gcc/testsuite/g++.old-deja/old-deja.exp       |  9 ++++++-
 gcc/testsuite/lib/gcc-dg.exp                  | 10 +++++++
 gcc/testsuite/lib/target-supports.exp         | 27 ++++++++++++++++---
 libgcc/config.host                            |  3 ++-
 libgcc/config/msp430/t-msp430                 |  6 +++++
 libgcc/configure                              |  9 +++++++
 libgcc/configure.ac                           |  8 ++++++
 40 files changed, 166 insertions(+), 47 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/4] MSP430: Disable TM clone registry by default
  2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
@ 2019-11-07 21:34 ` Jozef Lawrynowicz
  2019-11-17 19:32   ` Jeff Law
  2019-11-07 21:37 ` [PATCH 2/4] MSP430: Disable exception handling by default for C++ Jozef Lawrynowicz
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-07 21:34 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]

Given that MSP430 is a resource constrained, embedded target disabling
transactional memory by default is a good idea to save on code size in
the runtime library.

It can still be enabled by passing --enable-tm-clone-registry (although as far
as I understand the feature is fundamentally incompatible with MSP430 given
reliance on libitm, lack of thread support without an OS and the memory
limitations of the device.

[-- Attachment #2: 0001-MSP430-Disable-TM-clone-registry-by-default.patch --]
[-- Type: text/x-patch, Size: 1374 bytes --]

From 9dfc5fde568c5a4cd29471888bff538943a995b1 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Tue, 29 Oct 2019 14:49:08 +0000
Subject: [PATCH 1/4] MSP430: Disable TM clone registry by default

libgcc/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* configure: Regenerate.
	* configure.ac (tm-clone-registry): Disable by default for MSP430.
---
 libgcc/configure    | 9 +++++++++
 libgcc/configure.ac | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/libgcc/configure b/libgcc/configure
index 117e9c97e57..26d4d68a510 100755
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -4964,6 +4964,15 @@ if test "$enable_tm_clone_registry" = no; then
   use_tm_clone_registry=-DUSE_TM_CLONE_REGISTRY=0
 fi
 
+else
+
+use_tm_clone_registry=
+case $target in
+  msp430*)
+   use_tm_clone_registry=-DUSE_TM_CLONE_REGISTRY=0
+   ;;
+esac
+
 fi
 
 
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index f63c5e736e5..0f225b84117 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -268,6 +268,14 @@ use_tm_clone_registry=
 if test "$enable_tm_clone_registry" = no; then
   use_tm_clone_registry=-DUSE_TM_CLONE_REGISTRY=0
 fi
+],
+[
+use_tm_clone_registry=
+case $target in
+  msp430*)
+   use_tm_clone_registry=-DUSE_TM_CLONE_REGISTRY=0
+   ;;
+esac
 ])
 AC_SUBST([use_tm_clone_registry])
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 2/4] MSP430: Disable exception handling by default for C++
  2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
  2019-11-07 21:34 ` [PATCH 1/4] MSP430: Disable TM clone registry by default Jozef Lawrynowicz
@ 2019-11-07 21:37 ` Jozef Lawrynowicz
  2019-11-08  0:07   ` Oleg Endo
  2019-11-07 21:39 ` [PATCH 3/4] MSP430: Disable __cxa_atexit Jozef Lawrynowicz
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-07 21:37 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

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.

Multilibs have been added for the -fexceptions configuration.
Since building double the multilibs does significantly increase build time,
the patch also adds a configure option --disable-exceptions. This disables the
fexceptions mulitlibs from being built.

There was a lot of fallout from the G++ testsuite caused by disabling exceptions
by default.

I've mitigated some of it by adding dg-prune strings which mark a test as
unsupported if the compiler reports exception handling is disabled. This doesn't
work for some execution tests or tests for warnings/errors/messages.

There's some further mitigation achieved by new functionality which
will pass -fexceptions as a default flag if exceptions are supported but not
enabled by default.
However, for tests with dg-options directives, this gets ignored. So
for these tests (of which there weren't *too* many, I've added -fexceptions to
the dg-options directives in the tests.

As a result of all the above there aren't any DejaGNU regressions.

[-- Attachment #2: 0002-MSP430-Disable-exception-handling-by-default-for-C.patch --]
[-- Type: text/x-patch, Size: 22671 bytes --]

From 7844e05172d07443167c3e852cf0b695f043c0eb Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Tue, 29 Oct 2019 15:32:07 +0000
Subject: [PATCH 2/4] MSP430: Disable exception handling by default for C++

ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config-ml.in: Support --disable-exceptions configure flag.

gcc/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config/msp430/msp430.h (STARTFILE_SPEC) [!fexceptions]: Use
	crtbegin_no_eh.o.
	(ENDFILE_SPEC) [!fexceptions]: Use crtend_no_eh.o.
	(CC1PLUS_SPEC): Define.
	* config/msp430/t-msp430: Add -fexceptions multilibs.
	* doc/install.texi: Document --disable-exceptions configure option.
	* doc/invoke.texi: Document that exceptions are disabled by default for
	C++ for msp430-elf.

gcc/testsuite/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* g++.dg/cpp1y/sized-dealloc2.C: Add -fexceptions to dg-options.
	* g++.dg/cpp2a/explicit1.C: Likewise.
	* g++.dg/cpp2a/explicit2.C: Likewise.
	* g++.dg/cpp2a/explicit5.C: Likewise.
	* g++.dg/eh/array1.C: Likewise.
	* g++.dg/eh/spec11.C: Likewise.
	* g++.dg/eh/spec6.C: Likewise.
	* g++.dg/ext/vla4.C: Likewise.
	* g++.dg/ipa/pr64612.C: Likewise.
	* g++.dg/other/error32.C: Likewise.
	* g++.dg/torture/pr34850.C: Likewise.
	* g++.dg/tree-ssa/ivopts-3.C: Likewise.
	* g++.dg/tree-ssa/pr33615.C: Likewise.
	* g++.dg/warn/Wcatch-value-1.C: Likewise.
	* g++.dg/warn/Wcatch-value-2.C: Likewise.
	* g++.dg/warn/Wcatch-value-3.C: Likewise.
	* g++.dg/warn/Wstringop-truncation-2.C: Likewise.
	* g++.dg/warn/Wterminate1.C: Likewise.
	* g++.dg/warn/pr83054.C: Likewise.
	* g++.old-deja/g++.other/cond5.C: Likewise.
	* g++.dg/dg.exp: Pass -fexceptions as a default flag if exceptions
	aren't enabled by default.
	* g++.dg/torture/dg-torture.exp: Likewise.
	* g++.old-deja/old-deja.exp:
	* lib/gcc-dg.exp: Add dg-prune messages for when exception handling is
	disabled.
	* lib/target-supports.exp (check_effective_target_exceptions): Check if
	GCC was configured with --disable-exceptions.
	(check_effective_target_exceptions_enabled_by_default): New.

libgcc/ChangeLog:

2019-11-07  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/doc/invoke.texi                           |  6 +++--
 gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C   |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit1.C        |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit2.C        |  2 +-
 gcc/testsuite/g++.dg/cpp2a/explicit5.C        |  2 +-
 gcc/testsuite/g++.dg/dg.exp                   |  9 ++++++-
 gcc/testsuite/g++.dg/eh/array1.C              |  2 +-
 gcc/testsuite/g++.dg/eh/spec11.C              |  2 +-
 gcc/testsuite/g++.dg/eh/spec6.C               |  2 +-
 gcc/testsuite/g++.dg/ext/vla4.C               |  2 +-
 gcc/testsuite/g++.dg/ipa/pr64612.C            |  2 +-
 gcc/testsuite/g++.dg/other/error32.C          |  2 +-
 gcc/testsuite/g++.dg/torture/dg-torture.exp   |  9 ++++++-
 gcc/testsuite/g++.dg/torture/pr34850.C        |  2 +-
 gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C      |  2 +-
 gcc/testsuite/g++.dg/tree-ssa/pr33615.C       |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-1.C    |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-2.C    |  2 +-
 gcc/testsuite/g++.dg/warn/Wcatch-value-3.C    |  2 +-
 .../g++.dg/warn/Wstringop-truncation-2.C      |  2 +-
 gcc/testsuite/g++.dg/warn/Wterminate1.C       |  2 +-
 gcc/testsuite/g++.dg/warn/pr83054.C           |  2 +-
 gcc/testsuite/g++.old-deja/g++.other/cond5.C  |  2 +-
 gcc/testsuite/g++.old-deja/old-deja.exp       |  9 ++++++-
 gcc/testsuite/lib/gcc-dg.exp                  | 10 ++++++++
 gcc/testsuite/lib/target-supports.exp         | 24 ++++++++++++++++---
 libgcc/config.host                            |  3 ++-
 libgcc/config/msp430/t-msp430                 |  6 +++++
 32 files changed, 117 insertions(+), 35 deletions(-)

diff --git a/config-ml.in b/config-ml.in
index 3e37f875c88..0fccf41f7cd 100644
--- a/config-ml.in
+++ b/config-ml.in
@@ -383,6 +383,19 @@ mips*-*-*)
 	  done
 	fi
 	;;
+msp430-*-*)
+	if [ x$enable_exceptions = xno ]
+	then
+	  old_multidirs="${multidirs}"
+	  multidirs=""
+	  for x in ${old_multidirs}; do
+	    case "$x" in
+	      *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..90ceec0e947 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:%{fexceptions:crtbegin.o%s}%{!fexceptions:crtbegin_no_eh.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:%{fexceptions:crtend.o%s}%{!fexceptions:crtend_no_eh.o%s}} "  \
   "%{minrt:%:if-exists(crtn-minrt.o%s)}%{!minrt:%:if-exists(crtn.o%s)} -lgcc"
 
 #define ASM_SPEC "-mP " /* Enable polymorphic instructions.  */ \
@@ -104,6 +106,11 @@ extern const char *msp430_propagate_region_opt (int, const char **);
   { "msp430_check_path_for_devices", msp430_check_path_for_devices }, \
   { "msp430_propagate_region_opt", msp430_propagate_region_opt },
 
+#undef  CC1PLUS_SPEC
+#define CC1PLUS_SPEC	\
+  "%(cc1) "		\
+  "%{!fexceptions:-fno-exceptions} "
+
 /* Specify the libraries to include on the linker command line.
 
    Selecting the hardware multiply library to use is quite complex.
diff --git a/gcc/config/msp430/t-msp430 b/gcc/config/msp430/t-msp430
index f8ba7751123..2c27f94d19e 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 fexceptions
+MULTILIB_DIRNAMES   = 430	   large  full-memory-range 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 += fexceptions mcpu=msp430/fexceptions mlarge/fexceptions
 MULTILIB_REQUIRED += mlarge/mdata-region=none
+MULTILIB_REQUIRED += mlarge/mdata-region=none/fexceptions
 
 
 MULTILIB_EXTRA_OPTS =
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 563de705881..fcdbc948b7e 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-*-*
+exceptions
+
 @item powerpc*-*-*, rs6000*-*-*
 aix64, pthread, softfloat, powercpu, powerpccpu, powerpcos, biendian,
 sysv, aix.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1407d019d14..6829b949b4b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13945,14 +13945,16 @@ Enable exception handling.  Generates extra code needed to propagate
 exceptions.  For some targets, this implies GCC generates frame
 unwind information for all functions, which can produce significant data
 size overhead, although it does not affect execution.  If you do not
-specify this option, GCC enables it by default for languages like
-C++ that normally require exception handling, and disables it for
+specify this option, for most targets GCC enables it by default for languages
+like C++ that normally require exception handling, and disables it for
 languages like C that do not normally require it.  However, you may need
 to enable this option when compiling C code that needs to interoperate
 properly with exception handlers written in C++.  You may also wish to
 disable this option if you are compiling older C++ programs that don't
 use exception handling.
 
+The msp430-elf target disables exceptions by default for C++.
+
 @item -fnon-call-exceptions
 @opindex fnon-call-exceptions
 Generate code that allows trapping instructions to throw exceptions.
diff --git a/gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C b/gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C
index 0a76cdccd32..71545409b79 100644
--- a/gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C
+++ b/gcc/testsuite/g++.dg/cpp1y/sized-dealloc2.C
@@ -2,7 +2,7 @@
 // placement deallocation function.  This will be a warning in C++98/11
 // modes and an error in C++14 mode.
 
-// { dg-options "-Wc++14-compat" }
+// { dg-options "-fexceptions -Wc++14-compat" }
 
 #include <new>
 void *operator new (std::size_t s, std::size_t)
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit1.C b/gcc/testsuite/g++.dg/cpp2a/explicit1.C
index b39f90f3397..4537977f767 100644
--- a/gcc/testsuite/g++.dg/cpp2a/explicit1.C
+++ b/gcc/testsuite/g++.dg/cpp2a/explicit1.C
@@ -1,6 +1,6 @@
 // P0892R2
 // { dg-do compile }
-// { dg-options "-std=c++2a" }
+// { dg-options "-fexceptions -std=c++2a" }
 
 constexpr int fn0 () { return 0; }
 constexpr int fn1 () { return 1; }
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit2.C b/gcc/testsuite/g++.dg/cpp2a/explicit2.C
index 7d1748c0f5e..791218f56c4 100644
--- a/gcc/testsuite/g++.dg/cpp2a/explicit2.C
+++ b/gcc/testsuite/g++.dg/cpp2a/explicit2.C
@@ -1,6 +1,6 @@
 // P0892R2
 // { dg-do compile }
-// { dg-options "-std=c++2a" }
+// { dg-options "-fexceptions -std=c++2a" }
 
 int foo() { return 42; }
 int g;
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit5.C b/gcc/testsuite/g++.dg/cpp2a/explicit5.C
index 70a106f1fcb..9a20bf62b86 100644
--- a/gcc/testsuite/g++.dg/cpp2a/explicit5.C
+++ b/gcc/testsuite/g++.dg/cpp2a/explicit5.C
@@ -1,6 +1,6 @@
 // P0892R2
 // { dg-do compile }
-// { dg-options "-std=c++2a" }
+// { dg-options "-fexceptions -std=c++2a" }
 
 constexpr int fn0 () { return 0; }
 constexpr int fn1 () { return 1; }
diff --git a/gcc/testsuite/g++.dg/dg.exp b/gcc/testsuite/g++.dg/dg.exp
index 233fdabd327..0c3e6d4f0d5 100644
--- a/gcc/testsuite/g++.dg/dg.exp
+++ b/gcc/testsuite/g++.dg/dg.exp
@@ -42,8 +42,15 @@ proc find-cxx-tests { dir suffix } {
 
 set tests [find-cxx-tests $srcdir/$subdir {C}]
 
+# Pass -fexceptions as a default flag if it's not implicitly enabled.
+set flag_exceptions ""
+if { [check_effective_target_exceptions]
+    && ![check_effective_target_exceptions_enabled_by_default] } {
+    set flag_exceptions "-fexceptions"
+}
+
 # Main loop.
-g++-dg-runtest $tests "" $DEFAULT_CXXFLAGS
+g++-dg-runtest $tests "" "$DEFAULT_CXXFLAGS $flag_exceptions"
 
 # C/C++ common tests.
 g++-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/*.\[cSi\]]] \
diff --git a/gcc/testsuite/g++.dg/eh/array1.C b/gcc/testsuite/g++.dg/eh/array1.C
index 30b035cfc52..3b04da0206a 100644
--- a/gcc/testsuite/g++.dg/eh/array1.C
+++ b/gcc/testsuite/g++.dg/eh/array1.C
@@ -1,6 +1,6 @@
 // Test that we have one EH cleanup region for the whole array
 // rather than one for each element.
-// { dg-options "-fdump-tree-gimple" }
+// { dg-options "-fexceptions -fdump-tree-gimple" }
 
 struct A
 {
diff --git a/gcc/testsuite/g++.dg/eh/spec11.C b/gcc/testsuite/g++.dg/eh/spec11.C
index 4615a640519..0414ec59158 100644
--- a/gcc/testsuite/g++.dg/eh/spec11.C
+++ b/gcc/testsuite/g++.dg/eh/spec11.C
@@ -8,7 +8,7 @@
 // { dg-final { scan-assembler-not "EHB" } }
 // { dg-final { scan-assembler "LSDA" } }
 
-// { dg-options "-fnothrow-opt" }
+// { dg-options "-fexceptions -fnothrow-opt" }
 
 struct A { ~A(); };
 void g();
diff --git a/gcc/testsuite/g++.dg/eh/spec6.C b/gcc/testsuite/g++.dg/eh/spec6.C
index d08bd865a9b..83f55598d58 100644
--- a/gcc/testsuite/g++.dg/eh/spec6.C
+++ b/gcc/testsuite/g++.dg/eh/spec6.C
@@ -2,7 +2,7 @@
 // for a definition, or at a call site.
 
 // { dg-do compile { target c++14_down } }
-// { dg-options "-fpermissive -w" }
+// { dg-options "-fexceptions -fpermissive -w" }
 
 struct A;			// { dg-message "" }
 
diff --git a/gcc/testsuite/g++.dg/ext/vla4.C b/gcc/testsuite/g++.dg/ext/vla4.C
index 90e4160679a..e83857f3c54 100644
--- a/gcc/testsuite/g++.dg/ext/vla4.C
+++ b/gcc/testsuite/g++.dg/ext/vla4.C
@@ -1,5 +1,5 @@
 // PR c++/29318
-// { dg-options "" }
+// { dg-options "-fexceptions" }
 
 #include <typeinfo>
 
diff --git a/gcc/testsuite/g++.dg/ipa/pr64612.C b/gcc/testsuite/g++.dg/ipa/pr64612.C
index b6fe39a3741..d23c9a48259 100644
--- a/gcc/testsuite/g++.dg/ipa/pr64612.C
+++ b/gcc/testsuite/g++.dg/ipa/pr64612.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -std=c++11" } */
+/* { dg-options "-fexceptions -O3 -std=c++11" } */
 /* { dg-final { scan-assembler "_ZN5QListI7QStringED1Ev" { target comdat_group } } } */
 
 class A
diff --git a/gcc/testsuite/g++.dg/other/error32.C b/gcc/testsuite/g++.dg/other/error32.C
index 56d3b7aec8b..aad6dfb1ce3 100644
--- a/gcc/testsuite/g++.dg/other/error32.C
+++ b/gcc/testsuite/g++.dg/other/error32.C
@@ -1,5 +1,5 @@
 // PR c++/33492
-// { dg-options "" }
+// { dg-options "-fexceptions" }
 
 void foo()
 {
diff --git a/gcc/testsuite/g++.dg/torture/dg-torture.exp b/gcc/testsuite/g++.dg/torture/dg-torture.exp
index f42a6d21a39..5901d27634a 100644
--- a/gcc/testsuite/g++.dg/torture/dg-torture.exp
+++ b/gcc/testsuite/g++.dg/torture/dg-torture.exp
@@ -1,7 +1,14 @@
 # This harness is for tests that should be run at all optimisation levels.
 
 load_lib g++-dg.exp
+#
+# Pass -fexceptions as a default flag if it's not implicitly enabled.
+set flag_exceptions ""
+if { [check_effective_target_exceptions]
+    && ![check_effective_target_exceptions_enabled_by_default] } {
+    set flag_exceptions "-fexceptions"
+}
 
 dg-init
-gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C $srcdir/c-c++-common/torture/*.c]] "" ""
+gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C $srcdir/c-c++-common/torture/*.c]] "" "$flag_exceptions"
 dg-finish
diff --git a/gcc/testsuite/g++.dg/torture/pr34850.C b/gcc/testsuite/g++.dg/torture/pr34850.C
index 60a6c6ae57d..b224844192b 100644
--- a/gcc/testsuite/g++.dg/torture/pr34850.C
+++ b/gcc/testsuite/g++.dg/torture/pr34850.C
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
 /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
-/* { dg-options "-ffat-lto-objects" } */
+/* { dg-options "-fexceptions -ffat-lto-objects" } */
 /* { dg-additional-options "-Wno-return-type" } */
 
 typedef unsigned char uint8_t;
diff --git a/gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C b/gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C
index b0da5e68abc..c8f17197ab4 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/ivopts-3.C
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-O2 -fdump-tree-ivopts-details" }
+// { dg-options "-fexceptions -O2 -fdump-tree-ivopts-details" }
 
 class MinimalVec3
 {
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr33615.C b/gcc/testsuite/g++.dg/tree-ssa/pr33615.C
index 13e20e0cd2c..47e04964103 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/pr33615.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr33615.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fnon-call-exceptions -fdump-tree-lim2-details -w" } */
+/* { dg-options "-fexceptions -O -fnon-call-exceptions -fdump-tree-lim2-details -w" } */
 
 extern volatile int y;
 
diff --git a/gcc/testsuite/g++.dg/warn/Wcatch-value-1.C b/gcc/testsuite/g++.dg/warn/Wcatch-value-1.C
index 94ee934b6ae..1ce2ec40d9e 100644
--- a/gcc/testsuite/g++.dg/warn/Wcatch-value-1.C
+++ b/gcc/testsuite/g++.dg/warn/Wcatch-value-1.C
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=1" }
+// { dg-options "-fexceptions -Wcatch-value=1" }
 
 struct A { virtual ~A() {} };
 struct B : A {};
diff --git a/gcc/testsuite/g++.dg/warn/Wcatch-value-2.C b/gcc/testsuite/g++.dg/warn/Wcatch-value-2.C
index 1bcf4056027..3894eeb2b63 100644
--- a/gcc/testsuite/g++.dg/warn/Wcatch-value-2.C
+++ b/gcc/testsuite/g++.dg/warn/Wcatch-value-2.C
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=2" }
+// { dg-options "-fexceptions -Wcatch-value=2" }
 
 struct A { virtual ~A() {} };
 struct B : A {};
diff --git a/gcc/testsuite/g++.dg/warn/Wcatch-value-3.C b/gcc/testsuite/g++.dg/warn/Wcatch-value-3.C
index 88ae698caf6..94ff4b19dd8 100644
--- a/gcc/testsuite/g++.dg/warn/Wcatch-value-3.C
+++ b/gcc/testsuite/g++.dg/warn/Wcatch-value-3.C
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=3" }
+// { dg-options "-fexceptions -Wcatch-value=3" }
 
 struct A { virtual ~A() {} };
 struct B : A {};
diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-truncation-2.C b/gcc/testsuite/g++.dg/warn/Wstringop-truncation-2.C
index ebbd44307d9..4c24d02f6e7 100644
--- a/gcc/testsuite/g++.dg/warn/Wstringop-truncation-2.C
+++ b/gcc/testsuite/g++.dg/warn/Wstringop-truncation-2.C
@@ -3,7 +3,7 @@
 // Compile with -g to verify the warning deals properly with debug
 // statements.
 // { dg-do compile }
-// { dg-options "-O2 -Wstringop-truncation -g" }
+// { dg-options "-fexceptions -O2 -Wstringop-truncation -g" }
 
 extern "C" char* strncpy (char*, const char*, __SIZE_TYPE__);
 
diff --git a/gcc/testsuite/g++.dg/warn/Wterminate1.C b/gcc/testsuite/g++.dg/warn/Wterminate1.C
index affb48d3e8a..a611074301a 100644
--- a/gcc/testsuite/g++.dg/warn/Wterminate1.C
+++ b/gcc/testsuite/g++.dg/warn/Wterminate1.C
@@ -1,7 +1,7 @@
 // In C++98 mode this gets a -Wc++11-compat warning, in C++11 mode a
 // -Wterminate warning.
 
-// { dg-options "-Wall" }
+// { dg-options "-fexceptions -Wall" }
 
 struct A
 {
diff --git a/gcc/testsuite/g++.dg/warn/pr83054.C b/gcc/testsuite/g++.dg/warn/pr83054.C
index 506c9609b90..9a976da5386 100644
--- a/gcc/testsuite/g++.dg/warn/pr83054.C
+++ b/gcc/testsuite/g++.dg/warn/pr83054.C
@@ -1,5 +1,5 @@
 // PR ipa/83054
-// { dg-options "-O3 -Wsuggest-final-types" }
+// { dg-options "-fexceptions -O3 -Wsuggest-final-types" }
 // { dg-do compile }
 
 extern "C" int printf (const char *, ...);
diff --git a/gcc/testsuite/g++.old-deja/g++.other/cond5.C b/gcc/testsuite/g++.old-deja/g++.other/cond5.C
index 0d2baf9edf7..56e21b6aec2 100644
--- a/gcc/testsuite/g++.old-deja/g++.other/cond5.C
+++ b/gcc/testsuite/g++.old-deja/g++.other/cond5.C
@@ -1,5 +1,5 @@
 // { dg-do assemble  }
-// { dg-options "-W -pedantic -ansi" }
+// { dg-options "-fexceptions -W -pedantic -ansi" }
 
 // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 1 Sep 1999 <nathan@acm.org>
diff --git a/gcc/testsuite/g++.old-deja/old-deja.exp b/gcc/testsuite/g++.old-deja/old-deja.exp
index b214c1be5a1..d85f2ca9152 100644
--- a/gcc/testsuite/g++.old-deja/old-deja.exp
+++ b/gcc/testsuite/g++.old-deja/old-deja.exp
@@ -30,8 +30,15 @@ dg-init
 # that are handled specially.
 set tests [lsort [find $srcdir/$subdir *.C]]
 
+# Pass -fexceptions as a default flag if it's not implicitly enabled.
+set flag_exceptions ""
+if { [check_effective_target_exceptions]
+    && ![check_effective_target_exceptions_enabled_by_default] } {
+    set flag_exceptions "-fexceptions"
+}
+
 # Main loop.
-g++-dg-runtest $tests "" $DEFAULT_CXXFLAGS
+g++-dg-runtest $tests "" "$DEFAULT_CXXFLAGS $flag_exceptions"
 
 # All done.
 dg-finish
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/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 6f224fa8141..6c836a4accc 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8888,10 +8888,28 @@ proc check_effective_target_fenv_exceptions {} {
 # Return 1 if -fexceptions is supported.
 
 proc check_effective_target_exceptions {} {
-    if { [istarget amdgcn*-*-*] } {
+    return [check_cached_effective_target exceptions {
+	if { [istarget amdgcn*-*-*]
+	     || [check_configured_with "--disable-exceptions"] } {
+	    return 0
+	}
+	return 1
+    }]
+}
+
+proc check_effective_target_exceptions_enabled_by_default {} {
+    return [check_cached_effective_target exceptions_enabled_by_default {
+	if { [check_effective_target_exceptions] } {
+	    return [check_no_compiler_messages exceptions_enabled_by_default assembly {
+		void foo (void)
+		{
+		    throw 1;
+		}
+	    }]
+	}
+	# If exceptions aren't supported they're not enabled by default.
 	return 0
-    }
-    return 1
+    }]
 }
 
 
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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 3/4] MSP430: Disable __cxa_atexit
  2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
  2019-11-07 21:34 ` [PATCH 1/4] MSP430: Disable TM clone registry by default Jozef Lawrynowicz
  2019-11-07 21:37 ` [PATCH 2/4] MSP430: Disable exception handling by default for C++ Jozef Lawrynowicz
@ 2019-11-07 21:39 ` Jozef Lawrynowicz
  2019-11-07 21:41 ` [PATCH 4/4] MSP430: Deprecate -minrt option Jozef Lawrynowicz
  2019-11-08 12:14 ` [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Oleg Endo
  4 siblings, 0 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-07 21:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 470 bytes --]

The MSP430 target does not need to support dynamic shared objects so
__cxa_atexit does not need to be used - atexit is sufficient.

Newlib atexit is a fine replacement as it also supports registration of more
than 32 functions.

By not using __cxa_atexit, we can define TARGET_LIBGCC_REMOVE_DSO_HANDLE to
remove the definition of __dso_handle from crtstuff.c, saving code size by
removing the necessity to link in functions to initialize global data in
*every* program.

[-- Attachment #2: 0003-MSP430-Disable-__cxa_atexit.patch --]
[-- Type: text/x-patch, Size: 5199 bytes --]

From a0086b73d0e029c8888ab2f65a91e67a2502e4d4 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Wed, 30 Oct 2019 16:39:52 +0000
Subject: [PATCH 3/4] MSP430: Disable __cxa_atexit

gcc/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config.gcc (msp430*-*-*): Disable __cxa_atexit by default.
	* config/msp430/msp430.c (msp430_option_override): Emit an error if
	-fuse-cxa-atexit was used when __cxa_atexit was disabled at configure
	time.
	* config/msp430/msp430.h (TARGET_LIBGCC_REMOVE_DSO_HANDLE): Define if
	__cxa_atexit was disabled at configure time.
	
gcc/testsuite/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* g++.dg/init/dso_handle1.C: Add dg-require-cxa-atexit. 
	* g++.dg/init/dso_handle2.C: Likewise.
	* g++.dg/other/cxa-atexit1.C: Likewise.
	* lib/target-supports.exp (check_cxa_atexit_available): Add hard-coded
	case for msp430.

---
 gcc/config.gcc                           | 7 +++++++
 gcc/config/msp430/msp430.c               | 9 +++++++++
 gcc/config/msp430/msp430.h               | 6 ++++++
 gcc/testsuite/g++.dg/init/dso_handle1.C  | 1 +
 gcc/testsuite/g++.dg/init/dso_handle2.C  | 1 +
 gcc/testsuite/g++.dg/other/cxa-atexit1.C | 1 +
 gcc/testsuite/lib/target-supports.exp    | 3 +++
 7 files changed, 28 insertions(+)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index d74bcbb9856..2e79101cc8f 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2533,6 +2533,13 @@ msp430*-*-*)
 	tmake_file="${tmake_file} msp430/t-msp430"
 	extra_objs="${extra_objs} msp430-devices.o"
 	extra_gcc_objs="driver-msp430.o msp430-devices.o"
+
+	# __cxa_atexit increases code size, and we don't need to support dynamic
+	# shared objects on MSP430, so regular Newlib atexit is a fine
+	# replacement as it also supports registration of more than 32
+	# functions.
+	default_use_cxa_atexit=no
+
 	# Enable .init_array unless it has been explicitly disabled.
 	# The MSP430 EABI mandates the use of .init_array, and the Newlib CRT
 	# code since mid-2019 expects it.
diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index fe1fcc0db43..ce8d863abd3 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -284,6 +284,15 @@ msp430_option_override (void)
      possible to build newlib with -Os enabled.  Until now...  */
   if (TARGET_OPT_SPACE && optimize < 3)
     optimize_size = 1;
+
+#if !DEFAULT_USE_CXA_ATEXIT
+  /* By default, we enforce atexit() instead of __cxa_atexit() to save on code
+     size and remove the declaration of __dso_handle from the CRT library.
+     Configuring GCC with --enable-__cxa-atexit re-enables it by defining
+     DEFAULT_USE_CXA_ATEXIT to 1.  */
+  if (flag_use_cxa_atexit)
+    error ("%<-fuse-cxa-atexit%> is not supported for msp430-elf");
+#endif
 }
 
 #undef  TARGET_SCALAR_MODE_SUPPORTED_P
diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h
index 90ceec0e947..25944125182 100644
--- a/gcc/config/msp430/msp430.h
+++ b/gcc/config/msp430/msp430.h
@@ -509,4 +509,10 @@ typedef struct
 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN)	\
   msp430_output_aligned_decl_common ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
 
+#if !DEFAULT_USE_CXA_ATEXIT
+/* We're not using __cxa_atexit, so __dso_handle isn't needed.  */
+#undef TARGET_LIBGCC_REMOVE_DSO_HANDLE
+#define TARGET_LIBGCC_REMOVE_DSO_HANDLE
+#endif
+
 #define SYMBOL_FLAG_LOW_MEM (SYMBOL_FLAG_MACH_DEP << 0)
diff --git a/gcc/testsuite/g++.dg/init/dso_handle1.C b/gcc/testsuite/g++.dg/init/dso_handle1.C
index 97f67cad8f4..dc92e22d12a 100644
--- a/gcc/testsuite/g++.dg/init/dso_handle1.C
+++ b/gcc/testsuite/g++.dg/init/dso_handle1.C
@@ -1,6 +1,7 @@
 // PR c++/17042
 // { dg-do assemble }
 /* { dg-require-weak "" } */
+// { dg-require-cxa-atexit "" }
 // { dg-options "-fuse-cxa-atexit" }
 
 struct A
diff --git a/gcc/testsuite/g++.dg/init/dso_handle2.C b/gcc/testsuite/g++.dg/init/dso_handle2.C
index b219dc02611..6e151e50fa7 100644
--- a/gcc/testsuite/g++.dg/init/dso_handle2.C
+++ b/gcc/testsuite/g++.dg/init/dso_handle2.C
@@ -1,4 +1,5 @@
 // PR c++/58846
+// { dg-require-cxa-atexit "" }
 // { dg-options "-fuse-cxa-atexit" }
 
 extern "C" { char* __dso_handle; }
diff --git a/gcc/testsuite/g++.dg/other/cxa-atexit1.C b/gcc/testsuite/g++.dg/other/cxa-atexit1.C
index a51f3340142..d6ab3dc4733 100644
--- a/gcc/testsuite/g++.dg/other/cxa-atexit1.C
+++ b/gcc/testsuite/g++.dg/other/cxa-atexit1.C
@@ -1,4 +1,5 @@
 // { dg-do compile }
+// { dg-require-cxa-atexit "" }
 // { dg-options "-O2 -fuse-cxa-atexit" }
 
 # 1 "cxa-atexit1.C"
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 6c836a4accc..58bedb64d42 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2513,6 +2513,9 @@ proc check_cxa_atexit_available { } {
 	} elseif { [istarget *-*-vxworks] } {
 	    # vxworks doesn't have __cxa_atexit but subsequent test passes.
 	    expr 0
+	} elseif { [istarget msp430-*-*] } {
+	    # msp430 doesn't have __cxa_atexit but subsequent test passes.
+	    expr 0
 	} else {
 	    check_runtime_nocache cxa_atexit_available {
 		// C++
-- 
2.17.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/4] MSP430: Deprecate -minrt option
  2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
                   ` (2 preceding siblings ...)
  2019-11-07 21:39 ` [PATCH 3/4] MSP430: Disable __cxa_atexit Jozef Lawrynowicz
@ 2019-11-07 21:41 ` Jozef Lawrynowicz
  2019-11-17 21:02   ` Jeff Law
  2019-11-08 12:14 ` [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Oleg Endo
  4 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-07 21:41 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1465 bytes --]

Support for the MSP430 -minrt option has been removed from Newlib, since all the
associated behaviour is now dynamic. Initialization code run before main is only
included when needed.

This patch removes the final traces of -minrt from GCC.

-minrt used to modify the linking process in the following ways:
* Removing .init and .fini sections, by using a reduced crt0 and excluding crtn.
* Removing crtbegin and crtend (thereby not using crtstuff.c at all).
  + This meant that even if the program had constructors for global or
    static objects which must run before main, it would blindly remove them.

These causes of code bloat have been addressed by:
* switching to .{init,fini}_array instead of using .{init,fini} sections
  "Lean" code to run through constructors before main is only included if
  .init_array has contents.
* removing bloat (frame_dummy, *tm_clones*, *do_global_dtors*) from the
  crtstuff.c with the changes in the previous patches

Here are some examples of the total size of different "barebones" C programs to
show that the size previously achieved by -minrt is now matched by default:

program                 |old (with -minrt)      |new (without -minrt)
---------------------------------------------------------------------
Empty main              |20                     |20
Looping main            |14                     |14
Looping main with data  |94                     |94
Looping main with bss   |56                     |56

[-- Attachment #2: 0004-MSP430-Remove-minrt-option.patch --]
[-- Type: text/x-patch, Size: 3294 bytes --]

From 6e561b45c118540f06d5828ec386d2dd79c13b62 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Wed, 6 Nov 2019 18:12:45 +0000
Subject: [PATCH 4/4] MSP430: Remove -minrt option

gcc/ChangeLog:

2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config/msp430/msp430.h (STARTFILE_SPEC): Remove -minrt rules.
	Use "if, then, else" syntax for specs.
	(ENDFILE_SPEC): Likewise.
	* config/msp430/msp430.opt: Mark -minrt as deprecated.
	* doc/invoke.texi: Remove -minrt documentation.
---
 gcc/config/msp430/msp430.h   | 9 ++++-----
 gcc/config/msp430/msp430.opt | 4 ++--
 gcc/doc/invoke.texi          | 9 +--------
 3 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h
index 25944125182..3f013a9d315 100644
--- a/gcc/config/msp430/msp430.h
+++ b/gcc/config/msp430/msp430.h
@@ -45,15 +45,14 @@ extern bool msp430x;
   while (0)
 
 #undef  STARTFILE_SPEC
-#define STARTFILE_SPEC "%{pg:gcrt0.o%s}" \
-  "%{!pg:%{minrt:crt0-minrt.o%s}%{!minrt:crt0.o%s}} " \
-  "%{!minrt:%{fexceptions:crtbegin.o%s}%{!fexceptions:crtbegin_no_eh.o%s}}"
+#define STARTFILE_SPEC "%{pg:gcrt0.o%s; :crt0.o%s} " \
+  "%{fexceptions:crtbegin.o%s; :crtbegin_no_eh.o%s}"
 
 /* -lgcc is included because crtend.o needs __mspabi_func_epilog_1.  */
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{!minrt:%{fexceptions:crtend.o%s}%{!fexceptions:crtend_no_eh.o%s}} "  \
-  "%{minrt:%:if-exists(crtn-minrt.o%s)}%{!minrt:%:if-exists(crtn.o%s)} -lgcc"
+  "%{fexceptions:crtend.o%s; :crtend_no_eh.o%s} "  \
+  "%:if-exists(crtn.o%s) -lgcc"
 
 #define ASM_SPEC "-mP " /* Enable polymorphic instructions.  */ \
   "%{mcpu=*:-mcpu=%*} " /* Pass the CPU type on to the assembler.  */ \
diff --git a/gcc/config/msp430/msp430.opt b/gcc/config/msp430/msp430.opt
index 2db2906ca11..74fdcdf0851 100644
--- a/gcc/config/msp430/msp430.opt
+++ b/gcc/config/msp430/msp430.opt
@@ -38,8 +38,8 @@ mOs
 Target Undocumented Mask(OPT_SPACE)
 
 minrt
-Target Report Mask(MINRT) RejectNegative
-Use a minimum runtime (no static initializers or ctors) for memory-constrained devices.
+Target Undocumented WarnRemoved
+This option is deprecated in GCC10 and has no effect.
 
 HeaderInclude
 config/msp430/msp430-opts.h
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 6829b949b4b..12a360ed6a7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1009,7 +1009,7 @@ Objective-C and Objective-C++ Dialects}.
 -mwarn-mcu @gol
 -mcode-region=  -mdata-region= @gol
 -msilicon-errata=  -msilicon-errata-warn= @gol
--mhwmult=  -minrt}
+-mhwmult=}
 
 @emph{NDS32 Options}
 @gccoptlist{-mbig-endian  -mlittle-endian @gol
@@ -23262,13 +23262,6 @@ The hardware multiply routines disable interrupts whilst running and
 restore the previous interrupt state when they finish.  This makes
 them safe to use inside interrupt handlers as well as in normal code.
 
-@item -minrt
-@opindex minrt
-Enable the use of a minimum runtime environment - no static
-initializers or constructors.  This is intended for memory-constrained
-devices.  The compiler includes special symbols in some objects
-that tell the linker and runtime which code fragments are required.
-
 @item -mcode-region=
 @itemx -mdata-region=
 @opindex mcode-region
-- 
2.17.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] MSP430: Disable exception handling by default for C++
  2019-11-07 21:37 ` [PATCH 2/4] MSP430: Disable exception handling by default for C++ Jozef Lawrynowicz
@ 2019-11-08  0:07   ` Oleg Endo
  2019-11-08 13:26     ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Oleg Endo @ 2019-11-08  0:07 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size
  2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
                   ` (3 preceding siblings ...)
  2019-11-07 21:41 ` [PATCH 4/4] MSP430: Deprecate -minrt option Jozef Lawrynowicz
@ 2019-11-08 12:14 ` Oleg Endo
  2019-11-08 13:27   ` Jozef Lawrynowicz
  4 siblings, 1 reply; 19+ messages in thread
From: Oleg Endo @ 2019-11-08 12:14 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

On Thu, 2019-11-07 at 21:31 +0000, Jozef Lawrynowicz wrote:
> When building small programs for MSP430, the impact of the unused
> functions pulled in from the CRT libraries is quite noticeable. Most of these
> relates to feature that will never be used for MSP430 (Transactional memory,
> supporting shared objects and dynamic linking), or rarely used (exception
> handling).

There's a magic switch, which does the business, at least for me, most
of the time:

       -flto

If you're trying to bring down the executable size as much as possible,
but don't use -flto, I think something is wrong.

Cheers,
Oleg

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] MSP430: Disable exception handling by default for C++
  2019-11-08  0:07   ` Oleg Endo
@ 2019-11-08 13:26     ` Jozef Lawrynowicz
  2019-11-12 21:13       ` Richard Sandiford
  0 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-08 13:26 UTC (permalink / raw)
  To: Oleg Endo

[-- Attachment #1: Type: text/plain, Size: 1928 bytes --]

On Fri, 08 Nov 2019 09:07:39 +0900
Oleg Endo <oleg.endo@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

[-- Attachment #2: 0002-MSP430-Add-fno-exceptions-multilib.patch --]
[-- Type: text/x-patch, Size: 6295 bytes --]

From fe67a5ff71bc48af05b086b2d495fbf77e1a070d Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@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  <jozef.l@mittosystems.com>

	* config-ml.in: Support --disable-no-exceptions configure flag.

gcc/ChangeLog:

2019-11-08  Jozef Lawrynowicz  <jozef.l@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  <jozef.l@mittosystems.com>

	* lib/gcc-dg.exp: Add dg-prune messages for when exception handling is
	disabled.

libgcc/ChangeLog:

2019-11-08  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    |  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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size
  2019-11-08 12:14 ` [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Oleg Endo
@ 2019-11-08 13:27   ` Jozef Lawrynowicz
  2019-11-08 13:59     ` Oleg Endo
  0 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-08 13:27 UTC (permalink / raw)
  To: Oleg Endo

On Fri, 08 Nov 2019 21:14:19 +0900
Oleg Endo <oleg.endo@t-online.de> wrote:

> On Thu, 2019-11-07 at 21:31 +0000, Jozef Lawrynowicz wrote:
> > When building small programs for MSP430, the impact of the unused
> > functions pulled in from the CRT libraries is quite noticeable. Most of these
> > relates to feature that will never be used for MSP430 (Transactional memory,
> > supporting shared objects and dynamic linking), or rarely used (exception
> > handling).  
> 
> There's a magic switch, which does the business, at least for me, most
> of the time:
> 
>        -flto
> 
> If you're trying to bring down the executable size as much as possible,
> but don't use -flto, I think something is wrong.
> 
> Cheers,
> Oleg
> 

Yes, I should have used -flto in my examples. But it doesn't help remove these
CRT library functions which are normally either directly added to the
list of functions to run before main (via .init, .ctors or .init_array) or used
in functions which are themselves added to this list.

The unnecessary functions we want to remove are:
  deregister_tm_clones
  register_tm_clones
  __do_global_dtors_aux
  frame_dummy
LTO can't remove any of them.

Thanks,
Jozef

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size
  2019-11-08 13:27   ` Jozef Lawrynowicz
@ 2019-11-08 13:59     ` Oleg Endo
  2019-11-08 14:32       ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Oleg Endo @ 2019-11-08 13:59 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: gcc-patches

On Fri, 2019-11-08 at 13:27 +0000, Jozef Lawrynowicz wrote:
> 
> Yes, I should have used -flto in my examples. But it doesn't help remove these
> CRT library functions which are normally either directly added to the
> list of functions to run before main (via .init, .ctors or .init_array) or used
> in functions which are themselves added to this list.
> 
> The unnecessary functions we want to remove are:
>   deregister_tm_clones
>   register_tm_clones
>   __do_global_dtors_aux
>   frame_dummy
> LTO can't remove any of them.
> 

Ah, right, good point.  That's not MSP430 specific actually.  For those
things I usually have custom init code, which also does other things
occasionally.  Stripping off global dtors is then an option in the
build system which takes care of it (in my case, I do it by modifying
the generated linker script).

But again, as with the exceptions, it might be better to implement
these kind of things outside of the compiler, e.g. by building the app
with -nostartfiles -nodefaultlibs and providing your own substitutes.

Another option is to patch those things in using the OS part of the
target triplet.

Cheers,
Oleg

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size
  2019-11-08 13:59     ` Oleg Endo
@ 2019-11-08 14:32       ` Jozef Lawrynowicz
  0 siblings, 0 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-08 14:32 UTC (permalink / raw)
  To: Oleg Endo; +Cc: gcc-patches

On Fri, 08 Nov 2019 22:59:18 +0900
Oleg Endo <oleg.endo@t-online.de> wrote:

> On Fri, 2019-11-08 at 13:27 +0000, Jozef Lawrynowicz wrote:
> > 
> > Yes, I should have used -flto in my examples. But it doesn't help remove these
> > CRT library functions which are normally either directly added to the
> > list of functions to run before main (via .init, .ctors or .init_array) or used
> > in functions which are themselves added to this list.
> > 
> > The unnecessary functions we want to remove are:
> >   deregister_tm_clones
> >   register_tm_clones
> >   __do_global_dtors_aux
> >   frame_dummy
> > LTO can't remove any of them.
> >   
> 
> Ah, right, good point.  That's not MSP430 specific actually.  For those
> things I usually have custom init code, which also does other things
> occasionally.  Stripping off global dtors is then an option in the
> build system which takes care of it (in my case, I do it by modifying
> the generated linker script).
> 
> But again, as with the exceptions, it might be better to implement
> these kind of things outside of the compiler, e.g. by building the app
> with -nostartfiles -nodefaultlibs and providing your own substitutes.

I just don't think we need to be putting up this high barrier to entry for users
who want reduced code size but are building GCC from source.

With these changes users are getting a highly size-optimized runtime library
(14 bytes for a program that gets you to main() is always nice to see) out of
the box, by simply removing features that do not make sense on the target, and
they don't have to faff with any extra options.

The size of the CRT code has been a long standing complaint and is some part of
the reason a large chunk of the MSP430 user base still uses "mspgcc" which is
the old downstream GCC port of the target, which hasn't has any development
since 2012.

> 
> Another option is to patch those things in using the OS part of the
> target triplet.

Interesting idea. Something like msp430-unknown-min(imum)? The thing is even
with these changes the target is still ELF compliant.

Although I guess supplying a configuration which disables exceptions is not
very ELF-y.

Thanks,
Jozef
> 
> Cheers,
> Oleg
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] MSP430: Disable exception handling by default for C++
  2019-11-08 13:26     ` Jozef Lawrynowicz
@ 2019-11-12 21:13       ` Richard Sandiford
  2019-11-27 13:51         ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Richard Sandiford @ 2019-11-12 21:13 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: Oleg Endo, 

Jozef Lawrynowicz <jozef.l@mittosystems.com> writes:
> 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"
> +    }

This is probably safe, but...

> +
> +    if [regexp "(^|\n)\[^\n\]*: error: #error .__cpp_exceptions." $text] {
> +	return "::unsupported::exception handling disabled"
> +    }

...it looks like this would disable g++.dg/cpp1y/feat-neg.C for all
targets.  I assume this was motivated by g++.dg/cpp2a/feat-cxx2a.C,
but the kind of effective-target tests you had in the original patch
are probably better there.  It might then be more robust to test that
[check_effective_target_...] for the "exception handling disabled" case
above as well, so that other targets aren't affected accidentally.

It'd be good to test a target/multilib that has exceptions enabled by
default to make sure there's no change in the number of unsupported
tests (rather than just no new fails).

Thanks,
Richard

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] MSP430: Disable TM clone registry by default
  2019-11-07 21:34 ` [PATCH 1/4] MSP430: Disable TM clone registry by default Jozef Lawrynowicz
@ 2019-11-17 19:32   ` Jeff Law
  2019-11-24 14:22     ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Jeff Law @ 2019-11-17 19:32 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

On 11/7/19 2:34 PM, Jozef Lawrynowicz wrote:
> Given that MSP430 is a resource constrained, embedded target disabling
> transactional memory by default is a good idea to save on code size in
> the runtime library.
> 
> It can still be enabled by passing --enable-tm-clone-registry (although as far
> as I understand the feature is fundamentally incompatible with MSP430 given
> reliance on libitm, lack of thread support without an OS and the memory
> limitations of the device.
> 
I'm not a huge fan of making the default configurations behave
differently.  But I can also see how something like TM in particular
isn't of much interest in the embedded space (hell, it's having trouble
getting real traction in the server space as well).

May be a reasonable path forward is to add the configury bits, keep TM
on by default and create a different msp target which disables this stuff?

Jeff

ps.  I thought libitm would fallback to a full software solution and the
hardware requirements were really just enabling fast-paths.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] MSP430: Deprecate -minrt option
  2019-11-07 21:41 ` [PATCH 4/4] MSP430: Deprecate -minrt option Jozef Lawrynowicz
@ 2019-11-17 21:02   ` Jeff Law
  2019-11-24 16:38     ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Jeff Law @ 2019-11-17 21:02 UTC (permalink / raw)
  To: Jozef Lawrynowicz, gcc-patches

On 11/7/19 2:41 PM, Jozef Lawrynowicz wrote:
> Support for the MSP430 -minrt option has been removed from Newlib, since all the
> associated behaviour is now dynamic. Initialization code run before main is only
> included when needed.
> 
> This patch removes the final traces of -minrt from GCC.
> 
> -minrt used to modify the linking process in the following ways:
> * Removing .init and .fini sections, by using a reduced crt0 and excluding crtn.
> * Removing crtbegin and crtend (thereby not using crtstuff.c at all).
>   + This meant that even if the program had constructors for global or
>     static objects which must run before main, it would blindly remove them.
> 
> These causes of code bloat have been addressed by:
> * switching to .{init,fini}_array instead of using .{init,fini} sections
>   "Lean" code to run through constructors before main is only included if
>   .init_array has contents.
> * removing bloat (frame_dummy, *tm_clones*, *do_global_dtors*) from the
>   crtstuff.c with the changes in the previous patches
> 
> Here are some examples of the total size of different "barebones" C programs to
> show that the size previously achieved by -minrt is now matched by default:
> 
> program                 |old (with -minrt)      |new (without -minrt)
> ---------------------------------------------------------------------
> Empty main              |20                     |20
> Looping main            |14                     |14
> Looping main with data  |94                     |94
> Looping main with bss   |56                     |56
> 
> 
> 0004-MSP430-Remove-minrt-option.patch
> 
> From 6e561b45c118540f06d5828ec386d2dd79c13b62 Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> Date: Wed, 6 Nov 2019 18:12:45 +0000
> Subject: [PATCH 4/4] MSP430: Remove -minrt option
> 
> gcc/ChangeLog:
> 
> 2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> 
> 	* config/msp430/msp430.h (STARTFILE_SPEC): Remove -minrt rules.
> 	Use "if, then, else" syntax for specs.
> 	(ENDFILE_SPEC): Likewise.
> 	* config/msp430/msp430.opt: Mark -minrt as deprecated.
> 	* doc/invoke.texi: Remove -minrt documentation.
This is fine.  I leave the decision whether or not to install now or
wait for resolution on the other changes in this space as your decision.

jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] MSP430: Disable TM clone registry by default
  2019-11-17 19:32   ` Jeff Law
@ 2019-11-24 14:22     ` Jozef Lawrynowicz
  2019-11-24 17:24       ` Jeff Law
  0 siblings, 1 reply; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-24 14:22 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches

On Sun, 17 Nov 2019 12:11:23 -0700
Jeff Law <law@redhat.com> wrote:

> On 11/7/19 2:34 PM, Jozef Lawrynowicz wrote:
> > Given that MSP430 is a resource constrained, embedded target disabling
> > transactional memory by default is a good idea to save on code size in
> > the runtime library.
> > 
> > It can still be enabled by passing --enable-tm-clone-registry (although as far
> > as I understand the feature is fundamentally incompatible with MSP430 given
> > reliance on libitm, lack of thread support without an OS and the memory
> > limitations of the device.
> >   
> I'm not a huge fan of making the default configurations behave
> differently.  But I can also see how something like TM in particular
> isn't of much interest in the embedded space (hell, it's having trouble
> getting real traction in the server space as well).
> 
> May be a reasonable path forward is to add the configury bits, keep TM
> on by default and create a different msp target which disables this stuff?

Ok fair enough, what would an acceptable form for a new target triplet look
like? "msp430-*-elfbare"?

Since we're into stage 3 now I'll look at doing this for GCC 11.

Thanks,
Jozef

> 
> Jeff
> 
> ps.  I thought libitm would fallback to a full software solution and the
> hardware requirements were really just enabling fast-paths.
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4] MSP430: Deprecate -minrt option
  2019-11-17 21:02   ` Jeff Law
@ 2019-11-24 16:38     ` Jozef Lawrynowicz
  0 siblings, 0 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-24 16:38 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches

On Sun, 17 Nov 2019 14:00:58 -0700
Jeff Law <law@redhat.com> wrote:

> On 11/7/19 2:41 PM, Jozef Lawrynowicz wrote:
> > Support for the MSP430 -minrt option has been removed from Newlib, since all the
> > associated behaviour is now dynamic. Initialization code run before main is only
> > included when needed.
> > 
> > This patch removes the final traces of -minrt from GCC.
> > 
> > -minrt used to modify the linking process in the following ways:
> > * Removing .init and .fini sections, by using a reduced crt0 and excluding crtn.
> > * Removing crtbegin and crtend (thereby not using crtstuff.c at all).
> >   + This meant that even if the program had constructors for global or
> >     static objects which must run before main, it would blindly remove them.
> > 
> > These causes of code bloat have been addressed by:
> > * switching to .{init,fini}_array instead of using .{init,fini} sections
> >   "Lean" code to run through constructors before main is only included if
> >   .init_array has contents.
> > * removing bloat (frame_dummy, *tm_clones*, *do_global_dtors*) from the
> >   crtstuff.c with the changes in the previous patches
> > 
> > Here are some examples of the total size of different "barebones" C programs to
> > show that the size previously achieved by -minrt is now matched by default:
> > 
> > program                 |old (with -minrt)      |new (without -minrt)
> > ---------------------------------------------------------------------
> > Empty main              |20                     |20
> > Looping main            |14                     |14
> > Looping main with data  |94                     |94
> > Looping main with bss   |56                     |56
> > 
> > 
> > 0004-MSP430-Remove-minrt-option.patch
> > 
> > From 6e561b45c118540f06d5828ec386d2dd79c13b62 Mon Sep 17 00:00:00 2001
> > From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> > Date: Wed, 6 Nov 2019 18:12:45 +0000
> > Subject: [PATCH 4/4] MSP430: Remove -minrt option
> > 
> > gcc/ChangeLog:
> > 
> > 2019-11-07  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
> > 
> > 	* config/msp430/msp430.h (STARTFILE_SPEC): Remove -minrt rules.
> > 	Use "if, then, else" syntax for specs.
> > 	(ENDFILE_SPEC): Likewise.
> > 	* config/msp430/msp430.opt: Mark -minrt as deprecated.
> > 	* doc/invoke.texi: Remove -minrt documentation.  
> This is fine.  I leave the decision whether or not to install now or
> wait for resolution on the other changes in this space as your decision.

Unfortunately without the other changes installed by default this option is
still required if users want the bare minimum code size.

Jozef
> 
> jeff
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] MSP430: Disable TM clone registry by default
  2019-11-24 14:22     ` Jozef Lawrynowicz
@ 2019-11-24 17:24       ` Jeff Law
  2019-11-24 17:55         ` Jozef Lawrynowicz
  0 siblings, 1 reply; 19+ messages in thread
From: Jeff Law @ 2019-11-24 17:24 UTC (permalink / raw)
  To: Jozef Lawrynowicz; +Cc: gcc-patches

On 11/24/19 7:20 AM, Jozef Lawrynowicz wrote:
> On Sun, 17 Nov 2019 12:11:23 -0700
> Jeff Law <law@redhat.com> wrote:
> 
>> On 11/7/19 2:34 PM, Jozef Lawrynowicz wrote:
>>> Given that MSP430 is a resource constrained, embedded target disabling
>>> transactional memory by default is a good idea to save on code size in
>>> the runtime library.
>>>
>>> It can still be enabled by passing --enable-tm-clone-registry (although as far
>>> as I understand the feature is fundamentally incompatible with MSP430 given
>>> reliance on libitm, lack of thread support without an OS and the memory
>>> limitations of the device.
>>>   
>> I'm not a huge fan of making the default configurations behave
>> differently.  But I can also see how something like TM in particular
>> isn't of much interest in the embedded space (hell, it's having trouble
>> getting real traction in the server space as well).
>>
>> May be a reasonable path forward is to add the configury bits, keep TM
>> on by default and create a different msp target which disables this stuff?
> 
> Ok fair enough, what would an acceptable form for a new target triplet look
> like? "msp430-*-elfbare"?
Yea, that seems reasonable.

> 
> Since we're into stage 3 now I'll look at doing this for GCC 11.
I'd seriously consider letting this into gcc-10.  It's going to be well
isolated and it's an iteration of something you posted before the
stage1->stage3 transition.  Your choice if you want to try and pull it
together quickly for gcc-10.

Jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] MSP430: Disable TM clone registry by default
  2019-11-24 17:24       ` Jeff Law
@ 2019-11-24 17:55         ` Jozef Lawrynowicz
  0 siblings, 0 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-24 17:55 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches

On Sun, 24 Nov 2019 10:10:51 -0700
Jeff Law <law@redhat.com> wrote:

> On 11/24/19 7:20 AM, Jozef Lawrynowicz wrote:
> > On Sun, 17 Nov 2019 12:11:23 -0700
> > Jeff Law <law@redhat.com> wrote:
> >   
> >> On 11/7/19 2:34 PM, Jozef Lawrynowicz wrote:  
> >>> Given that MSP430 is a resource constrained, embedded target disabling
> >>> transactional memory by default is a good idea to save on code size in
> >>> the runtime library.
> >>>
> >>> It can still be enabled by passing --enable-tm-clone-registry (although as far
> >>> as I understand the feature is fundamentally incompatible with MSP430 given
> >>> reliance on libitm, lack of thread support without an OS and the memory
> >>> limitations of the device.
> >>>     
> >> I'm not a huge fan of making the default configurations behave
> >> differently.  But I can also see how something like TM in particular
> >> isn't of much interest in the embedded space (hell, it's having trouble
> >> getting real traction in the server space as well).
> >>
> >> May be a reasonable path forward is to add the configury bits, keep TM
> >> on by default and create a different msp target which disables this stuff?  
> > 
> > Ok fair enough, what would an acceptable form for a new target triplet look
> > like? "msp430-*-elfbare"?  
> Yea, that seems reasonable.
> 
> > 
> > Since we're into stage 3 now I'll look at doing this for GCC 11.  
> I'd seriously consider letting this into gcc-10.  It's going to be well
> isolated and it's an iteration of something you posted before the
> stage1->stage3 transition.  Your choice if you want to try and pull it
> together quickly for gcc-10.

Ok great, I will aim to get something together ASAP.

Thanks,
Jozef
> 
> Jeff
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] MSP430: Disable exception handling by default for C++
  2019-11-12 21:13       ` Richard Sandiford
@ 2019-11-27 13:51         ` Jozef Lawrynowicz
  0 siblings, 0 replies; 19+ messages in thread
From: Jozef Lawrynowicz @ 2019-11-27 13:51 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: Oleg Endo, 

On Tue, 12 Nov 2019 21:08:48 +0000
Richard Sandiford <richard.sandiford@arm.com> wrote:

> Jozef Lawrynowicz <jozef.l@mittosystems.com> writes:
> > 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"
> > +    }  
> 
> This is probably safe, but...
> 
> > +
> > +    if [regexp "(^|\n)\[^\n\]*: error: #error .__cpp_exceptions." $text] {
> > +	return "::unsupported::exception handling disabled"
> > +    }  
> 
> ...it looks like this would disable g++.dg/cpp1y/feat-neg.C for all
> targets.  I assume this was motivated by g++.dg/cpp2a/feat-cxx2a.C,
> but the kind of effective-target tests you had in the original patch
> are probably better there.  It might then be more robust to test that
> [check_effective_target_...] for the "exception handling disabled" case
> above as well, so that other targets aren't affected accidentally.
> 
> It'd be good to test a target/multilib that has exceptions enabled by
> default to make sure there's no change in the number of unsupported
> tests (rather than just no new fails).

Apologies for the delayed response.

The messages caught in gcc-dg-prune will only be pruned if they haven't already
been caught by dg-warning/error/etc. So basically only if the regex being tested
would trigger an "excess errors" failure.

As a result, there was no change in passes/fails/unsupported on
x86_64-pc-linux-gnu.

Checking if exceptions are actually disabled before enabling those prunes is a
nice suggestion though, I'll add it to the revised patch.

Thanks,
Jozef

> 
> Thanks,
> Richard

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-11-27 13:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 21:31 [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Jozef Lawrynowicz
2019-11-07 21:34 ` [PATCH 1/4] MSP430: Disable TM clone registry by default Jozef Lawrynowicz
2019-11-17 19:32   ` Jeff Law
2019-11-24 14:22     ` Jozef Lawrynowicz
2019-11-24 17:24       ` Jeff Law
2019-11-24 17:55         ` Jozef Lawrynowicz
2019-11-07 21:37 ` [PATCH 2/4] MSP430: Disable exception handling by default for C++ Jozef Lawrynowicz
2019-11-08  0:07   ` Oleg Endo
2019-11-08 13:26     ` Jozef Lawrynowicz
2019-11-12 21:13       ` Richard Sandiford
2019-11-27 13:51         ` Jozef Lawrynowicz
2019-11-07 21:39 ` [PATCH 3/4] MSP430: Disable __cxa_atexit Jozef Lawrynowicz
2019-11-07 21:41 ` [PATCH 4/4] MSP430: Deprecate -minrt option Jozef Lawrynowicz
2019-11-17 21:02   ` Jeff Law
2019-11-24 16:38     ` Jozef Lawrynowicz
2019-11-08 12:14 ` [PATCH 0/4][MSP430] Tweaks to default configuration to reduce code size Oleg Endo
2019-11-08 13:27   ` Jozef Lawrynowicz
2019-11-08 13:59     ` Oleg Endo
2019-11-08 14:32       ` Jozef Lawrynowicz

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).