This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libstdc++] Initialize terminate() handler based on hosted vs freestanding
- From: Phil Edwards <phil at jaj dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 31 Aug 2003 01:30:37 -0400
- Subject: [libstdc++] Initialize terminate() handler based on hosted vs freestanding
Last Christmas, we had a long discussion about using the "verbose terminate"
handler routine by default, culminating in this patch:
http://gcc.gnu.org/ml/gcc-patches/2002-12/msg01322.html
One of the major worries was what to do in a freestanding or embedded
environment. The result is what we have now in eh_term_handler.cc, where a
user of a limited-resource environment can trivially change the code to not
use the verbose handler by default. (Or just link with a custom object file
before linking against the library, if the linker for that system allows it.)
Yesterday, bits of memory slowly drifted up out of my subconscious until
I realized that we can implement a variant of an idea I'd had at the time:
http://gcc.gnu.org/ml/libstdc++/2002-12/msg00253.html
now that libstdc++ has an explicit --enable/--disable switch for hosted vs
freestanding. There's still nothing tying that switch together with the
compiler's -ffreestanding option, but we can rely on embedded developers
doing the right thing here, I think.
(Possibly, if --disable-hosted-libstdcxx has been passed, what's left of
libstdc++ should be built with -ffreestanding, but I haven't experimented
with doing so.)
The core of a patch to do this is below. (Documentation and some
regen'd files not included.) It seems a bit heavy-handed to include
all of c++config.h in a libsupc++ file, but any other method would have
required special build rules, and c++config.h is nothing but cpp macros.
With this patch, developers might not have to edit the source to avoid
pulling in all the overhead of the verbose handler.
I'll check this in later. Any comments on style/spelling?
2003-08-31 Phil Edwards <phil@codesourcery.com>
* acinclude.m4 (GLIBCXX_ENABLE_HOSTED): #define _GLIBCXX_HOSTED
appropriately.
* libsupc++/eh_term_handler.cc: Test it here, initialize
__terminate_handler to std::abort if freestanding.
Index: acinclude.m4
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.268
diff -u -3 -p -r1.268 acinclude.m4
--- acinclude.m4 27 Aug 2003 20:26:22 -0000 1.268
+++ acinclude.m4 31 Aug 2003 05:26:28 -0000
@@ -1284,12 +1284,16 @@ AC_DEFUN(GLIBCXX_ENABLE_HOSTED, [
if test "$enable_hosted_libstdcxx" = no; then
AC_MSG_NOTICE([Only freestanding libraries will be built])
is_hosted=no
+ hosted_define=0
enable_abi_check=no
enable_libstdcxx_pch=no
else
is_hosted=yes
+ hosted_define=1
fi
GLIBCXX_CONDITIONAL(GLIBCXX_HOSTED, test $is_hosted = yes)
+ AC_DEFINE_UNQUOTED(_GLIBCXX_HOSTED, $hosted_define,
+ [Define to 1 if a full hosted library is built, or 0 if freestanding.])
])
Index: libsupc++/eh_term_handler.cc
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/libsupc++/eh_term_handler.cc,v
retrieving revision 1.3
diff -u -3 -p -r1.3 eh_term_handler.cc
--- libsupc++/eh_term_handler.cc 24 May 2003 16:22:03 -0000 1.3
+++ libsupc++/eh_term_handler.cc 31 Aug 2003 05:26:28 -0000
@@ -1,5 +1,5 @@
// -*- C++ -*- std::terminate handler
-// Copyright (C) 2002 Free Software Foundation
+// Copyright (C) 2002, 2003 Free Software Foundation
//
// This file is part of GCC.
//
@@ -28,14 +28,24 @@
// the GNU General Public License.
#include "unwind-cxx.h"
+#include <bits/c++config.h>
-/* We default to the talkative, informative handler. This pulls in the
- demangler, the dyn-string utilities, and elements of the I/O library.
- For a low-memory environment, you can return to the earlier "silent death"
- handler by including <cstdlib>, initializg to "std::abort", and rebuilding
- the library. */
+/* We default to the talkative, informative handler in a normal hosted
+ library. This pulls in the demangler, the dyn-string utilities, and
+ elements of the I/O library. For a low-memory environment, you can return
+ to the earlier "silent death" handler by including <cstdlib>, initializg
+ to "std::abort", and rebuilding the library. In a freestanding mode, we
+ default to this latter approach. */
+
+#if ! _GLIBCXX_HOSTED
+# include <cstdlib>
+#endif
/* The current installed user handler. */
std::terminate_handler __cxxabiv1::__terminate_handler =
- __gnu_cxx::__verbose_terminate_handler;
+#if _GLIBCXX_HOSTED
+ __gnu_cxx::__verbose_terminate_handler;
+#else
+ std::abort;
+#endif