Skip to content

Allow opting out of RTLD_GLOBAL #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/ie/options
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
31 changes: 23 additions & 8 deletions python/IECore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,37 @@
#
# 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
)

__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 *

Expand Down
6 changes: 5 additions & 1 deletion src/IECoreHoudini/plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/IECoreMaya/plugin/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down