[PATCH] D159294: [llvm-nm][MachO] Add support for `MH_FILESET`

Antonio Frighetto via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 31 09:24:56 PDT 2023


antoniofrighetto created this revision.
antoniofrighetto added reviewers: davide, JDevlieghere, jasonmolenda, pete, MaskRay.
Herald added a subscriber: hiraditya.
Herald added a reviewer: jhenderson.
Herald added a project: All.
antoniofrighetto requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch builds upon Jonas’ D132432 <https://reviews.llvm.org/D132432> and aims to support symbols printing of a `MH_FILESET` MachO within `llvm-nm`. Currently `llvm-nm` returns “no symbols” for a fileset; as a result, discerning the presence of symbols within MachO entries may require manual inspection of the binary. One concern is that, among other things, this might inadvertently lead to the improper assumption that symbols may have been stripped (as `LC_SYMTAB` of main MachO has no symbols). This patch addresses this issue by establishing whether symbols actually exist or not within each MachO entry.

One possible implementation is to specialize `dumpSymbolNamesFromObject` function to encompass fileset handling as well. While it may be slightly suboptimal to retain the entire MachO in memory for each `LC_FILESET_ENTRY`, this ensures accurate MachO parsing, let us extend `MachOObjectFile` constructor to include just an offset that locates each MachO entry from the file's start, and it makes the patch as non-invasive as possible. Also, this would be exceptionally done only for a specific type of MachO. Note that the MachO would still need to be parsed (at least) twice, once to determine the MachO type, and again to locate the `LC_SYMTAB` within the entry.


The test is a simple mock `MH_FILESET` binary, generated from an iOS kernelcache, and trimmed so as to preserve one load command (a `LC_FILESET_ENTRY`), another LC within a MachO entry (a `LC_SYMTAB`), and the actual symbol table.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159294

Files:
  llvm/include/llvm/BinaryFormat/MachO.h
  llvm/include/llvm/Object/MachO.h
  llvm/include/llvm/Object/ObjectFile.h
  llvm/lib/Object/MachOObjectFile.cpp
  llvm/lib/ObjectYAML/MachOYAML.cpp
  llvm/test/tools/llvm-nm/AArch64/Inputs/fileset.macho-aarch64
  llvm/test/tools/llvm-nm/AArch64/macho-fileset.test
  llvm/tools/llvm-nm/llvm-nm.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159294.555079.patch
Type: text/x-patch
Size: 15229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230831/a76718fb/attachment.bin>


More information about the llvm-commits mailing list