Add DeepBind option to QLibrary

Adds an option to request the RTLD_DEEPBIND flag to dlopen. On Linux
this can be used to force a library to resolve global symbols locally
instead of using the similarly named symbols already loaded.

This makes it possible to load and use plugins linked against Qt 4
without crashing.

[ChangeLog][QtCore][QLibrary] Added DeepBindHint which maps to RTLD_DEEPBIND
on Linux making it possible to load libraries with external symbols that
clash with already loaded ones, such as plugins linked to Qt4.

Change-Id: I4edb4af68e4a47e932a87d108360dba8d91dc34a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Allan Sandfeld Jensen 2014-10-21 11:15:55 +02:00 committed by Allan Sandfeld Jensen
parent f6eb3c220b
commit 864cf2a6cd
3 changed files with 11 additions and 1 deletions

View File

@ -168,6 +168,11 @@ QT_BEGIN_NAMESPACE
Prevents the library from being unloaded from the address space if close()
is called. The library's static variables are not reinitialized if open()
is called at a later time.
\value DeepBindHint
Instructs the linker to prefer definitions in the loaded library
over exported definitions in the loading application when resolving
external symbols in the loaded library. This option is only supported
on Linux.
\sa loadHints
*/

View File

@ -53,7 +53,8 @@ public:
ResolveAllSymbolsHint = 0x01,
ExportExternalSymbolsHint = 0x02,
LoadArchiveMemberHint = 0x04,
PreventUnloadHint = 0x08
PreventUnloadHint = 0x08,
DeepBindHint = 0x10
};
Q_DECLARE_FLAGS(LoadHints, LoadHint)

View File

@ -171,6 +171,10 @@ bool QLibraryPrivate::load_sys()
dlFlags |= RTLD_LOCAL;
}
#endif
#if defined(RTLD_DEEPBIND)
if (loadHints & QLibrary::DeepBindHint)
dlFlags |= RTLD_DEEPBIND;
#endif
// Provide access to RTLD_NODELETE flag on Unix
// From GNU documentation on RTLD_NODELETE: