From b3ab7292931fe8fb0411b667de31c68988ce3c94 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 5 Apr 2018 08:14:23 +0100 Subject: If the function is in mergelib, store mergelib module Regression from commit 707f787cd991f9c59712cd3020d127d09605c792 It didn't ensure that we store mergelib when required, thus still trying to get function from stubs and failing (with mergelibs enabled), leading to SEGFAULT later. Change-Id: Ib15528795f3d65b1ae5c31be2aa5284ce5ff04cf Reviewed-on: https://gerrit.libreoffice.org/52428 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- vcl/source/window/builder.cxx | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index cc1bff6fc4c9..926549db5302 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -1223,27 +1223,32 @@ void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Wind } #ifndef DISABLE_DYNLOADING + extern "C" { static void thisModule() {} } -#endif // We store these forever, closing modules is non-ideal from a performance // perspective, code pages will be freed up by the OS anyway if unused for // a while in many cases, and this helps us pre-init. -typedef std::map> ModuleMap; +typedef std::map> ModuleMap; static ModuleMap g_aModuleMap; -static osl::Module g_aMergedLib; + +#if ENABLE_MERGELIBS +static std::shared_ptr g_pMergedLib = std::make_shared(); +#endif #ifndef SAL_DLLPREFIX # define SAL_DLLPREFIX "" #endif +#endif + void VclBuilder::preload() { #ifndef DISABLE_DYNLOADING #if ENABLE_MERGELIBS - g_aMergedLib.loadRelative(&thisModule, SVLIBRARY("merged")); -#endif + g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged")); +#else // find -name '*ui*' | xargs grep 'class=".*lo-' | // sed 's/.*class="//' | sed 's/-.*$//' | sort | uniq static const char *aWidgetLibs[] = { @@ -1266,6 +1271,7 @@ void VclBuilder::preload() else delete pModule; } +#endif // ENABLE_MERGELIBS #endif // DISABLE_DYNLOADING } @@ -1768,6 +1774,7 @@ VclPtr VclBuilder::makeObject(vcl::Window *pParent, const OString & { OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8)); + customMakeWidget pFunction = nullptr; #ifndef DISABLE_DYNLOADING OUStringBuffer sModuleBuf; sModuleBuf.append(SAL_DLLPREFIX); @@ -1778,21 +1785,26 @@ VclPtr VclBuilder::makeObject(vcl::Window *pParent, const OString & ModuleMap::iterator aI = g_aModuleMap.find(sModule); if (aI == g_aModuleMap.end()) { - osl::Module* pModule = new osl::Module; - bool ok = false; + std::shared_ptr pModule; #if ENABLE_MERGELIBS - if (!g_aMergedLib.is()) - g_aMergedLib.loadRelative(&thisModule, SVLIBRARY("merged")); - ok = g_aMergedLib.getFunctionSymbol(sFunction); + if (!g_pMergedLib->is()) + g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged")); + if ((pFunction = reinterpret_cast(g_pMergedLib->getFunctionSymbol(sFunction)))) + pModule = g_pMergedLib; #endif - if (!ok) - ok = pModule->loadRelative(&thisModule, sModule); - assert(ok && "bad module name in .ui"); - aI = g_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr(pModule))).first; + if (!pFunction) + { + pModule.reset(new osl::Module); + bool ok = pModule->loadRelative(&thisModule, sModule); + assert(ok && "bad module name in .ui"); + pFunction = reinterpret_cast(pModule->getFunctionSymbol(sFunction)); + } + g_aModuleMap.insert(std::make_pair(sModule, pModule)); } - customMakeWidget pFunction = reinterpret_cast(aI->second->getFunctionSymbol(sFunction)); + else + pFunction = reinterpret_cast(aI->second->getFunctionSymbol(sFunction)); #else - customMakeWidget pFunction = reinterpret_cast(osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData)); + pFunction = reinterpret_cast(osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData)); #endif if (pFunction) { -- cgit