[Lldb-commits] [PATCH] D145547: When setting load addresses on darwin kernel kexts, handle case where in-memory load commands are not updated

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 7 22:33:35 PST 2023


jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

The Darwin kernel has a number of kernel extensions, kexts, akin to solibs to lldb.  We find the kext binary on disk, we create a MemoryModule from the in-memory image based on the Mach-O header and Mach-O load commands in memory.  The LC_SEGMENT vmaddrs for each segment in memory have been updated with their actual load addresses.  DynamicLoaderDarwinKernel uses the MemoryModule's Section "file" addresses to set the load addresses for the on-disk Module in the target.

There are some extensions that can be loaded into memory which won't have the Mach-O load commands with their load addresses updated.  So the MemoryModule has the original file addresses, instead of the actual in-memory load addresses. The current DynamicLoader code will then set the target section load addresses to the file addresses, which doesn't work.

This patch detects this by looking at the MemoryModule's Mach-O header (`__TEXT`) segment, and comparing its actual memory address we used to create the MemoryModule with the vmaddr ("file address") of the MemoryModule Section.  If they differ, this is one of those binaries that hasn't had its load commands updated when they were added to memory.

When this is detected, we assume all segments slide by a constant value, calculate that slide, and apply it to all the sections.  Normal kexts have their load addresses calculated as they always had been.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145547

Files:
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145547.503233.patch
Type: text/x-patch
Size: 5104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230308/345bbdd2/attachment-0001.bin>


More information about the lldb-commits mailing list