@@ -82,6 +82,8 @@ struct SharedCache::State
8282
8383struct SharedCache ::ViewSpecificState {
8484 std::mutex typeLibraryMutex;
85+ std::unordered_map<std::string, Ref<TypeLibrary>> typeLibraries;
86+
8587 std::mutex viewOperationsThatInfluenceMetadataMutex;
8688
8789 std::atomic<BNDSCViewLoadProgress> progress;
@@ -1906,21 +1908,7 @@ bool SharedCache::LoadImageWithInstallName(std::string installName, bool skipObj
19061908 return false ;
19071909 }
19081910
1909- std::unique_lock typelibLock (m_viewSpecificState->typeLibraryMutex );
1910- auto typeLib = m_dscView->GetTypeLibrary (header.installName );
1911-
1912- if (!typeLib)
1913- {
1914- auto typeLibs = m_dscView->GetDefaultPlatform ()->GetTypeLibrariesByName (header.installName );
1915- if (!typeLibs.empty ())
1916- {
1917- typeLib = typeLibs[0 ];
1918- m_dscView->AddTypeLibrary (typeLib);
1919- m_logger->LogInfo (" shared-cache: adding type library for '%s': %s (%s)" ,
1920- targetImage->installName .c_str (), typeLib->GetName ().c_str (), typeLib->GetGuid ().c_str ());
1921- }
1922- }
1923- typelibLock.unlock ();
1911+ auto typeLib = TypeLibraryForImage (header.installName );
19241912
19251913 SaveToDSCView ();
19261914
@@ -2955,6 +2943,24 @@ std::string SharedCache::SerializedImageHeaderForName(std::string name)
29552943 return " " ;
29562944}
29572945
2946+ Ref<TypeLibrary> SharedCache::TypeLibraryForImage (const std::string& installName) {
2947+ std::lock_guard lock (m_viewSpecificState->typeLibraryMutex );
2948+ if (auto it = m_viewSpecificState->typeLibraries .find (installName); it != m_viewSpecificState->typeLibraries .end ()) {
2949+ return it->second ;
2950+ }
2951+
2952+ auto typeLib = m_dscView->GetTypeLibrary (installName);
2953+ if (!typeLib) {
2954+ auto typeLibs = m_dscView->GetDefaultPlatform ()->GetTypeLibrariesByName (installName);
2955+ if (!typeLibs.empty ()) {
2956+ typeLib = typeLibs[0 ];
2957+ m_dscView->AddTypeLibrary (typeLib);
2958+ }
2959+ }
2960+
2961+ m_viewSpecificState->typeLibraries [installName] = typeLib;
2962+ return typeLib;
2963+ }
29582964
29592965void SharedCache::FindSymbolAtAddrAndApplyToAddr (
29602966 uint64_t symbolLocation, uint64_t targetLocation, bool triggerReanalysis)
@@ -2999,18 +3005,7 @@ void SharedCache::FindSymbolAtAddrAndApplyToAddr(
29993005 }
30003006 auto exportList = SharedCache::ParseExportTrie (mapping, *header);
30013007 std::vector<std::pair<uint64_t , std::pair<BNSymbolType, std::string>>> exportMapping;
3002- std::unique_lock lock (m_viewSpecificState->typeLibraryMutex );
3003- auto typeLib = m_dscView->GetTypeLibrary (header->installName );
3004- if (!typeLib)
3005- {
3006- auto typeLibs = m_dscView->GetDefaultPlatform ()->GetTypeLibrariesByName (header->installName );
3007- if (!typeLibs.empty ())
3008- {
3009- typeLib = typeLibs[0 ];
3010- m_dscView->AddTypeLibrary (typeLib);
3011- }
3012- }
3013- lock.unlock ();
3008+ auto typeLib = TypeLibraryForImage (header->installName );
30143009 id = m_dscView->BeginUndoActions ();
30153010 m_dscView->BeginBulkModifySymbols ();
30163011 for (const auto & sym : exportList)
0 commit comments