[llvm] e854c17 - [llvm] Teach LLVM about filesets

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 09:33:59 PDT 2022


Author: Jonas Devlieghere
Date: 2022-08-24T09:33:45-07:00
New Revision: e854c17b02f8cd82a303d223ba5f3b0d87579cd7

URL: https://github.com/llvm/llvm-project/commit/e854c17b02f8cd82a303d223ba5f3b0d87579cd7
DIFF: https://github.com/llvm/llvm-project/commit/e854c17b02f8cd82a303d223ba5f3b0d87579cd7.diff

LOG: [llvm] Teach LLVM about filesets

Teach LLVM about filesets. Filesets were added in macOS 11 (Big Sur) to
combine multiple Mach-O files. They introduce a new 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 */
  };

This patch teaches LLVM about the new load command and the corresponding
data.

Differential revision: https://reviews.llvm.org/D132432

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/BinaryFormat/MachO.def b/llvm/include/llvm/BinaryFormat/MachO.def
index f68ecefa6c9e4..6d1ddda3bfa9a 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -76,6 +76,7 @@ HANDLE_LOAD_COMMAND(LC_NOTE, 0x00000031u, note_command)
 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(uuid_command)
 LOAD_COMMAND_STRUCT(version_min_command)
 LOAD_COMMAND_STRUCT(note_command)
 LOAD_COMMAND_STRUCT(build_version_command)
+LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 

diff  --git a/llvm/include/llvm/BinaryFormat/MachO.h b/llvm/include/llvm/BinaryFormat/MachO.h
index cdc8792e7b2d9..8fcaeb0eb1b05 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -50,7 +50,8 @@ enum HeaderFileType {
   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 @@ struct linker_option_command {
   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 @@ inline void swapStruct(linker_option_command &C) {
   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);

diff  --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp
index b6f3b53a42b3a..81b1d46c7c8e5 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -613,6 +613,13 @@ void MappingTraits<MachO::build_version_command>::mapping(
   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


        


More information about the llvm-commits mailing list