diff --git a/ChangeLog b/ChangeLog index 43e664c..661f9e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-01-06 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> + Richard B. Kreckel <kreckel@ginac.de> + + Cater to the fact that g++ 4.3 will use a different naming for + the global constructor suffix in shared and static objects. + * m4/c++-constructors.m4 (CL_GLOBAL_CONSTRUCTORS): Add test for + the global constructor suffix, define CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC + and CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC appropriately. + * include/cln/config.h.in: Provide templates to be filled in by + configure. + * include/cln/modules.h (CL_PROVIDE, CL_REQUIRE): Use + CL_GLOBAL_CONSTRUCTOR_SUFFIX_PIC, CL_GLOBAL_CONSTRUCTOR_SUFFIX_NOPIC. + 2007-12-19 Richard B. Kreckel <kreckel@ginac.de> * m4/general.m4 (CL_CANONICAL_HOST_CPU): Force host_cpu=rs6000 for diff --git a/include/cln/config.h.in b/include/cln/config.h.in index 3ef1e76..ec00f5e 100644 --- a/include/cln/config.h.in +++ b/include/cln/config.h.in @@ -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__ diff --git a/include/cln/modules.h b/include/cln/modules.h index ad05e0b..29f4730 100644 --- a/include/cln/modules.h +++ b/include/cln/modules.h @@ -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 "_" @@ -224,14 +233,22 @@ // gcc-3.0 -fuse-cxa-atexit doesn't have a single per-module destructor // function anymore. Instead, for each object's static constructor it // executes, it pushes the corresponding object's destructor onto a list. - // Thus we need to hack the constructors only. + // Thus we need to hack the constructors only. gcc-4.3 uses different names + // for global ctors in shared and static objects, so we cannot directly + // call the ctors from CL_REQUIRE(M): the compiling function does not know + // yet how it's going to be linked. Hence, we must hide the ctor call beind + // an additional indirection. #define CL_PROVIDE(module) \ extern "C" void cl_module__##module##__firstglobalfun () {} \ - extern "C" void cl_module__##module##__ctorend (void); \ - CL_GLOBALIZE_JUMP_LABEL(cl_module__##module##__ctorend) \ + extern "C" void cl_module__##module##__ctorend (); \ + extern "C" void cl_module__##module##__docallctors () \ + __asm__ (ASM_UNDERSCORE_PREFIX CL_GLOBAL_CONSTRUCTOR_PREFIX \ + CL_GLOBAL_CONSTRUCTOR_SUFFIX(module)); \ + extern "C" void cl_module__##module##__globalctors () \ + { cl_module__##module##__docallctors(); } \ 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 () \ @@ -247,9 +264,8 @@ }; \ 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"); \ + extern "C" void cl_module__##module##__ctor () \ + __asm__ (ASM_UNDERSCORE_PREFIX "cl_module__" #module "__globalctors"); \ struct _CL_REQUIRE_CLASSNAME(module,__LINE__) { \ inline _CL_REQUIRE_CLASSNAME(module,__LINE__) () \ { cl_module__##module##__ctor (); } \ diff --git a/m4/c++-constructors.m4 b/m4/c++-constructors.m4 index 2eb9889..192b1e7 100644 --- a/m4/c++-constructors.m4 +++ b/m4/c++-constructors.m4 @@ -95,6 +95,46 @@ rm -f conftest* if test "$cl_cv_cplusplus_ctorexport" = yes; then AC_DEFINE(CL_NEED_GLOBALIZE_CTORDTOR) fi +dnl Test what suffix to give the global ctors inside shared object files. +if test "$enable_shared" = yes; then +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]) +fi +dnl Test what suffix to give the global ctors inside static object files. +if test "$enable_static" = yes; then +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 fi ])