summaryrefslogtreecommitdiff
path: root/view
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-09-12 13:41:50 -0700
committerMark Rowe <mark@vector35.com>2025-09-17 20:37:28 -0700
commitbdb62855f9b6cb85fcf64dba0a067d9056f09af5 (patch)
tree62b18b93bb78bea49709449b01efc0f2b00b4f51 /view
parenteabcd1c6ec928cb596faa043199069ce1a167e4f (diff)
[MachO] Populate external links with library imports for files in projects
A mapping from imported symbol names to libraries is added to metadata. This is used to populate external links for files within projects, following the lead of `PEView`.
Diffstat (limited to 'view')
-rw-r--r--view/macho/machoview.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/view/macho/machoview.cpp b/view/macho/machoview.cpp
index 1c65629a..52315485 100644
--- a/view/macho/machoview.cpp
+++ b/view/macho/machoview.cpp
@@ -790,6 +790,9 @@ MachOHeader MachoView::HeaderForAddress(BinaryView* data, uint64_t address, bool
}
break;
case LC_LOAD_DYLIB:
+ case LC_LOAD_WEAK_DYLIB:
+ case LC_REEXPORT_DYLIB:
+ case LC_LOAD_UPWARD_DYLIB:
{
uint32_t offset = reader.Read32();
reader.Read32(); // timestamp
@@ -2087,6 +2090,8 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
if (objcProcessor)
objcProcessor->AddRelocatedPointer(relocationLocation, slidTarget);
}
+
+ Ref<Metadata> symbolToLibraryMapping = new Metadata(KeyValueDataType);
for (auto& [relocation, name, ordinal] : header.bindingRelocations)
{
bool handled = false;
@@ -2149,6 +2154,8 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
DefineRelocation(m_arch, relocation, symbol, relocation.address);
handled = true;
}
+ if (ordinal - 1 < header.dylibs.size())
+ symbolToLibraryMapping->SetValueForKey(name, new Metadata(header.dylibs[ordinal - 1].first));
}
break;
}
@@ -2157,6 +2164,8 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_
m_logger->LogErrorF("Failed to find external symbol {:?}, couldn't bind symbol at {:#x}", name, relocation.address);
}
+ StoreMetadata("SymbolExternalLibraryMapping", std::move(symbolToLibraryMapping), true);
+
auto relocationHandler = m_arch->GetRelocationHandler("Mach-O");
if (relocationHandler)
{