From 96c40afe7296aba26ee7fb639517c7f16e137cc6 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 2 Apr 2025 05:31:24 -0400 Subject: [SharedCache] Fix linear sweep picking up basically every function and removing it --- view/sharedcache/core/Utility.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'view/sharedcache/core/Utility.cpp') diff --git a/view/sharedcache/core/Utility.cpp b/view/sharedcache/core/Utility.cpp index c4891930..396c3337 100644 --- a/view/sharedcache/core/Utility.cpp +++ b/view/sharedcache/core/Utility.cpp @@ -71,30 +71,36 @@ void ApplySymbol(Ref view, Ref typeLib, Ref sym auto symbolAddress = symbol->GetAddress(); auto symbolName = symbol->GetFullName(); - if (symbol->GetType() == FunctionSymbol) - { - Ref targetPlatform = view->GetDefaultPlatform(); - func = view->AddFunctionForAnalysis(targetPlatform, symbolAddress, true); - } + // Sometimes the symbol will be duplicated, so lets not do this work again. + if (view->GetSymbolByAddress(symbolAddress)) + return; + // Define the symbol! + view->DefineAutoSymbol(symbol); + + // Try and pull a type to apply at the symbol location. + Ref type = nullptr; if (typeLib) + type = view->ImportTypeLibraryObject(typeLib, {symbolName}); + + if (symbol->GetType() == FunctionSymbol) { - auto type = view->ImportTypeLibraryObject(typeLib, {symbolName}); - // TODO: This is still auto - if (type) - view->DefineAutoSymbolAndVariableOrFunction(view->GetDefaultPlatform(), symbol, type); - else - view->DefineAutoSymbol(symbol); + Ref targetPlatform = view->GetDefaultPlatform(); + // Make sure to check for already added function from the function table. + // Unless we have retrieved a type here we don't need to make a new function. + func = view->GetAnalysisFunction(targetPlatform, symbolAddress); + if (!func || type) + func = view->AddFunctionForAnalysis(targetPlatform, symbolAddress, false, type); } else { - view->DefineAutoSymbol(symbol); + // Other symbol types can just use this, they don't need to worry about linear sweep removing them. + view->DefineAutoSymbolAndVariableOrFunction(view->GetDefaultPlatform(), symbol, type); } - if (!func) - func = view->GetAnalysisFunction(view->GetDefaultPlatform(), symbolAddress); if (func) { + // objective c type adjustment stuff. if (symbolName == "_objc_msgSend") { func->SetHasVariableArguments(false); -- cgit v1.3.1