From 33a4e3b4706e6819f4471fc431436ec69bee1d33 Mon Sep 17 00:00:00 2001 From: Yan Shapochnik Date: Fri, 20 Apr 2012 08:41:18 -0400 Subject: [PATCH] Provide access to RTLD_NODELETE flag on Unix. Introduce a new QLibrary::PreventUnloadHint to support the RTLD_NODELETE flag support by dlcompat on Unix platforms. Change-Id: Ib1327e968a2a888850ad1086a102a143f86c5090 Reviewed-by: Thiago Macieira Reviewed-by: Giuseppe D'Angelo --- src/corelib/plugin/qlibrary.cpp | 6 ++++++ src/corelib/plugin/qlibrary.h | 3 ++- src/corelib/plugin/qlibrary_unix.cpp | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 7bb1ef12639..a704b8f02d3 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -163,6 +163,10 @@ static QBasicMutex qt_library_mutex; If this hint is given, the filename of the library consists of a path, which is a reference to an archive file, followed by a reference to the archive member. + \value PreventUnloadHint + 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. \sa loadHints */ @@ -1230,6 +1234,8 @@ QString QLibrary::errorString() const to the library \c shr_64.o in the archive file named \c libGL.a. This is only supported on the AIX platform. + Setting PreventUnloadHint will only apply on Unix platforms. + The interpretation of the load hints is platform dependent, and if you use it you are probably making some assumptions on which platform you are compiling for, so use them only if you understand the consequences diff --git a/src/corelib/plugin/qlibrary.h b/src/corelib/plugin/qlibrary.h index f373ad06b6f..80e6fd3d4ca 100644 --- a/src/corelib/plugin/qlibrary.h +++ b/src/corelib/plugin/qlibrary.h @@ -68,7 +68,8 @@ public: enum LoadHint { ResolveAllSymbolsHint = 0x01, ExportExternalSymbolsHint = 0x02, - LoadArchiveMemberHint = 0x04 + LoadArchiveMemberHint = 0x04, + PreventUnloadHint = 0x08 }; Q_DECLARE_FLAGS(LoadHints, LoadHint) diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index cb81440c7ef..0ad7a87c97a 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -167,6 +167,18 @@ bool QLibraryPrivate::load_sys() dlFlags |= RTLD_LOCAL; } #endif + + // Provide access to RTLD_NODELETE flag on Unix + // From GNU documentation on RTLD_NODELETE: + // Do not unload the library during dlclose(). Consequently, the + // library's specific static variables are not reinitialized if the + // library is reloaded with dlopen() at a later time. +#ifdef RTLD_NODELETE + if (loadHints & QLibrary::PreventUnloadHint) { + dlFlags |= RTLD_NODELETE; + } +#endif + #if defined(Q_OS_AIX) // Not sure if any other platform actually support this thing. if (loadHints & QLibrary::LoadArchiveMemberHint) { dlFlags |= RTLD_MEMBER;