Skip to content

Commit

Permalink
[llvm] Teach LLVM about filesets
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JDevlieghere committed Aug 24, 2022
1 parent bb63d24 commit e854c17
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/MachO.def
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion llvm/include/llvm/BinaryFormat/MachO.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/ObjectYAML/MachOYAML.cpp
Expand Up @@ -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

0 comments on commit e854c17

Please sign in to comment.