From 5a86d36fcc33e2461ab247715769b72d6d24e3e5 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Sun, 9 Sep 2012 23:08:48 +0000
Subject: [PATCH] re PR libstdc++/43852 (Embedded systems friendly libstdc++)

2012-09-10  Sebastian Huber  <sebastian.huber@embedded-brains.de>
	    Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/43852
	* acinclude.m4 (GLIBCXX_ENABLE_VERBOSE): Define.
	* configure.ac (GLIBCXX_ENABLE_VERBOSE): Use it.
	* config.h.in: Regenerate.
	* configure: Likewise.
	* libsupc++/eh_term_handler.cc (_GLIBCXX_VERBOSE): Check new macro.
	* libsupc++/pure.cc (_GLIBCXX_VERBOSE): Likewise.
	* doc/xml/manual/configure.xml (--disable-libstdcxx-verbose): Document.
	* doc/html/manual/configure.html: Regenerate.

Co-Authored-By: Jonathan Wakely <jwakely.gcc@gmail.com>

From-SVN: r191121
---
 libstdc++-v3/ChangeLog                      | 13 ++++++
 libstdc++-v3/acinclude.m4                   | 25 +++++++++++
 libstdc++-v3/config.h.in                    |  3 ++
 libstdc++-v3/configure                      | 46 ++++++++++++++++-----
 libstdc++-v3/configure.ac                   |  3 ++
 libstdc++-v3/doc/html/manual/configure.html |  8 ++++
 libstdc++-v3/doc/xml/manual/configure.xml   | 13 ++++++
 libstdc++-v3/libsupc++/eh_term_handler.cc   | 18 ++++----
 libstdc++-v3/libsupc++/pure.cc              |  4 +-
 9 files changed, 111 insertions(+), 22 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a2ed07e018a9..4ecedf818bd1 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,16 @@
+2012-09-10  Sebastian Huber  <sebastian.huber@embedded-brains.de>
+	    Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+	PR libstdc++/43852
+	* acinclude.m4 (GLIBCXX_ENABLE_VERBOSE): Define.
+	* configure.ac (GLIBCXX_ENABLE_VERBOSE): Use it.
+	* config.h.in: Regenerate.
+	* configure: Likewise.
+	* libsupc++/eh_term_handler.cc (_GLIBCXX_VERBOSE): Check new macro.
+	* libsupc++/pure.cc (_GLIBCXX_VERBOSE): Likewise.
+	* doc/xml/manual/configure.xml (--disable-libstdcxx-verbose): Document.
+	* doc/html/manual/configure.html: Regenerate.
+
 2012-09-09  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
 	PR bootstrap/54419
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index c9b8d37e86a0..794df5c22be8 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -2316,6 +2316,31 @@ AC_DEFUN([GLIBCXX_ENABLE_HOSTED], [
 ])
 
 
+dnl
+dnl Check if the user wants a non-verbose library implementation.
+dnl
+dnl --disable-libstdcxx-verbose will turn off descriptive messages to
+dnl standard error on termination.
+dnl
+dnl Defines:
+dnl  _GLIBCXX_VERBOSE (always defined, either to 1 or 0)
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_VERBOSE], [
+  AC_ARG_ENABLE([libstdcxx-verbose],
+    AC_HELP_STRING([--disable-libstdcxx-verbose],
+		   [disable termination messages to standard error]),,
+		   [enable_libstdcxx_verbose=yes])
+  if test x"$enable_libstdcxx_verbose" = xyes; then
+    verbose_define=1
+  else
+    AC_MSG_NOTICE([verbose termination messages are disabled])
+    verbose_define=0
+  fi
+  AC_DEFINE_UNQUOTED(_GLIBCXX_VERBOSE, $verbose_define,
+    [Define to 1 if a verbose library is built, or 0 otherwise.])
+])
+
+
 dnl
 dnl Check for template specializations for the 'long long' type.
 dnl The result determines only whether 'long long' I/O is enabled; things
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 075c9f814a8d..0667bbf7df89 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -845,6 +845,9 @@
 /* Define if code specialized for wchar_t should be used. */
 #undef _GLIBCXX_USE_WCHAR_T
 
+/* Define to 1 if a verbose library is built, or 0 otherwise. */
+#undef _GLIBCXX_VERBOSE
+
 /* Defined if as can handle rdrand. */
 #undef _GLIBCXX_X86_RDRAND
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index b29ca1b942c1..ba471ad3b450 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -843,6 +843,7 @@ enable_fast_install
 with_gnu_ld
 enable_libtool_lock
 enable_hosted_libstdcxx
+enable_libstdcxx_verbose
 enable_sjlj_exceptions
 enable_libstdcxx_pch
 enable_cstdio
@@ -1517,6 +1518,8 @@ Optional Features:
   --disable-libtool-lock  avoid locking (might break parallel builds)
   --disable-hosted-libstdcxx
                           only build freestanding C++ runtime support
+  --disable-libstdcxx-verbose
+                          disable termination messages to standard error
   --enable-sjlj-exceptions
                           force use of builtin_setjmp for exceptions
                           [default=auto]
@@ -11504,7 +11507,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11507 "configure"
+#line 11510 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11610,7 +11613,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11613 "configure"
+#line 11616 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14936,6 +14939,29 @@ _ACEOF
 
 
 
+# Enable descriptive messages to standard output on termination.
+
+  # Check whether --enable-libstdcxx-verbose was given.
+if test "${enable_libstdcxx_verbose+set}" = set; then :
+  enableval=$enable_libstdcxx_verbose;
+else
+  enable_libstdcxx_verbose=yes
+fi
+
+  if test x"$enable_libstdcxx_verbose" = xyes; then
+    verbose_define=1
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: verbose termination messages are disabled" >&5
+$as_echo "$as_me: verbose termination messages are disabled" >&6;}
+    verbose_define=0
+  fi
+
+cat >>confdefs.h <<_ACEOF
+#define _GLIBCXX_VERBOSE $verbose_define
+_ACEOF
+
+
+
 # Enable compiler support that doesn't require linking.
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for exception model to use" >&5
@@ -14968,7 +14994,7 @@ fi
     #
     # Fake what AC_TRY_COMPILE does.  XXX Look at redoing this new-style.
     cat > conftest.$ac_ext << EOF
-#line 14971 "configure"
+#line 14997 "configure"
 struct S { ~S(); };
 void bar();
 void foo()
@@ -15303,7 +15329,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; }
   # Fake what AC_TRY_COMPILE does.
 
     cat > conftest.$ac_ext << EOF
-#line 15306 "configure"
+#line 15332 "configure"
 int main()
 {
   typedef bool atomic_type;
@@ -15338,7 +15364,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15341 "configure"
+#line 15367 "configure"
 int main()
 {
   typedef short atomic_type;
@@ -15373,7 +15399,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15376 "configure"
+#line 15402 "configure"
 int main()
 {
   // NB: _Atomic_word not necessarily int.
@@ -15409,7 +15435,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15412 "configure"
+#line 15438 "configure"
 int main()
 {
   typedef long long atomic_type;
@@ -15488,7 +15514,7 @@ $as_echo "$as_me: WARNING: Performance of certain classes will degrade as a resu
   # unnecessary for this test.
 
     cat > conftest.$ac_ext << EOF
-#line 15491 "configure"
+#line 15517 "configure"
 int main()
 {
   _Decimal32 d1;
@@ -15530,7 +15556,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
   # unnecessary for this test.
 
     cat > conftest.$ac_ext << EOF
-#line 15533 "configure"
+#line 15559 "configure"
 template<typename T1, typename T2>
   struct same
   { typedef T2 type; };
@@ -15564,7 +15590,7 @@ $as_echo "$enable_int128" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15567 "configure"
+#line 15593 "configure"
 template<typename T1, typename T2>
   struct same
   { typedef T2 type; };
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index 555f380495bc..c09c685e099d 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -104,6 +104,9 @@ postdeps_CXX=`echo " $postdeps_CXX " | sed 's, -lstdc++ ,,g'`
 ## than just ignoring the results.  Faster /and/ more correct, win win.
 GLIBCXX_ENABLE_HOSTED
 
+# Enable descriptive messages to standard output on termination.
+GLIBCXX_ENABLE_VERBOSE
+
 # Enable compiler support that doesn't require linking.
 GLIBCXX_ENABLE_SJLJ_EXCEPTIONS
 GLIBCXX_ENABLE_PCH($is_hosted)
diff --git a/libstdc++-v3/doc/html/manual/configure.html b/libstdc++-v3/doc/html/manual/configure.html
index a721df2cd757..ec4e78ba7fcb 100644
--- a/libstdc++-v3/doc/html/manual/configure.html
+++ b/libstdc++-v3/doc/html/manual/configure.html
@@ -215,4 +215,12 @@
      <span class="emphasis"><em>freestanding</em></span> environment, in which only a
      minimal set of headers are provided.  This option builds such an
      environment.
+     </p></dd><dt><span class="term"><code class="code">--disable-libstdcxx-verbose</code></span></dt><dd><p>
+     By default, the library is configured to write descriptive messages
+     to standard error for certain events such as calling a pure virtual
+     function or the invocation of the standard terminate handler.  Those
+     messages cause the library to depend on the demangler and standard I/O
+     facilites, which might be undesirable in a low-memory environment or
+     when standard error is not available.  This option disables those
+     messages.  This option does not change the library ABI.
      </p></dd></dl></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="setup.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="setup.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="make.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. Setup </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Make</td></tr></table></div></body></html>
diff --git a/libstdc++-v3/doc/xml/manual/configure.xml b/libstdc++-v3/doc/xml/manual/configure.xml
index 83443ef4c1f2..bc98d7a16e95 100644
--- a/libstdc++-v3/doc/xml/manual/configure.xml
+++ b/libstdc++-v3/doc/xml/manual/configure.xml
@@ -370,6 +370,19 @@
      </para>
  </listitem></varlistentry>
 
+<varlistentry><term><code>--disable-libstdcxx-verbose</code></term>
+ <listitem>
+   <para>
+     By default, the library is configured to write descriptive messages
+     to standard error for certain events such as calling a pure virtual
+     function or the invocation of the standard terminate handler.  Those
+     messages cause the library to depend on the demangler and standard I/O
+     facilites, which might be undesirable in a low-memory environment or
+     when standard error is not available.  This option disables those
+     messages.  This option does not change the library ABI.
+   </para>
+ </listitem></varlistentry>
+
 </variablelist>
 
 </section>
diff --git a/libstdc++-v3/libsupc++/eh_term_handler.cc b/libstdc++-v3/libsupc++/eh_term_handler.cc
index 52a074596fe9..f4bf2a30821b 100644
--- a/libstdc++-v3/libsupc++/eh_term_handler.cc
+++ b/libstdc++-v3/libsupc++/eh_term_handler.cc
@@ -1,5 +1,5 @@
 // -*- C++ -*- std::terminate handler
-// Copyright (C) 2002, 2003, 2009 Free Software Foundation
+// Copyright (C) 2002-2012 Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -28,19 +28,17 @@
 /* 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>, initializing
-   to "std::abort", and rebuilding the library.  In a freestanding mode, we
-   default to this latter approach.  */
-
-#if ! _GLIBCXX_HOSTED
-# include <cstdlib>
-#endif
+   to the earlier "silent death" handler by configuring GCC with
+   --disable-libstdcxx-verbose and rebuilding the library.
+   In a freestanding environment, we default to this latter approach.  */
 
+#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
 /* The current installed user handler.  */
 std::terminate_handler __cxxabiv1::__terminate_handler =
-#if _GLIBCXX_HOSTED
 	__gnu_cxx::__verbose_terminate_handler;
 #else
-	std::abort;
+# include <cstdlib>
+/* The current installed user handler.  */
+std::terminate_handler __cxxabiv1::__terminate_handler = std::abort;
 #endif
 
diff --git a/libstdc++-v3/libsupc++/pure.cc b/libstdc++-v3/libsupc++/pure.cc
index 4879e59de356..a7745979be72 100644
--- a/libstdc++-v3/libsupc++/pure.cc
+++ b/libstdc++-v3/libsupc++/pure.cc
@@ -1,5 +1,5 @@
 // -*- C++ -*- 
-// Copyright (C) 2000, 2001, 2009, 2011 Free Software Foundation
+// Copyright (C) 2000-2012 Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -26,7 +26,7 @@
 #include <cxxabi.h>
 #include "unwind-cxx.h"
 
-#if _GLIBCXX_HOSTED
+#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
 #ifdef _GLIBCXX_HAVE_UNISTD_H
 # include <unistd.h>
 # define writestr(str)	write(2, str, sizeof(str) - 1)
-- 
GitLab