[PATCH] D132432: [llvm] Teach LLVM about filesets

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 22 21:43:23 PDT 2022


JDevlieghere created this revision.
JDevlieghere added reviewers: jasonmolenda, pete.
Herald added a subscriber: hiraditya.
Herald added a project: All.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.

Teach LLVM about filesets. Filesets were added in macOS 11 (Big Sur) to combine multiple Mach-O files. They consist of a load command (`LC_FILESET_ENTRY`) consisting of a `fileset_entry_command`.

  struct fileset_entry_command {
      uint32_t     cmd;        /* LC_FILESET_ENTRY */
      uint32_t     cmdsize;    /* includes entry_id string */
      uint64_t     vmaddr;     /* memory address of the entry */
      uint64_t     fileoff;    /* file offset of the entry */
      union lc_str entry_id;   /* contained entry id */
      uint32_t     reserved;   /* reserved */
  };

[1] https://github.com/apple-oss-distributions/xnu/blob/e7776783b89a353188416a9a346c6cdb4928faad/EXTERNAL_HEADERS/mach-o/loader.h#L326


https://reviews.llvm.org/D132432

Files:
  llvm/include/llvm/BinaryFormat/MachO.def
  llvm/include/llvm/BinaryFormat/MachO.h
  llvm/lib/ObjectYAML/MachOYAML.cpp


Index: llvm/lib/ObjectYAML/MachOYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/MachOYAML.cpp
+++ llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -613,6 +613,13 @@
   IO.mapRequired("ntools", LoadCommand.ntools);
 }
 
+void MappingTraits<MachO::fileset_entry_command>::mapping(
+    IO &IO, MachO::fileset_entry_command &LoadCommand) {
+  IO.mapRequired("vmaddr", LoadCommand.vmaddr);
+  IO.mapRequired("fileoff", LoadCommand.fileoff);
+  IO.mapRequired("id", LoadCommand.entry_id);
+}
+
 } // end namespace yaml
 
 } // end namespace llvm
Index: llvm/include/llvm/BinaryFormat/MachO.h
===================================================================
--- llvm/include/llvm/BinaryFormat/MachO.h
+++ llvm/include/llvm/BinaryFormat/MachO.h
@@ -50,7 +50,8 @@
   MH_BUNDLE = 0x8u,
   MH_DYLIB_STUB = 0x9u,
   MH_DSYM = 0xAu,
-  MH_KEXT_BUNDLE = 0xBu
+  MH_KEXT_BUNDLE = 0xBu,
+  MH_FILESET = 0xCu,
 };
 
 enum {
@@ -885,6 +886,14 @@
   uint32_t count;
 };
 
+struct fileset_entry_command {
+  uint32_t cmd;
+  uint32_t cmdsize;
+  uint64_t vmaddr;
+  uint64_t fileoff;
+  uint32_t entry_id;
+};
+
 // The symseg_command is obsolete and no longer supported.
 struct symseg_command {
   uint32_t cmd;
@@ -1363,6 +1372,14 @@
   sys::swapByteOrder(C.count);
 }
 
+inline void swapStruct(fileset_entry_command &C) {
+  sys::swapByteOrder(C.cmd);
+  sys::swapByteOrder(C.cmdsize);
+  sys::swapByteOrder(C.vmaddr);
+  sys::swapByteOrder(C.fileoff);
+  sys::swapByteOrder(C.entry_id);
+}
+
 inline void swapStruct(version_min_command &C) {
   sys::swapByteOrder(C.cmd);
   sys::swapByteOrder(C.cmdsize);
Index: llvm/include/llvm/BinaryFormat/MachO.def
===================================================================
--- llvm/include/llvm/BinaryFormat/MachO.def
+++ llvm/include/llvm/BinaryFormat/MachO.def
@@ -76,6 +76,7 @@
 HANDLE_LOAD_COMMAND(LC_BUILD_VERSION, 0x00000032u, build_version_command)
 HANDLE_LOAD_COMMAND(LC_DYLD_EXPORTS_TRIE, 0x80000033u, linkedit_data_command)
 HANDLE_LOAD_COMMAND(LC_DYLD_CHAINED_FIXUPS, 0x80000034u, linkedit_data_command)
+HANDLE_LOAD_COMMAND(LC_FILESET_ENTRY, 0x80000035u, fileset_entry_command)
 
 #endif
 
@@ -114,6 +115,7 @@
 LOAD_COMMAND_STRUCT(version_min_command)
 LOAD_COMMAND_STRUCT(note_command)
 LOAD_COMMAND_STRUCT(build_version_command)
+LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132432.454691.patch
Type: text/x-patch
Size: 2379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/15326048/attachment-0001.bin>


More information about the llvm-commits mailing list