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(-)
@@ -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
@@ -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.
@@ -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 =
@@ -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.
@@ -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.
@@ -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)
@@ -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; }
@@ -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;
@@ -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; }
@@ -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\]]] \
@@ -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
{
@@ -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();
@@ -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 "" }
@@ -1,5 +1,5 @@
// PR c++/29318
-// { dg-options "" }
+// { dg-options "-fexceptions" }
#include <typeinfo>
@@ -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
@@ -1,5 +1,5 @@
// PR c++/33492
-// { dg-options "" }
+// { dg-options "-fexceptions" }
void foo()
{
@@ -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
@@ -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;
@@ -1,5 +1,5 @@
// { dg-do compile }
-// { dg-options "-O2 -fdump-tree-ivopts-details" }
+// { dg-options "-fexceptions -O2 -fdump-tree-ivopts-details" }
class MinimalVec3
{
@@ -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;
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=1" }
+// { dg-options "-fexceptions -Wcatch-value=1" }
struct A { virtual ~A() {} };
struct B : A {};
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=2" }
+// { dg-options "-fexceptions -Wcatch-value=2" }
struct A { virtual ~A() {} };
struct B : A {};
@@ -1,4 +1,4 @@
-// { dg-options "-Wcatch-value=3" }
+// { dg-options "-fexceptions -Wcatch-value=3" }
struct A { virtual ~A() {} };
struct B : A {};
@@ -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__);
@@ -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
{
@@ -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 *, ...);
@@ -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>
@@ -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
@@ -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
}
@@ -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
+ }]
}
@@ -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.
@@ -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