From b1eac62ff0ed8ff20c515b928fe676616e14f908 Mon Sep 17 00:00:00 2001 From: Andrew Kaufman Date: Tue, 4 Jun 2019 16:24:50 -0700 Subject: [PATCH 1/5] IECore : Control RTLD_GLOBAL via an environment variable. Set IECORE_FORCE_GLOBAL_SYMBOLS to force it on. Note we're adding this for backwards compatibility during a limited testing phase at IE. We anticipate removing it entirely once proven safe. --- python/IECore/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/IECore/__init__.py b/python/IECore/__init__.py index 6b7b9f65d6..a247acbca3 100644 --- a/python/IECore/__init__.py +++ b/python/IECore/__init__.py @@ -38,17 +38,17 @@ # # Some parts of the IECore library are defined purely in Python. These are shown below. -# Turn on RTLD_GLOBAL to avoid the dreaded cross module RTTI -# errors on Linux. This causes libIECore etc to be loaded into -# the global symbol table and those symbols to be shared between -# modules. Without it, different python modules and/or libraries -# can end up with their own copies of symbols, which breaks a -# great many things. +# Set IECORE_FORCE_GLOBAL_SYMBOLS = 1 to turn on RTLD_GLOBAL to +# avoid the dreaded cross module RTTI errors on Linux. +# This causes libIECore etc to be loaded into the global symbol +# table and those symbols to be shared between modules. Without +# it, different python modules and/or libraries can end up with +# their own copies of symbols, which breaks a great many things. # # We use the awkward "__import__" approach to avoid importing sys # and ctypes into the IECore namespace. -if __import__( "os" ).name == 'posix': +if __import__( "os" ).name == 'posix' and __import__( "os" ).environ.get( "IECORE_FORCE_GLOBAL_SYMBOLS" ) == "1" : __import__( "sys" ).setdlopenflags( __import__( "sys" ).getdlopenflags() | __import__( "ctypes" ).RTLD_GLOBAL ) From 3dab74f4f175ee54b38d1856ae614e19418a1a9e Mon Sep 17 00:00:00 2001 From: Andrew Kaufman Date: Tue, 4 Jun 2019 15:38:26 -0700 Subject: [PATCH 2/5] IECoreMaya Plugin : Control RTLD_GLOBAL via an environment variable. --- src/IECoreMaya/plugin/Loader.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/IECoreMaya/plugin/Loader.cpp b/src/IECoreMaya/plugin/Loader.cpp index 04dbd55866..922c4a601b 100644 --- a/src/IECoreMaya/plugin/Loader.cpp +++ b/src/IECoreMaya/plugin/Loader.cpp @@ -51,7 +51,15 @@ IECORE_EXPORT MStatus initializePlugin( MObject obj ) std::string implName = pluginPath + "/impl/" + pluginName + ".so"; - g_libraryHandle = dlopen( implName.c_str(), RTLD_NOW | RTLD_GLOBAL ); + const char *forceGlobals = std::getenv( "IECORE_FORCE_GLOBAL_SYMBOLS" ); + if( forceGlobals && !strcmp( forceGlobals, "1" ) ) + { + g_libraryHandle = dlopen( implName.c_str(), RTLD_NOW | RTLD_GLOBAL ); + } + else + { + g_libraryHandle = dlopen( implName.c_str(), RTLD_NOW ); + } if (! g_libraryHandle ) { From 5778642db8bdf681c859f112eee174029527f490 Mon Sep 17 00:00:00 2001 From: Andrew Kaufman Date: Tue, 4 Jun 2019 15:35:19 -0700 Subject: [PATCH 3/5] IECoreHoudini Plugin : Control RTLD_GLOBAL via an environment variable. --- src/IECoreHoudini/plugin/Plugin.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/IECoreHoudini/plugin/Plugin.cpp b/src/IECoreHoudini/plugin/Plugin.cpp index 10e99ab90a..98931e732c 100644 --- a/src/IECoreHoudini/plugin/Plugin.cpp +++ b/src/IECoreHoudini/plugin/Plugin.cpp @@ -86,7 +86,11 @@ extern "C" { SYS_VISIBILITY_EXPORT void HoudiniDSOInit( UT_DSOInfo &dsoinfo ) { - dsoinfo.loadGlobal = true; + const char *forceGlobals = std::getenv( "IECORE_FORCE_GLOBAL_SYMBOLS" ); + if( forceGlobals && !strcmp( forceGlobals, "1" ) ) + { + dsoinfo.loadGlobal = true; + } } } From 8033e225f83abf5b56318d7a0813d5a5d18b271f Mon Sep 17 00:00:00 2001 From: Andrew Kaufman Date: Tue, 4 Jun 2019 16:34:09 -0700 Subject: [PATCH 4/5] IE Config : Respect IECORE_FORCE_GLOBAL_SYMBOLS during tests --- config/ie/options | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/ie/options b/config/ie/options index 986f5caedf..6904e7b3f7 100644 --- a/config/ie/options +++ b/config/ie/options @@ -389,7 +389,9 @@ envVarsToImport = ["PATH", "CORTEX_POINTDISTRIBUTION_TILESET", "OCIO", "IECORE_DEBUG_WAIT", - "CORTEX_PERFORMANCE_TEST"] + "CORTEX_PERFORMANCE_TEST", + "IECORE_FORCE_GLOBAL_SYMBOLS", +] ENV_VARS_TO_IMPORT= " ".join(envVarsToImport) From c0f860e5ee490beb4e2426473e89a548c22b963e Mon Sep 17 00:00:00 2001 From: Andrew Kaufman Date: Wed, 5 Jun 2019 10:49:13 -0700 Subject: [PATCH 5/5] IECore : Force RTLD_GLOBAL for imath We still need to use RTLD_GLOBAL when importing imath to avoid the following error: `TypeError: No to_python (by-value) converter found for C++ type: Imath_2_2::Vec2` --- python/IECore/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/python/IECore/__init__.py b/python/IECore/__init__.py index a247acbca3..b5c46bb5fe 100644 --- a/python/IECore/__init__.py +++ b/python/IECore/__init__.py @@ -53,7 +53,22 @@ __import__( "sys" ).getdlopenflags() | __import__( "ctypes" ).RTLD_GLOBAL ) -__import__( "imath" ) +try : + + # Make sure we import imath _with_ RTLD_GLOBAL. This avoids + # boost to_python (by-value) converter issues for imath types. + + import sys + import ctypes + originalDLOpenFlags = sys.getdlopenflags() + sys.setdlopenflags( originalDLOpenFlags | ctypes.RTLD_GLOBAL ) + + __import__( "imath" ) + +finally : + + sys.setdlopenflags( originalDLOpenFlags ) + del sys, ctypes, originalDLOpenFlags from _IECore import *