Created
November 19, 2025 20:18
-
-
Save EricRahm/42bc2c67f8593ba8a944312a3c5fd64c to your computer and use it in GitHub Desktop.
Diff of xnu loader.h and cctools loader.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- xnu/EXTERNAL_HEADERS/mach-o/loader.h 2025-11-19 20:10:52.970880191 +0000 | |
| +++ cctools/include/mach-o/loader.h 2025-11-19 20:00:11.438993179 +0000 | |
| @@ -1,5 +1,5 @@ | |
| /* | |
| - * Copyright (c) 1999-2019 Apple Inc. All Rights Reserved. | |
| + * Copyright (c) 1999-2010 Apple Inc. All Rights Reserved. | |
| * | |
| * @APPLE_LICENSE_HEADER_START@ | |
| * | |
| @@ -32,20 +32,28 @@ | |
| * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types | |
| * and contains the constants for the possible values of these types. | |
| */ | |
| +#if __has_include(<mach/machine.h>) | |
| #include <mach/machine.h> | |
| +#endif | |
| /* | |
| * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the | |
| * constants that are or'ed together for the possible values of this type. | |
| */ | |
| +#if __has_include(<mach/vm_prot.h>) | |
| #include <mach/vm_prot.h> | |
| +#endif | |
| /* | |
| * <machine/thread_status.h> is expected to define the flavors of the thread | |
| * states and the structures of those flavors for each machine. | |
| */ | |
| +#if __has_include(<mach/machine/thread_status.h>) | |
| #include <mach/machine/thread_status.h> | |
| +#endif | |
| +#if __has_include(<architecture/byte_order.h>) | |
| #include <architecture/byte_order.h> | |
| +#endif | |
| /* | |
| * The 32-bit mach header appears at the very beginning of the object file for | |
| @@ -53,8 +61,8 @@ | |
| */ | |
| struct mach_header { | |
| uint32_t magic; /* mach magic number identifier */ | |
| - cpu_type_t cputype; /* cpu specifier */ | |
| - cpu_subtype_t cpusubtype; /* machine specifier */ | |
| + int32_t cputype; /* cpu specifier */ | |
| + int32_t cpusubtype; /* machine specifier */ | |
| uint32_t filetype; /* type of file */ | |
| uint32_t ncmds; /* number of load commands */ | |
| uint32_t sizeofcmds; /* the size of all the load commands */ | |
| @@ -71,8 +79,8 @@ | |
| */ | |
| struct mach_header_64 { | |
| uint32_t magic; /* mach magic number identifier */ | |
| - cpu_type_t cputype; /* cpu specifier */ | |
| - cpu_subtype_t cpusubtype; /* machine specifier */ | |
| + int32_t cputype; /* cpu specifier */ | |
| + int32_t cpusubtype; /* machine specifier */ | |
| uint32_t filetype; /* type of file */ | |
| uint32_t ncmds; /* number of load commands */ | |
| uint32_t sizeofcmds; /* the size of all the load commands */ | |
| @@ -115,12 +123,17 @@ | |
| #define MH_DYLIB 0x6 /* dynamically bound shared library */ | |
| #define MH_DYLINKER 0x7 /* dynamic link editor */ | |
| #define MH_BUNDLE 0x8 /* dynamically bound bundle file */ | |
| -#define MH_DYLIB_STUB 0x9 /* shared library stub for static */ | |
| - /* linking only, no section contents */ | |
| -#define MH_DSYM 0xa /* companion file with only debug */ | |
| - /* sections */ | |
| +#define MH_DYLIB_STUB 0x9 /* shared library stub for static | |
| + linking only, no section contents */ | |
| +#define MH_DSYM 0xa /* companion file with only debug | |
| + sections */ | |
| #define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */ | |
| -#define MH_FILESET 0xc /* set of mach-o's */ | |
| +#define MH_FILESET 0xc /* a file composed of other Mach-Os to | |
| + be run in the same userspace sharing | |
| + a single linkedit. */ | |
| +#define MH_GPU_EXECUTE 0xd /* gpu program */ | |
| +#define MH_GPU_DYLIB 0xe /* gpu support functions */ | |
| + | |
| /* Constants for the flags field of the mach_header */ | |
| #define MH_NOUNDEFS 0x1 /* the object file has no undefined | |
| @@ -218,10 +231,15 @@ | |
| #define MH_SIM_SUPPORT 0x08000000 /* Allow LC_MIN_VERSION_MACOS and | |
| LC_BUILD_VERSION load commands with | |
| - the platforms macOS, iOSMac, | |
| + the platforms macOS, macCatalyst, | |
| iOSSimulator, tvOSSimulator and | |
| watchOSSimulator. */ | |
| +#define MH_IMPLICIT_PAGEZERO 0x10000000 /* main executable has no __PAGEZERO | |
| + segment. Instead, loader (xnu) | |
| + will load program high and block | |
| + out all memory below it. */ | |
| + | |
| #define MH_DYLIB_IN_CACHE 0x80000000 /* Only for use on dylibs. When this bit | |
| is set, the dylib is part of the dyld | |
| shared cache, rather than loose in | |
| @@ -323,7 +341,13 @@ | |
| #define LC_BUILD_VERSION 0x32 /* build for platform min OS version */ | |
| #define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD) /* used with linkedit_data_command, payload is trie */ | |
| #define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD) /* used with linkedit_data_command */ | |
| -#define LC_FILESET_ENTRY (0x35 | LC_REQ_DYLD) /* used with fileset_entry_command */ | |
| +#define LC_FILESET_ENTRY (0x35 | LC_REQ_DYLD) /* used with fileset_entry_command */ | |
| +#define LC_ATOM_INFO 0x36 /* used with linkedit_data_command */ | |
| +#define LC_FUNCTION_VARIANTS 0x37 /* used with linkedit_data_command */ | |
| +#define LC_FUNCTION_VARIANT_FIXUPS 0x38 /* used with linkedit_data_command */ | |
| +#define LC_TARGET_TRIPLE 0x39 /* target triple used to compile */ | |
| + | |
| + | |
| /* | |
| * A variable length string in a load command is represented by an lc_str | |
| @@ -360,8 +384,8 @@ | |
| uint32_t vmsize; /* memory size of this segment */ | |
| uint32_t fileoff; /* file offset of this segment */ | |
| uint32_t filesize; /* amount to map from the file */ | |
| - vm_prot_t maxprot; /* maximum VM protection */ | |
| - vm_prot_t initprot; /* initial VM protection */ | |
| + int32_t maxprot; /* maximum VM protection */ | |
| + int32_t initprot; /* initial VM protection */ | |
| uint32_t nsects; /* number of sections in segment */ | |
| uint32_t flags; /* flags */ | |
| }; | |
| @@ -380,8 +404,8 @@ | |
| uint64_t vmsize; /* memory size of this segment */ | |
| uint64_t fileoff; /* file offset of this segment */ | |
| uint64_t filesize; /* amount to map from the file */ | |
| - vm_prot_t maxprot; /* maximum VM protection */ | |
| - vm_prot_t initprot; /* initial VM protection */ | |
| + int32_t maxprot; /* maximum VM protection */ | |
| + int32_t initprot; /* initial VM protection */ | |
| uint32_t nsects; /* number of sections in segment */ | |
| uint32_t flags; /* flags */ | |
| }; | |
| @@ -624,9 +648,6 @@ | |
| /* option to ld(1) for MH_EXECUTE and */ | |
| /* FVMLIB file types only */ | |
| -#define SEG_LINKINFO "__LINKINFO" /* the segment overlapping with linkedit */ | |
| - /* containing linking information */ | |
| - | |
| #define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */ | |
| #define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */ | |
| @@ -659,7 +680,7 @@ | |
| }; | |
| /* | |
| - * Dynamicly linked shared libraries are identified by two things. The | |
| + * Dynamically linked shared libraries are identified by two things. The | |
| * pathname (the name of the library as found for execution), and the | |
| * compatibility version number. The pathname must match and the compatibility | |
| * number in the user of the library must be greater than or equal to the | |
| @@ -688,6 +709,30 @@ | |
| struct dylib dylib; /* the library identification */ | |
| }; | |
| + | |
| +/* | |
| + * An alternate encoding for: LC_LOAD_DYLIB. | |
| + * The flags field contains independent flags DYLIB_USE_* | |
| + * First supported in macOS 15, iOS 18. | |
| + */ | |
| +struct dylib_use_command { | |
| + uint32_t cmd; /* LC_LOAD_DYLIB or LC_LOAD_WEAK_DYLIB */ | |
| + uint32_t cmdsize; /* overall size, including path */ | |
| + uint32_t nameoff; /* == 28, dylibs's path offset */ | |
| + uint32_t marker; /* == DYLIB_USE_MARKER */ | |
| + uint32_t current_version; /* dylib's current version number */ | |
| + uint32_t compat_version; /* dylib's compatibility version number */ | |
| + uint32_t flags; /* DYLIB_USE_... flags */ | |
| +}; | |
| +#define DYLIB_USE_WEAK_LINK 0x01 | |
| +#define DYLIB_USE_REEXPORT 0x02 | |
| +#define DYLIB_USE_UPWARD 0x04 | |
| +#define DYLIB_USE_DELAYED_INIT 0x08 | |
| + | |
| +#define DYLIB_USE_MARKER 0x1a741800 | |
| + | |
| + | |
| + | |
| /* | |
| * A dynamically linked shared library may be a subframework of an umbrella | |
| * framework. If so it will be linked with "-umbrella umbrella_name" where | |
| @@ -1186,30 +1231,32 @@ | |
| }; | |
| /* | |
| + * The target_triple_command contains a string which specifies the | |
| + * target triple (e.g. "arm64e-apple-macosx15.0.0") used to compile the code. | |
| + */ | |
| +struct target_triple_command { | |
| + uint32_t cmd; /* LC_TARGET_TRIPLE */ | |
| + uint32_t cmdsize; /* including string */ | |
| + union lc_str triple; /* target triple string */ | |
| +}; | |
| + | |
| +/* | |
| * The linkedit_data_command contains the offsets and sizes of a blob | |
| * of data in the __LINKEDIT segment. | |
| */ | |
| struct linkedit_data_command { | |
| uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, | |
| - LC_FUNCTION_STARTS, LC_DATA_IN_CODE, | |
| - LC_DYLIB_CODE_SIGN_DRS, | |
| + LC_FUNCTION_STARTS, LC_DATA_IN_CODE, | |
| + LC_DYLIB_CODE_SIGN_DRS, LC_ATOM_INFO, | |
| LC_LINKER_OPTIMIZATION_HINT, | |
| - LC_DYLD_EXPORTS_TRIE, or | |
| + LC_DYLD_EXPORTS_TRIE, | |
| + LC_FUNCTION_VARIANTS, LC_FUNCTION_VARIANT_FIXUPS, or | |
| LC_DYLD_CHAINED_FIXUPS. */ | |
| uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */ | |
| uint32_t dataoff; /* file offset of data in __LINKEDIT segment */ | |
| uint32_t datasize; /* file size of data in __LINKEDIT segment */ | |
| }; | |
| -struct fileset_entry_command { | |
| - uint32_t cmd; /* LC_FILESET_ENTRY */ | |
| - uint32_t cmdsize; /* includes id string */ | |
| - uint64_t vmaddr; /* memory address of the dylib */ | |
| - uint64_t fileoff; /* file offset of the dylib */ | |
| - union lc_str entry_id; /* contained entry id */ | |
| - uint32_t reserved; /* entry_id is 32-bits long, so this is the reserved padding */ | |
| -}; | |
| - | |
| /* | |
| * The encryption_info_command contains the file offset and size of an | |
| * of an encrypted segment. | |
| @@ -1253,14 +1300,14 @@ | |
| }; | |
| /* | |
| - * The build_version_command contains the min OS version on which this | |
| + * The build_version_command contains the min OS version on which this | |
| * binary was built to run for its platform. The list of known platforms and | |
| * tool values following it. | |
| */ | |
| struct build_version_command { | |
| uint32_t cmd; /* LC_BUILD_VERSION */ | |
| uint32_t cmdsize; /* sizeof(struct build_version_command) plus */ | |
| - /* ntools * sizeof(struct build_tool_version) */ | |
| + /* ntools * sizeof(struct build_tool_version) */ | |
| uint32_t platform; /* platform */ | |
| uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ | |
| uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ | |
| @@ -1273,6 +1320,8 @@ | |
| }; | |
| /* Known values for the platform field above. */ | |
| +#define PLATFORM_UNKNOWN 0 | |
| +#define PLATFORM_ANY 0xFFFFFFFF | |
| #define PLATFORM_MACOS 1 | |
| #define PLATFORM_IOS 2 | |
| #define PLATFORM_TVOS 3 | |
| @@ -1283,13 +1332,41 @@ | |
| #define PLATFORM_TVOSSIMULATOR 8 | |
| #define PLATFORM_WATCHOSSIMULATOR 9 | |
| #define PLATFORM_DRIVERKIT 10 | |
| -#define PLATFORM_MAX PLATFORM_DRIVERKIT | |
| -/* Addition of simulated platfrom also needs to update proc_is_simulated() */ | |
| +#define PLATFORM_VISIONOS 11 | |
| +#define PLATFORM_VISIONOSSIMULATOR 12 | |
| + | |
| +#define PLATFORM_FIRMWARE 13 | |
| +#define PLATFORM_SEPOS 14 | |
| + | |
| +#define PLATFORM_MACOS_EXCLAVECORE 15 | |
| +#define PLATFORM_MACOS_EXCLAVEKIT 16 | |
| +#define PLATFORM_IOS_EXCLAVECORE 17 | |
| +#define PLATFORM_IOS_EXCLAVEKIT 18 | |
| +#define PLATFORM_TVOS_EXCLAVECORE 19 | |
| +#define PLATFORM_TVOS_EXCLAVEKIT 20 | |
| +#define PLATFORM_WATCHOS_EXCLAVECORE 21 | |
| +#define PLATFORM_WATCHOS_EXCLAVEKIT 22 | |
| +#define PLATFORM_VISIONOS_EXCLAVECORE 23 | |
| +#define PLATFORM_VISIONOS_EXCLAVEKIT 24 | |
| + | |
| + | |
| + | |
| /* Known values for the tool field above. */ | |
| #define TOOL_CLANG 1 | |
| #define TOOL_SWIFT 2 | |
| #define TOOL_LD 3 | |
| +#define TOOL_LLD 4 | |
| + | |
| +/* values for gpu tools (1024 to 1048) */ | |
| +#define TOOL_METAL 1024 | |
| +#define TOOL_AIRLLD 1025 | |
| +#define TOOL_AIRNT 1026 | |
| +#define TOOL_AIRNT_PLUGIN 1027 | |
| +#define TOOL_AIRPACK 1028 | |
| +#define TOOL_GPUARCHIVER 1031 | |
| +#define TOOL_METAL_FRAMEWORK 1032 | |
| + | |
| /* | |
| * The dyld_info_command contains the file offsets and sizes of | |
| @@ -1377,18 +1454,18 @@ | |
| * the exported symbol information for the string so far. | |
| * If there is no exported symbol, the node starts with a zero byte. | |
| * If there is exported info, it follows the length. | |
| - * | |
| - * First is a uleb128 containing flags. Normally, it is followed by | |
| + * | |
| + * First is a uleb128 containing flags. Normally, it is followed by | |
| * a uleb128 encoded offset which is location of the content named | |
| * by the symbol from the mach_header for the image. If the flags | |
| * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is | |
| * a uleb128 encoded library ordinal, then a zero terminated | |
| * UTF8 string. If the string is zero length, then the symbol | |
| * is re-export from the specified dylib with the same name. | |
| - * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following | |
| - * the flags is two uleb128s: the stub offset and the resolver offset. | |
| - * The stub is used by non-lazy pointers. The resolver is used | |
| - * by lazy pointers and must be called to get the actual address to use. | |
| + * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following | |
| + * the flags is two uleb128s: the stub offset and the resolver offset. | |
| + * The stub is used by non-lazy pointers. The resolver is used | |
| + * by lazy pointers and must be called to get the actual address to use. | |
| * | |
| * After the optional exported symbol information is a byte of | |
| * how many edges (0-255) that this node has leaving it, | |
| @@ -1468,6 +1545,8 @@ | |
| #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04 | |
| #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08 | |
| #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10 | |
| +#define EXPORT_SYMBOL_FLAGS_STATIC_RESOLVER 0x20 | |
| + | |
| /* | |
| * The linker_option_command contains linker options embedded in object files. | |
| @@ -1587,4 +1666,27 @@ | |
| uint64_t size; /* length of data region */ | |
| }; | |
| +/* | |
| + * LC_FILESET_ENTRY commands describe constituent Mach-O files that are part | |
| + * of a fileset. In one implementation, entries are dylibs with individual | |
| + * mach headers and repositionable text and data segments. Each entry is | |
| + * further described by its own mach header. | |
| + */ | |
| +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 */ | |
| +}; | |
| + | |
| +/* | |
| + * These deprecated values may still be used within Apple but are mechanically | |
| + * removed from public API. The mechanical process may produce unusual results. | |
| + */ | |
| +#if (!defined(PLATFORM_IOSMAC)) | |
| +#define PLATFORM_IOSMAC PLATFORM_MACCATALYST | |
| +#endif | |
| + | |
| #endif /* _MACHO_LOADER_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment