[RFC] Check for __cxa_atexit when building native compiler

Submitted by Kang-Che Sung on April 19, 2017, 1:25 p.m.

Details

Message ID 20170419132558.4808-1-explorer09@gmail.com
State New
Headers show

Commit Message

Kang-Che Sung April 19, 2017, 1:25 p.m.
From: Explorer09 <explorer09@gmail.com>

(This is my first time submitting a patch for GCC)

I found the logic of use_cxa_atexit in configure script a little
bit weird.

It first looks up the default_use_cxa_atexit value for the target,
then, for building the native compiler, checks for __cxa_atexit
in libc. But, from what I read about __cxa_atexit, it should be the
recommended way for registering destructors, and in other words, GCC
shall --enable-__cxa_atexit whenever libc has it, or when _we_ have its
implementation for the target.

The logic should be:
When building native compiler, check for libc's function despite
default_use_cxa_atexit defined for the target, and
default_use_cxa_atexit be used only when building a cross.

Do I understand it wrong?

Below is the patch for the proposed logic change. Thank you.

	2017-04-19  Kang-Che Sung  <explorer09@gmail.com>

	* configure.ac (use_cxa_atexit): When building native compiler,
	ignore $default_use_cxa_atexit and check for libc's __cxa_atexit.
	* configure: Regenerate.

---
 gcc/ChangeLog    |  6 ++++++
 gcc/configure.ac | 24 ++++++++++++++----------
 gcc/configure    | 27 ++++++++++++++++-----------
 3 files changed, 36 insertions(+), 21 deletions(-)

Patch hide | download patch | download mbox

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d52db8a3609..e93789faf9c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@ 
+2017-04-19  Kang-Che Sung  <explorer09@gmail.com>
+
+	* configure.ac (use_cxa_atexit): When building native compiler,
+	ignore $default_use_cxa_atexit and check for libc's __cxa_atexit.
+	* configure: Regenerate.
+
 2017-04-19  Eric Botcazou  <ebotcazou@adacore.com>
             Vladimir Makarov  <vmakarov@redhat.com>
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 9d4c792a33f..cf7ddce79c1 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1632,9 +1632,8 @@  fi
 # --------
 
 use_cxa_atexit=no
-if test x$enable___cxa_atexit = xyes || \
-   test x$enable___cxa_atexit = x -a x$default_use_cxa_atexit = xyes; then
-  if test x$host = x$target; then
+if test x$host = x$target; then
+  if test x$enable___cxa_atexit != xno; then
     case $host in
       # mingw32 doesn't have __cxa_atexit but uses atexit registration
       # keyed to flag_use_cxa_atexit
@@ -1645,22 +1644,27 @@  if test x$enable___cxa_atexit = xyes || \
 	use_cxa_atexit=yes
 	;;
       *)
-	AC_CHECK_FUNC(__cxa_atexit,[use_cxa_atexit=yes],
-	  [echo "__cxa_atexit can't be enabled on this target"])
+	AC_CHECK_FUNC(__cxa_atexit, [use_cxa_atexit=yes],[
+          if test x$enable___cxa_atexit = xyes; then
+            AC_MSG_ERROR([__cxa_atexit can't be enabled on this target])
+          fi])
 	;;
     esac
-  else
-    # We can't check for __cxa_atexit when building a cross, so assume
-    # it is available 
+  fi
+else
+  # Can't check presence of libc functions during cross-compile, so respect
+  # user or use our default.
+  if test x$enable___cxa_atexit = xyes || \
+     test x$enable___cxa_atexit = x -a x$default_use_cxa_atexit = xyes; then
     use_cxa_atexit=yes
   fi
-  if test x$use_cxa_atexit = xyes; then
+fi
+if test x$use_cxa_atexit = xyes; then
     AC_DEFINE(DEFAULT_USE_CXA_ATEXIT, 2,
       [Define if you want to use __cxa_atexit, rather than atexit, to
       register C++ destructors for local statics and global objects.
       This is essential for fully standards-compliant handling of
       destructors, but requires __cxa_atexit in libc.])
-  fi
 fi
 
 # Look for a file containing extra machine modes.