Hi,
This is not related to kernel. I however couldn't find any dyld related forums. Please advice if this is not the right forum.
I came across this scenario when using C++ with classes marked visible which are defined in multiple dylibs as private extern.
e.g. exception classes from boost library which are defined in header files.
** Scenario
Main Executable
-> dlopen(dylib1, RTLD_LOCAL)
-> dlopen(dylib2, RTLD_LOCAL)
dylib1 is linked with dylib3 (dependency library).
Now, if there is a polymorphic class, e.g. exception class boost::bad_any_cast (derived from say std::exception) and is marked visible.
Another class, e.g. CustomException derived from bad_any_cast
If both the classes are defined as private extern in all of the three dylibs,
* when dylib1 is loaded, dylib3 is loaded by dyld as a dependency
* when dylib2 is loaded, RTTI for bad_any_cast in dylib2 does not work correctly.
Verified using
try
{
throw CustomException;
}
catch (const boost::bad_any_cast& )
{
//Control does not come here
}
catch (const std::exception &)
{
//Instead, control reaches here.
}
--------------------
If instead the dependency library dylib3 is loaded manually beforehand with RTLD_LOCAL, then the same scenario works as expected.
Main Executable
-> dlopen(dylib3, RTLD_LOCAL)
-> dlopen(dylib1, RTLD_LOCAL)
-> dlopen(dylib2, RTLD_LOCAL)
dylib1 is linked with dylib3 (dependency library).
--------------------
This suggests that dylib3 when implictly loaded by dyld as dependent library, the symbols are not kept private but instead exported in global lookup scope.