[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Pkg-octave-devel] CXX_ABI



On 29-Jul-2008, John W. Eaton wrote:

| I will try to see if we can rework the way .oct files are loaded in
| the main development branch so that it does not depend on C++ name
| mangling to do the job.  Then we can eliminate the CXX_ABI macro and
| this (ugly) part of the configure script.

I checked in the following changes for the default development
branch.  This change should not be installed on the release-3-0-x
branch it will break backward compatibility with the ABI.

jwe


# HG changeset patch
# User John W. Eaton <jwe@octave.org>
# Date 1217441625 14400
# Node ID 6a7db240b3a3b3950ac1cc70db43a08e721a2662
# Parent  89dd4531b26a0c8654ce6e9d5ffddcbbb37921d0
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-30  John W. Eaton  <jwe@octave.org>
+
+	* aclocal.m4 (CXX_ABI, OCTAVE_CXX_PREPENDS_UNDERSCORE,
+	OCTAVE_PROG_NM): Delete macros.
+	* configure.in: Delete uses.
+
 2008-07-29  Tatsuro MATSUOKA  <tmacchant@yahoo.co.jp>
 
 	* aclocal.m4 (OCTAVE_OPENGL): Handle MinGW the same as MSVC.
diff --git a/aclocal.m4 b/aclocal.m4
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -627,56 +627,6 @@
   AC_SUBST(TEXI2PDF)
 ])
 dnl
-dnl Find nm.
-dnl
-dnl OCTAVE_PROG_NM
-AC_DEFUN(OCTAVE_PROG_NM,
-[AC_CHECK_PROG(NM, ${ac_tool_prefix}nm, ${ac_tool_prefix}nm, [])
-  AC_SUBST(NM)
-])
-dnl
-dnl See if the C++ compiler prepends an underscore to external names.
-dnl
-dnl OCTAVE_CXX_PREPENDS_UNDERSCORE
-AC_DEFUN(OCTAVE_CXX_PREPENDS_UNDERSCORE, [
-  AC_REQUIRE([OCTAVE_PROG_NM])
-  AC_MSG_CHECKING([whether ${CXX-g++} prepends an underscore to external names])
-  AC_CACHE_VAL(octave_cv_cxx_prepends_underscore,
-    [octave_cv_cxx_prepends_underscore=no
-    AC_LANG_PUSH(C++)
-    cat > conftest.$ac_ext <<EOF
-bool FSmy_dld_fcn (void) { return false; }
-EOF
-    if (eval "$ac_compile") 2>&AS_MESSAGE_LOG_FD; then
-      if test "`${NM-nm} conftest.$ac_objext | grep _FSmy_dld_fcn`" != ""; then
-        octave_cv_cxx_prepends_underscore=yes
-      fi
-    else
-      echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
-      cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD
-    fi
-    AC_LANG_POP(C++)
-### FIXME -- Ignore test result on Windows.  Yes it prepends
-### underscore, but LoadLibrary ignores it automatically.  The
-### correct test is to build the shared library then try to grab the
-### symbol from it with and without underscore.
-    case "$canonical_host_type" in
-      *-*-cygwin* | *-*-mingw*)
-        octave_cv_cxx_prepends_underscore=no
-      ;;
-### FIXME -- Ignore test result on OS X.  Yes it prepends
-### underscore, but also messes with the name so test fails (incorrectly).
-      *-*-darwin*)
-        octave_cv_cxx_prepends_underscore=yes
-      ;;
-    esac
-  ])
-  AC_MSG_RESULT($octave_cv_cxx_prepends_underscore)
-  if test $octave_cv_cxx_prepends_underscore = yes; then
-    AC_DEFINE(CXX_PREPENDS_UNDERSCORE, 1, [Define if your compiler prepends underscores to external names.])
-  fi
-])
-dnl
 dnl See if the C++ library is ISO compliant.
 dnl FIXME: This is obviously very simplistic, and trivially fooled.
 dnl
@@ -737,43 +687,6 @@
     ])
   fi
   AC_SUBST(LIBREADLINE)
-])
-dnl
-dnl Determine the C++ compiler ABI. It sets the macro CXX_ABI to the
-dnl name of the ABI, and is used to mangle the C linkage loadable
-dnl functions to avoid ABI mismatch.  GNU C++ currently uses gnu_v2 
-dnl (GCC versions <= 2.95.x) dnl or gnu_v3 (GCC versions >= 3.0).
-dnl Set to "unknown" is when we don't know enough about the ABI, which 
-dnl will happen when using an unsupported C++ compiler. 
-dnl
-dnl OCTAVE_CXX_ABI
-AC_DEFUN(OCTAVE_CXX_ABI, [
-  AC_REQUIRE([OCTAVE_PROG_NM])
-  AC_MSG_CHECKING([C++ ABI version used by ${CXX}])
-  AC_CACHE_VAL(octave_cv_cxx_abi,
-    [octave_cv_cxx_abi='unknown'
-    AC_LANG_PUSH(C++)
-    cat > conftest.$ac_ext <<EOF
-bool FSmy_dld_fcn (void) { return false; }
-EOF
-    if (eval "$ac_compile") 2>&AS_MESSAGE_LOG_FD; then
-      if test "`${NM-nm} conftest.$ac_objext | grep FSmy_dld_fcn__Fv`" != ""; then
-        octave_cv_cxx_abi='gnu_v2'
-      fi
-      if test "`${NM-nm} conftest.$ac_objext | grep _Z12FSmy_dld_fcnv`" != ""; then
-        octave_cv_cxx_abi='gnu_v3'
-      fi
-      if test "`${NM-nm} conftest.$ac_objext | grep __1cMFSmy_dld_fcn6F_b_`" != ""; then
-        octave_cv_cxx_abi='sun_v5'
-      fi
-    else
-      echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
-      cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD
-    fi
-    AC_LANG_POP(C++)
-  ])
-  AC_MSG_RESULT($octave_cv_cxx_abi)
-  AC_DEFINE_UNQUOTED(CXX_ABI, $octave_cv_cxx_abi, [Define to the C++ ABI your compiler uses.])
 ])
 dnl
 dnl Check to see if C++ reintrepret cast works for function pointers.
diff --git a/configure.in b/configure.in
--- a/configure.in
+++ b/configure.in
@@ -205,11 +205,6 @@
 OCTAVE_CXX_ISO_COMPLIANT_LIBRARY
 OCTAVE_CXX_BROKEN_REINTERPRET_CAST
 
-# Determine the ABI used the C++ compiler, needed by the dynamic loading
-# code. Currently supported ABIs are GNU v2, GNU v3 and Sun Workshop.
-
-OCTAVE_CXX_ABI
-
 ### See which C compiler to use (we expect to find gcc).
 
 AC_PROG_CC
@@ -348,8 +343,6 @@
   AC_MSG_NOTICE([defining LD_STATIC_FLAG to be $LD_STATIC_FLAG])
 fi
 AC_SUBST(LD_STATIC_FLAG)
-
-OCTAVE_CXX_PREPENDS_UNDERSCORE
 
 ### Defaults for cross compiling.  BUILD_CC and BUILD_CXX are
 ### the compilers that we use for building tools on the build system.
@@ -1758,8 +1751,6 @@
 
 AC_PROG_LN_S
 
-OCTAVE_PROG_NM
-
 AC_PROG_INSTALL
 INSTALL_SCRIPT='${INSTALL}'
 AC_SUBST(INSTALL_SCRIPT)
diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,4 +1,18 @@
 2008-07-30  John W. Eaton  <jwe@octave.org>
+
+	* defun-dld.h (DEFUNX_DLD): Eliminate fsname arg.
+	* defun-int.h (DEFINE_FUN_INSTALLER_FUN2,
+	DEFINE_FUN_INSTALLER_FUN3, DEFINE_FUNX_INSTALLER_FUN2): Delete.
+	(DEFINE_FUNX_INSTALLER_FUN): Rename from DEFINE_FUNX_INSTALLER_FUN3.
+	Don't emit fsname function.  Don't append cxx_abi to gname.
+	(DEFINE_FUN_INSTALLER_FUN): Define in terms of
+	DEFINE_FUNX_INSTALLER_FUN, not DEFINE_FUN_INSTALLER_FUN2.
+	* dynamic-ld.cc (octave_dynamic_loader::name_mangler,
+	octave_dynamic_loader::name_uscore_mangler): New functions.
+	(octave_dynamic_loader::mangle_name,
+	octave_dynamic_loader::xmangle_name): Delete.
+	(octave_dynamic_loader::do_load_oct): Search for function with
+	name_mangler then name_uscore_mangler.
 
 	* oct-stream.cc (do_read): New arg, do_NA_conv.
 	Perform NA translation if do_NA_conv is true.
diff --git a/src/defun-dld.h b/src/defun-dld.h
--- a/src/defun-dld.h
+++ b/src/defun-dld.h
@@ -48,9 +48,11 @@
 // This one can be used when `name' cannot be used directly (if it is
 // already defined as a macro).  In that case, name is already a
 // quoted string, and the internal name of the function must be passed
-// too (the convention is to use a prefix of "F", so "foo" becomes "Ffoo").
+// too (the convention is to use a prefix of "F", so "foo" becomes
+// "Ffoo") as well as the name of the generated installer function
+// (the convention is to use a prefix of "G", so "foo" becomes "Gfoo").
 
-#define DEFUNX_DLD(name, fname, fsname, gname, args_name, nargout_name, doc) \
+#define DEFUNX_DLD(name, fname, gname, args_name, nargout_name, doc) \
   DEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, false, doc)
 
 #else
@@ -60,9 +62,9 @@
   DEFINE_FUN_INSTALLER_FUN (name, doc) \
   DECLARE_FUN (name, args_name, nargout_name)
 
-#define DEFUNX_DLD(name, fname, fsname, gname, args_name, nargout_name, doc) \
+#define DEFUNX_DLD(name, fname, gname, args_name, nargout_name, doc) \
   DECLARE_FUNX (fname, args_name, nargout_name); \
-  DEFINE_FUNX_INSTALLER_FUN (name, fname, fsname, gname, doc) \
+  DEFINE_FUNX_INSTALLER_FUN (name, fname, gname, doc) \
   DECLARE_FUNX (fname, args_name, nargout_name)
 
 #endif
diff --git a/src/defun-int.h b/src/defun-int.h
--- a/src/defun-int.h
+++ b/src/defun-int.h
@@ -73,42 +73,13 @@
 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative);
 
 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \
-  DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI)
+  DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc)
 
-#define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \
-  DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi)
-
-#define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \
-  DEFINE_FUNX_INSTALLER_FUN3(#name, F ## name, FS ## name, G ## name, doc, cxx_abi)
-
-#define DEFINE_FUNX_INSTALLER_FUN(name, fname, fsname, gname, doc) \
-  DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, CXX_ABI)
-
-#define DEFINE_FUNX_INSTALLER_FUN2(name, fname, fsname, gname, doc, cxx_abi) \
-  DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi)
-
-#define DEFINE_FUNX_INSTALLER_FUN3(name, fname, fsname, gname, doc, cxx_abi) \
-  extern "C" \
-  OCTAVE_EXPORT \
-  bool \
-  fsname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \
-  { \
-    bool retval = true; \
- \
-    check_version (OCTAVE_API_VERSION, name); \
- \
-    if (error_state) \
-      retval = false; \
-    else \
-      install_dld_function (fname, name, shl, doc, false, relative); \
- \
-    return retval; \
-  } \
- \
+#define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \
   extern "C" \
   OCTAVE_EXPORT \
   octave_function * \
-  gname ## _ ## cxx_abi (const octave_shlib& shl, bool relative) \
+  gname (const octave_shlib& shl, bool relative) \
   { \
     octave_function *retval = 0; \
  \
diff --git a/src/dynamic-ld.cc b/src/dynamic-ld.cc
--- a/src/dynamic-ld.cc
+++ b/src/dynamic-ld.cc
@@ -357,7 +357,15 @@
     {
       if (oct_file)
 	{
-	  void *function = oct_file.search (fcn_name, xmangle_name);
+	  void *function = oct_file.search (fcn_name, name_mangler);
+
+	  if (! function)
+	    {
+	      // FIXME -- can we determine this C mangling scheme
+	      // automatically at run time or configure time?
+
+	      function = oct_file.search (fcn_name, name_uscore_mangler);
+	    }
 
 	  if (function)
 	    {
@@ -527,31 +535,15 @@
 }
 
 std::string
-octave_dynamic_loader::mangle_name (const std::string& name)
+octave_dynamic_loader::name_mangler (const std::string& name)
 {
-#if defined (CXX_PREPENDS_UNDERSCORE)
-  std::string retval ("_FS");
-#else
-  std::string retval ("FS");
-#endif
-  retval.append (name);
-  retval.append ("_");
-  retval.append (STRINGIFY (CXX_ABI));
-  return retval;
+  return "G" + name;
 }
 
 std::string
-octave_dynamic_loader::xmangle_name (const std::string& name)
+octave_dynamic_loader::name_uscore_mangler (const std::string& name)
 {
-#if defined (CXX_PREPENDS_UNDERSCORE)
-  std::string retval ("_G");
-#else
-  std::string retval ("G");
-#endif
-  retval.append (name);
-  retval.append ("_");
-  retval.append (STRINGIFY (CXX_ABI));
-  return retval;
+  return "_G" + name;
 }
 
 std::string
diff --git a/src/dynamic-ld.h b/src/dynamic-ld.h
--- a/src/dynamic-ld.h
+++ b/src/dynamic-ld.h
@@ -85,9 +85,9 @@
 
 protected:
 
-  static std::string mangle_name (const std::string& name);
+  static std::string name_mangler (const std::string& name);
 
-  static std::string xmangle_name (const std::string& name);
+  static std::string name_uscore_mangler (const std::string& name);
 
   static std::string mex_mangler (const std::string& name);
 

Reply to: