Index: include/cln/config.h.in =================================================================== RCS file: /home/cvs/cln/include/cln/config.h.in,v retrieving revision 1.10 diff -u -r1.10 config.h.in --- include/cln/config.h.in 13 Jun 2006 18:31:18 -0000 1.10 +++ include/cln/config.h.in 4 Jan 2008 22:01:53 -0000 @@ -141,6 +141,13 @@ /* Define if a module's global constructor function and global destructor function need to be exported in order to be accessible from other modules. */ #undef CL_NEED_GLOBALIZE_CTORDTOR +/* Define as the suffix of the name of a module's global constructor function */ +#ifndef CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC +#undef CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC +#endif +#ifndef CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC +#undef CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC +#endif /* CL_CHAR_UNSIGNED */ #ifndef __CHAR_UNSIGNED__ Index: include/cln/modules.h =================================================================== RCS file: /home/cvs/cln/include/cln/modules.h,v retrieving revision 1.20 diff -u -r1.20 modules.h --- include/cln/modules.h 18 Sep 2007 21:56:18 -0000 1.20 +++ include/cln/modules.h 4 Jan 2008 22:01:54 -0000 @@ -3,6 +3,9 @@ #ifndef _CL_MODULES_H #define _CL_MODULES_H +// global constructor/destructor naming. +#include "cln/config.h" + // The order of initialization of different compilation units is not // specified in C++. AIX 4 has a linker which apparently does order // the modules according to dependencies, so that low-level modules @@ -56,6 +59,12 @@ // OK, stop reading here, because it's getting obscene. +#if defined(PIC) + #define CL_GLOBAL_CONSTRUCTOR_SUFFIX CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC +#else + #define CL_GLOBAL_CONSTRUCTOR_SUFFIX CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC +#endif + #if defined(__GNUC__) && defined(__OPTIMIZE__) && !(defined(__hppa__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 8)) && !defined(NO_PROVIDE_REQUIRE) #ifdef ASM_UNDERSCORE #define ASM_UNDERSCORE_PREFIX "_" @@ -227,11 +236,20 @@ // Thus we need to hack the constructors only. #define CL_PROVIDE(module) \ extern "C" void cl_module__##module##__firstglobalfun () {} \ + extern "C" void cl_module__##module##__callctor() \ + __asm__ (ASM_UNDERSCORE_PREFIX CL_GLOBAL_CONSTRUCTOR_PREFIX \ + CL_GLOBAL_CONSTRUCTOR_SUFFIX(module)); \ + static struct cl_module__##module##__ctordelegator { \ + inline cl_module__##module##__ctordelegator () { \ + CL_GLOBALIZE_LABEL("cl_module__" #module "__ctordelegator") \ + CL_OUTPUT_LABEL("cl_module__" #module "__ctordelegator"); \ + cl_module__##module##__callctor(); } \ + } cl_module__##module##__ctordelegatordummy; \ extern "C" void cl_module__##module##__ctorend (void); \ CL_GLOBALIZE_JUMP_LABEL(cl_module__##module##__ctorend) \ CL_GLOBALIZE_CTORDTOR_LABEL( \ ASM_UNDERSCORE_PREFIX CL_GLOBAL_CONSTRUCTOR_PREFIX \ - "cl_module__" #module "__firstglobalfun") \ + CL_GLOBAL_CONSTRUCTOR_SUFFIX(module)) \ static int cl_module__##module##__counter; \ struct cl_module__##module##__controller { \ inline cl_module__##module##__controller () \ @@ -248,8 +266,7 @@ static cl_module__##module##__destroyer cl_module__##module##__dtordummy; #define CL_REQUIRE(module) \ extern "C" void cl_module__##module##__ctor (void) \ - __asm__ (ASM_UNDERSCORE_PREFIX CL_GLOBAL_CONSTRUCTOR_PREFIX \ - "cl_module__" #module "__firstglobalfun"); \ + __asm__ ("cl_module__" #module "__ctordelegator"); \ struct _CL_REQUIRE_CLASSNAME(module,__LINE__) { \ inline _CL_REQUIRE_CLASSNAME(module,__LINE__) () \ { cl_module__##module##__ctor (); } \ Index: m4/c++-constructors.m4 =================================================================== RCS file: /home/cvs/cln/m4/c++-constructors.m4,v retrieving revision 1.1 diff -u -r1.1 c++-constructors.m4 --- m4/c++-constructors.m4 29 Aug 2005 13:18:40 -0000 1.1 +++ m4/c++-constructors.m4 4 Jan 2008 22:01:54 -0000 @@ -95,6 +95,40 @@ if test "$cl_cv_cplusplus_ctorexport" = yes; then AC_DEFINE(CL_NEED_GLOBALIZE_CTORDTOR) fi +AC_CACHE_CHECK([for the global constructor function suffix in shared objects], +cl_cv_cplusplus_ctorsuffix_pic, [ +cat > conftest.cc << EOF +extern "C" void func () {} +static struct S { + inline S () {} +} S; +EOF +AC_TRY_COMMAND(${CXX-g++} $CXXFLAGS ${lt_prog_compiler_pic_CXX-"-fPIC"} -S conftest.cc) >/dev/null 2>&1 +if grep "${cl_cv_cplusplus_ctorprefix}conftest\.cc" conftest.s >/dev/null; then + cl_cv_cplusplus_ctorsuffix_pic='#module ".cc"' +else + cl_cv_cplusplus_ctorsuffix_pic='"cl_module__" #module "__firstglobalfun"' +fi +rm -f conftest* +]) +AC_DEFINE_UNQUOTED([CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC(module)], [$cl_cv_cplusplus_ctorsuffix_pic]) +AC_CACHE_CHECK([for the global constructor function suffix in static objects], +cl_cv_cplusplus_ctorsuffix_nopic, [ +cat > conftest.cc << EOF +extern "C" void func () {} +static struct S { + inline S () {} +} S; +EOF +AC_TRY_COMMAND(${CXX-g++} $CXXFLAGS -S conftest.cc) >/dev/null 2>&1 +if grep "${cl_cv_cplusplus_ctorprefix}conftest\.cc" conftest.s >/dev/null; then + cl_cv_cplusplus_ctorsuffix_nopic='#module ".cc"' +else + cl_cv_cplusplus_ctorsuffix_nopic='"cl_module__" #module "__firstglobalfun"' +fi +rm -f conftest* +]) +AC_DEFINE_UNQUOTED([CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC(module)], [$cl_cv_cplusplus_ctorsuffix_nopic]) fi fi ])