From 85d51eeefdca18ec9efe8c4b85d9e5b457ad9e11 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 11 May 2025 21:40:35 -0400 Subject: Misc shared cache improvements - Removed last use of user object creation in objective-c - Fixed function type info being omitted from certain images loaded automatically - Add TODO about undo action in view init. This is not critical, just a non-actionable warning because of a design flaw I will restate this again for anyone in the future, until the undo action system is thread-safe avoid calling it from any thread other than the main thread, it is very easy to deadlock or cause other issues. That goes for basically all user analysis object creation. --- objectivec/objc.cpp | 69 +++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 39 deletions(-) (limited to 'objectivec/objc.cpp') diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp index 46add246..f66c0a47 100644 --- a/objectivec/objc.cpp +++ b/objectivec/objc.cpp @@ -288,43 +288,38 @@ void ObjCProcessor::DefineObjCSymbol( new Symbol(type, shortName, fullName, name, addr, LocalBinding, nameSpace), typeRef); }; - if (deferred) - { - m_symbolQueue->Append(process, [this, addr = addr](Symbol* symbol, Type* type) { - // Armv7/Thumb: This will rewrite the symbol's address. - // e.g. We pass in 0xc001, it will rewrite it to 0xc000 and create the function w/ the "thumb2" arch. - if (Ref existingSymbol = m_data->GetSymbolByAddress(addr)) - m_data->UndefineAutoSymbol(existingSymbol); - auto funcSym = m_data->DefineAutoSymbolAndVariableOrFunction(m_data->GetDefaultPlatform(), symbol, type); - if (funcSym->GetType() == FunctionSymbol) - { - uint64_t target = symbol->GetAddress(); - Ref targetPlatform = - m_data->GetDefaultPlatform()->GetAssociatedPlatformByAddress(target); // rewrites target. - if (Ref targetFunction = m_data->GetAnalysisFunction(targetPlatform, target)) - { - if (!m_isBackedByDatabase) - targetFunction->SetUserType(type); - } - } - }); - return; - } + auto defineSymbol = [this](Ref symbol, Ref type) { + uint64_t symbolAddress = symbol->GetAddress(); + // Armv7/Thumb: This will rewrite the symbol's address. + // e.g. We pass in 0xc001, it will rewrite it to 0xc000 and create the function w/ the "thumb2" arch. + if (Ref existingSymbol = m_data->GetSymbolByAddress(symbolAddress)) + m_data->UndefineAutoSymbol(existingSymbol); + Ref targetPlatform = m_data->GetDefaultPlatform()->GetAssociatedPlatformByAddress(symbolAddress); + if (symbol->GetType() == FunctionSymbol) + { + // For thumb2 we want to get the adjusted address, we can do that using the target function. + Ref targetFunction = m_data->GetAnalysisFunction(targetPlatform, symbolAddress); + if (targetFunction && type) + targetFunction->ApplyAutoDiscoveredType(type); - if (Ref existingSymbol = m_data->GetSymbolByAddress(addr)) - m_data->UndefineAutoSymbol(existingSymbol); - auto result = process(); - auto sym = m_data->DefineAutoSymbolAndVariableOrFunction(m_data->GetDefaultPlatform(), result.first, result.second); - if (sym->GetType() == FunctionSymbol) - { - uint64_t target = result.first->GetAddress(); - Ref targetPlatform = m_data->GetDefaultPlatform()->GetAssociatedPlatformByAddress(target); // rewrites - // target. - if (Ref targetFunction = m_data->GetAnalysisFunction(targetPlatform, target)) + auto adjustedSym = new Symbol(FunctionSymbol, symbol->GetShortName(), symbol->GetFullName(), symbol->GetRawName(), symbolAddress); + m_data->DefineAutoSymbol(adjustedSym); + } + else { - if (!m_isBackedByDatabase) - targetFunction->SetUserType(result.second); + // Other symbol types can just use this, they don't need to worry about linear sweep removing them. + m_data->DefineAutoSymbolAndVariableOrFunction(targetPlatform, symbol, type); } + }; + + if (!deferred) + { + m_symbolQueue->Append(process, defineSymbol); + } + else + { + auto [symbol, type] = process(); + defineSymbol(symbol, type); } } @@ -1455,11 +1450,9 @@ void ObjCProcessor::ProcessObjCData() PostProcessObjCSections(reader.get()); - auto id = m_data->BeginUndoActions(); m_symbolQueue->Process(); m_data->EndBulkModifySymbols(); delete m_symbolQueue; - m_data->ForgetUndoActions(id); auto meta = SerializeMetadata(); m_data->StoreMetadata("Objective-C", meta, true); @@ -1577,12 +1570,10 @@ void ObjCProcessor::ProcessCFStrings() DefineObjCSymbol(DataSymbol, Type::NamedType(m_data, m_typeNames.cfString), "cfstr_" + str, i, true); } } - auto id = m_data->BeginUndoActions(); m_symbolQueue->Process(); m_data->EndBulkModifySymbols(); - m_data->ForgetUndoActions(id); + delete m_symbolQueue; } - delete m_symbolQueue; } void ObjCProcessor::AddRelocatedPointer(uint64_t location, uint64_t rewrite) -- cgit v1.3.1