[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] Use C linkage for dynamic linking
From: |
Mumit Khan |
Subject: |
[patch] Use C linkage for dynamic linking |
Date: |
Thu, 28 Jun 2001 20:00:26 -0500 (CDT) |
[ I'm not subscribed to this list, so please copy me if appropriate ]
This is a slight variation of the alternative proposed by jwe to load
dynamically loadable functions in Octave. To avoid ABI mismatch, I
encode the ABI name in the DLF, and that's checked when loading it.
Currently supported ABIs are gnu_v2, gnu_v3 and sun. The DLF are now
named FS#name#_#ABI; eg., besselj will become FSbesselj_gnu_v3 if you're
using GCC 3.0 or later.
Note to testers -- you must re-create the autogenerated files after
applying this patch as it changes acconfig.h and aclocal.m4. If you
use the CVS version:
$ cd <octave_src_toplevel>
$ ./autogen.sh
or, if you're using snapshots that lack autogen.sh,
$ autoconf
$ autoheader
should do the job.
A few odds and ends to note:
- I've added a new macro -- CXX_ABI -- the encodes the ABI.
- Note the CPP macro hacks in both src/defun-int.h and src/dynamic-ld.cc,
which I would presume to be easily fixable by those who understand
cpp argument scanning. Basically, I need to paste the macro CXX_ABI
(which is not a string token in config.h) with various tokens, and
hence the mess.
My tree is somewhat modified, so please try and manually work out any
patch conflicts.
Tested on GNU/Linux with gcc-2.95.2 and gcc-3.0.
ChangeLog/toplevel:
2001-04-21 Mumit Khan <address@hidden>
* aclocal.m4 (OCTAVE_CXX_ABI): New macro.
(OCTAVE_CXX_PREPENDS_UNDERSCORE): Add missing return value.
* configure.in: Use.
* acconfig.h (CXX_ABI): New macro.
ChangeLog/src:
* defun-int.h (DEFINE_FUN_INSTALLER_FUN{2,3}): New macros.
(DEFINE_FUN_INSTALLER_FUN): Use.
* dynamic-ld.cc ({STRINGIFY, STRINGIFY1}): New macros.
(octave_dynamic_loader::mangle_name): Support dynamic linking
for GNU v3 and Sun C++ ABI.
Index: aclocal.m4
===================================================================
RCS file: /cvs/octave/aclocal.m4,v
retrieving revision 1.55
diff -u -3 -p -r1.55 aclocal.m4
--- aclocal.m4 2001/05/23 06:41:58 1.55
+++ aclocal.m4 2001/06/29 00:41:28
@@ -913,7 +913,7 @@ AC_DEFUN(OCTAVE_CXX_PREPENDS_UNDERSCORE,
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
cat > conftest.$ac_ext <<EOF
-bool FSmy_dld_fcn (void) { }
+bool FSmy_dld_fcn (void) { return false; }
EOF
if AC_TRY_EVAL(ac_compile); then
if test "`${NM-nm} conftest.o | grep _FSmy_dld_fcn`" != ""; then
@@ -990,3 +990,41 @@ AC_DEFUN(OCTAVE_ENABLE_READLINE, [
])
fi
])
+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_MSG_CHECKING([C++ ABI version used by ${CXX}])
+ AC_CACHE_VAL(octave_cv_cxx_abi,
+ [octave_cv_cxx_abi='unknown'
+ AC_LANG_SAVE
+ AC_LANG_CPLUSPLUS
+ cat > conftest.$ac_ext <<EOF
+bool FSmy_dld_fcn (void) { return false; }
+EOF
+ if AC_TRY_EVAL(ac_compile); then
+ if test "`${NM-nm} conftest.o | grep FSmy_dld_fcn__Fv`" != ""; then
+ octave_cv_cxx_abi='gnu_v2'
+ fi
+ if test "`${NM-nm} conftest.o | grep _Z12FSmy_dld_fcnv`" != ""; then
+ octave_cv_cxx_abi='gnu_v3'
+ fi
+ if test "`${NM-nm} conftest.o | grep __1cMFSmy_dld_fcn6F_b_`" != ""; then
+ octave_cv_cxx_abi='sun'
+ fi
+ else
+ echo "configure: failed program was:" >&AC_FD_CC
+ cat conftest.$ac_ext >&AC_FD_CC
+ fi
+ AC_LANG_RESTORE
+ ])
+ AC_MSG_RESULT($octave_cv_cxx_abi)
+ AC_DEFINE_UNQUOTED(CXX_ABI, $octave_cv_cxx_abi)
+])
+
Index: configure.in
===================================================================
RCS file: /cvs/octave/configure.in,v
retrieving revision 1.348
diff -u -3 -p -r1.348 configure.in
--- configure.in 2001/05/23 06:41:58 1.348
+++ configure.in 2001/06/29 00:38:05
@@ -194,6 +194,11 @@ AC_SUBST(CXX_VERSION)
OCTAVE_CXX_NEW_FRIEND_TEMPLATE_DECL
OCTAVE_CXX_ISO_COMPLIANT_LIBRARY
+# 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).
EXTERN_CFLAGS="$CFLAGS"
Index: acconfig.h
===================================================================
RCS file: /cvs/octave/acconfig.h,v
retrieving revision 1.47
diff -u -3 -p -r1.47 acconfig.h
--- acconfig.h 2001/05/02 06:15:07 1.47
+++ acconfig.h 2001/06/29 00:38:05
@@ -14,6 +14,9 @@
internal array and matrix classes. */
#undef BOUNDS_CHECKING
+/* Define to the C++ ABI your compiler uses. */
+#undef CXX_ABI
+
/* Define if your C++ runtime library is ISO compliant. */
#undef CXX_ISO_COMPLIANT_LIBRARY
Index: src/defun-int.h
===================================================================
RCS file: /cvs/octave/src/defun-int.h,v
retrieving revision 1.37
diff -u -3 -p -r1.37 defun-int.h
--- src/defun-int.h 2000/11/30 00:27:01 1.37
+++ src/defun-int.h 2001/06/29 00:38:06
@@ -76,13 +76,21 @@ alias_builtin (const std::string& alias,
typedef bool (*octave_dld_fcn_installer) (const octave_shlib&);
#define DEFINE_FUN_INSTALLER_FUN(name, doc) \
+ DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI)
+
+#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) \
+ extern "C" \
bool \
- FS ## name (const octave_shlib& shl) \
+ FS ## name ## _ ## cxx_abi (const octave_shlib& shl) \
{ \
check_version (OCTAVE_VERSION, #name); \
install_dld_function (F ## name, #name, shl, doc); \
return error_state ? false : true; \
}
+
// MAKE_BUILTINS is defined to extract function names and related
// information and create the *.df files that are eventually used to
Index: src/dynamic-ld.cc
===================================================================
RCS file: /cvs/octave/src/dynamic-ld.cc,v
retrieving revision 1.64
diff -u -3 -p -r1.64 dynamic-ld.cc
--- src/dynamic-ld.cc 2000/04/04 06:16:23 1.64
+++ src/dynamic-ld.cc 2001/06/29 00:38:06
@@ -308,6 +308,9 @@ octave_dynamic_loader::remove (const std
return (instance_ok ()) ? instance->do_remove (fcn_name, shl) : false;
}
+#define STRINGIFY(s) STRINGIFY1(s)
+#define STRINGIFY1(s) #s
+
std::string
octave_dynamic_loader::mangle_name (const std::string& name)
{
@@ -317,7 +320,8 @@ octave_dynamic_loader::mangle_name (cons
std::string retval ("FS");
#endif
retval.append (name);
- retval.append ("__FRC12octave_shlib");
+ retval.append ("_");
+ retval.append (STRINGIFY (CXX_ABI));
return retval;
}
- [patch] Use C linkage for dynamic linking,
Mumit Khan <=