Skip to content

Commit e854c17

Browse files
committed
[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
1 parent bb63d24 commit e854c17

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

llvm/include/llvm/BinaryFormat/MachO.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ HANDLE_LOAD_COMMAND(LC_NOTE, 0x00000031u, note_command)
7676
HANDLE_LOAD_COMMAND(LC_BUILD_VERSION, 0x00000032u, build_version_command)
7777
HANDLE_LOAD_COMMAND(LC_DYLD_EXPORTS_TRIE, 0x80000033u, linkedit_data_command)
7878
HANDLE_LOAD_COMMAND(LC_DYLD_CHAINED_FIXUPS, 0x80000034u, linkedit_data_command)
79+
HANDLE_LOAD_COMMAND(LC_FILESET_ENTRY, 0x80000035u, fileset_entry_command)
7980

8081
#endif
8182

@@ -114,6 +115,7 @@ LOAD_COMMAND_STRUCT(uuid_command)
114115
LOAD_COMMAND_STRUCT(version_min_command)
115116
LOAD_COMMAND_STRUCT(note_command)
116117
LOAD_COMMAND_STRUCT(build_version_command)
118+
LOAD_COMMAND_STRUCT(fileset_entry_command)
117119

118120
#endif
119121

llvm/include/llvm/BinaryFormat/MachO.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ enum HeaderFileType {
5050
MH_BUNDLE = 0x8u,
5151
MH_DYLIB_STUB = 0x9u,
5252
MH_DSYM = 0xAu,
53-
MH_KEXT_BUNDLE = 0xBu
53+
MH_KEXT_BUNDLE = 0xBu,
54+
MH_FILESET = 0xCu,
5455
};
5556

5657
enum {
@@ -885,6 +886,14 @@ struct linker_option_command {
885886
uint32_t count;
886887
};
887888

889+
struct fileset_entry_command {
890+
uint32_t cmd;
891+
uint32_t cmdsize;
892+
uint64_t vmaddr;
893+
uint64_t fileoff;
894+
uint32_t entry_id;
895+
};
896+
888897
// The symseg_command is obsolete and no longer supported.
889898
struct symseg_command {
890899
uint32_t cmd;
@@ -1363,6 +1372,14 @@ inline void swapStruct(linker_option_command &C) {
13631372
sys::swapByteOrder(C.count);
13641373
}
13651374

1375+
inline void swapStruct(fileset_entry_command &C) {
1376+
sys::swapByteOrder(C.cmd);
1377+
sys::swapByteOrder(C.cmdsize);
1378+
sys::swapByteOrder(C.vmaddr);
1379+
sys::swapByteOrder(C.fileoff);
1380+
sys::swapByteOrder(C.entry_id);
1381+
}
1382+
13661383
inline void swapStruct(version_min_command &C) {
13671384
sys::swapByteOrder(C.cmd);
13681385
sys::swapByteOrder(C.cmdsize);

llvm/lib/ObjectYAML/MachOYAML.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ void MappingTraits<MachO::build_version_command>::mapping(
613613
IO.mapRequired("ntools", LoadCommand.ntools);
614614
}
615615

616+
void MappingTraits<MachO::fileset_entry_command>::mapping(
617+
IO &IO, MachO::fileset_entry_command &LoadCommand) {
618+
IO.mapRequired("vmaddr", LoadCommand.vmaddr);
619+
IO.mapRequired("fileoff", LoadCommand.fileoff);
620+
IO.mapRequired("id", LoadCommand.entry_id);
621+
}
622+
616623
} // end namespace yaml
617624

618625
} // end namespace llvm

0 commit comments

Comments
 (0)