This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: Add --enable-__cxa_atexit
On Tue, Jun 04, 2002 at 02:13:26PM -0400, Jakub Jelinek wrote:
> On Tue, Jun 04, 2002 at 10:11:53AM -0700, H . J . Lu wrote:
> > > If people find that this is too expensive, they can still use
> > > -fno-use-cxa-atexit for their application, trading speed for
> > > correctness. By default, I think the implementation should favour
> > > correctness over performance (trying to speed-up the correct
> > > implementation if that turns out too slow).
> >
> > You can even build libstdc++ with -fno-use-cxa-atexit if you believe
> > it won't affect its correctness. Maybe it should be added by default.
>
> It is actually not that hard to prove it.
> Just run nm -uD libstdc++.so.4 | grep atexit
>
Here is a new patch to pass -fno-use-cxa-atexit to libstdc++-v3.
H.J.
---
2002-06-04 H.J. Lu (hjl@gnu.org)
* acinclude.m4 (EXTRA_CXX_FLAGS): Add -fno-use-cxa-atexit.
* aclocale.m4: Regenerated.
* configure: Likewise.
2002-06-02 H.J. Lu (hjl@gnu.org)
* configure.in: Add --enable-__cxa_atexit.
* configure: Regenerated.
* config.in: Likewise.
* defaults.h (DEFAULT_USE_CXA_ATEXIT): New. Defined to be 0 if
not defined.
2002-06-02 H.J. Lu (hjl@gnu.org)
* decl2.c (flag_use_cxa_atexit): Set to DEFAULT_USE_CXA_ATEXIT.
--- gcc/gcc/config.in.atexit Thu May 23 16:28:28 2002
+++ gcc/gcc/config.in Mon Jun 3 16:29:55 2002
@@ -296,6 +296,10 @@
every opportunity. This is extremely expensive. */
#undef ENABLE_GC_ALWAYS_COLLECT
+/* Define if you want to use __cxa_atexit, rather than atexit, to
+ register C++ destructors for local statics and global objects. */
+#undef DEFAULT_USE_CXA_ATEXIT
+
/* Define if you want the C and C++ compilers to support multibyte
character sets for source code. */
#undef MULTIBYTE_CHARS
--- gcc/gcc/configure.in.atexit Mon Jun 3 16:29:55 2002
+++ gcc/gcc/configure.in Mon Jun 3 16:29:55 2002
@@ -259,6 +259,16 @@ elif test x$withval != xno; then
cpp_install_dir=$withval
fi])
+# Enable __cxa_atexit for C++.
+AC_ARG_ENABLE(__cxa_atexit,
+[ --enable-__cxa_atexit enable __cxa_atexit for C++],
+[], [])
+if test x$enable___cxa_atexit = xyes; then
+ AC_DEFINE(DEFAULT_USE_CXA_ATEXIT, 1,
+ [Define if you want to use __cxa_atexit, rather than atexit, to
+ register C++ destructors for local statics and global objects.])
+fi
+
# Enable Multibyte Characters for C/C++
AC_ARG_ENABLE(c-mbchar,
[ --enable-c-mbchar enable multibyte characters for C and C++],
--- gcc/gcc/cp/decl2.c.atexit Tue Apr 30 10:11:37 2002
+++ gcc/gcc/cp/decl2.c Mon Jun 3 16:29:55 2002
@@ -376,7 +376,7 @@ int flag_weak = 1;
/* Nonzero to use __cxa_atexit, rather than atexit, to register
destructors for local statics and global objects. */
-int flag_use_cxa_atexit;
+int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
/* Maximum template instantiation depth. This limit is rather
arbitrary, but it exists to limit the time it takes to notice
--- gcc/gcc/defaults.h.atexit Sun May 19 21:43:24 2002
+++ gcc/gcc/defaults.h Mon Jun 3 16:29:55 2002
@@ -462,4 +462,10 @@ You Lose! You must define PREFERRED_DEB
#define MODE_BASE_REG_CLASS(MODE) BASE_REG_CLASS
#endif
+/* Determine whether __cxa_atexit, rather than atexit, is used to
+ register C++ destructors for local statics and global objects. */
+#ifndef DEFAULT_USE_CXA_ATEXIT
+#define DEFAULT_USE_CXA_ATEXIT 0
+#endif
+
#endif /* ! GCC_DEFAULTS_H */
--- gcc/libstdc++-v3/acinclude.m4.atexit Mon May 27 09:12:08 2002
+++ gcc/libstdc++-v3/acinclude.m4 Tue Jun 4 12:50:03 2002
@@ -1062,6 +1062,9 @@ if test "$enable_cxx_flags" = "none"; th
enable_cxx_flags='';
fi
+# Since libstdc++-v3 doesn't call atexit directly, it is safe to always
+# optimize with -fno-use-cxa-atexit.
+EXTRA_CXX_FLAGS="-fno-use-cxa-atexit"
dnl Run through flags (either default or command-line) and set anything
dnl extra (e.g., #defines) that must accompany particular g++ options.
if test -n "$enable_cxx_flags"; then
@@ -1074,9 +1077,9 @@ if test -n "$enable_cxx_flags"; then
esac
done
fi
-EXTRA_CXX_FLAGS="$enable_cxx_flags"
-AC_SUBST(EXTRA_CXX_FLAGS)
+EXTRA_CXX_FLAGS="$EXTRA_CXX_FLAGS $enable_cxx_flags"
])
+AC_SUBST(EXTRA_CXX_FLAGS)
dnl