Skip to content

Commit d455b6e

Browse files
committed
[SharedCache] Fix linear sweep picking up basically every function and removing it
1 parent 0ccc722 commit d455b6e

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

view/sharedcache/core/MachOProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void SharedCacheMachOProcessor::ApplyHeader(SharedCacheMachOHeader& header)
3535
auto targetPlatform = m_view->GetDefaultPlatform();
3636
auto functions = header.ReadFunctionTable(*m_vm);
3737
for (const auto& func : functions)
38-
m_view->AddFunctionForAnalysis(targetPlatform, func, true);
38+
m_view->AddFunctionForAnalysis(targetPlatform, func, false);
3939
}
4040

4141
auto typeLib = m_view->GetTypeLibrary(header.installName);

view/sharedcache/core/Utility.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,36 @@ void ApplySymbol(Ref<BinaryView> view, Ref<TypeLibrary> typeLib, Ref<Symbol> sym
7171
auto symbolAddress = symbol->GetAddress();
7272
auto symbolName = symbol->GetFullName();
7373

74-
if (symbol->GetType() == FunctionSymbol)
75-
{
76-
Ref<Platform> targetPlatform = view->GetDefaultPlatform();
77-
func = view->AddFunctionForAnalysis(targetPlatform, symbolAddress, true);
78-
}
74+
// Sometimes the symbol will be duplicated, so lets not do this work again.
75+
if (view->GetSymbolByAddress(symbolAddress))
76+
return;
7977

78+
// Define the symbol!
79+
view->DefineAutoSymbol(symbol);
80+
81+
// Try and pull a type to apply at the symbol location.
82+
Ref<Type> type = nullptr;
8083
if (typeLib)
84+
type = view->ImportTypeLibraryObject(typeLib, {symbolName});
85+
86+
if (symbol->GetType() == FunctionSymbol)
8187
{
82-
auto type = view->ImportTypeLibraryObject(typeLib, {symbolName});
83-
// TODO: This is still auto
84-
if (type)
85-
view->DefineAutoSymbolAndVariableOrFunction(view->GetDefaultPlatform(), symbol, type);
86-
else
87-
view->DefineAutoSymbol(symbol);
88+
Ref<Platform> targetPlatform = view->GetDefaultPlatform();
89+
// Make sure to check for already added function from the function table.
90+
// Unless we have retrieved a type here we don't need to make a new function.
91+
func = view->GetAnalysisFunction(targetPlatform, symbolAddress);
92+
if (!func || type)
93+
func = view->AddFunctionForAnalysis(targetPlatform, symbolAddress, false, type);
8894
}
8995
else
9096
{
91-
view->DefineAutoSymbol(symbol);
97+
// Other symbol types can just use this, they don't need to worry about linear sweep removing them.
98+
view->DefineAutoSymbolAndVariableOrFunction(view->GetDefaultPlatform(), symbol, type);
9299
}
93100

94-
if (!func)
95-
func = view->GetAnalysisFunction(view->GetDefaultPlatform(), symbolAddress);
96101
if (func)
97102
{
103+
// objective c type adjustment stuff.
98104
if (symbolName == "_objc_msgSend")
99105
{
100106
func->SetHasVariableArguments(false);

0 commit comments

Comments
 (0)