authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-13 11:19:19+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-15 08:59:20+01:00
logab328aca3365102cea95ea8c1f5e1e8ca8793dc5
tree74a6b41a1509ed28837ef901f87b913ccf101c67
parentff93486d0cbf032cbbf8b7953a072d448400ba2a

macho: put `LC_*` consts in a typed enum(u32) LC

repeat for `PLATFORM_*` and `TOOL_*` sets

6 files changed, 186 insertions(+), 184 deletions(-)

lib/std/debug.zig+4-4
......@@ -843,7 +843,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
843843 const symtab = while (ncmd != 0) : (ncmd -= 1) {
844844 const lc = @ptrCast(*const std.macho.load_command, ptr);
845845 switch (lc.cmd) {
846 std.macho.LC_SYMTAB => break @ptrCast(*const std.macho.symtab_command, ptr),
846 .SYMTAB => break @ptrCast(*const std.macho.symtab_command, ptr),
847847 else => {},
848848 }
849849 ptr = @alignCast(@alignOf(std.macho.load_command), ptr + lc.cmdsize);
......@@ -1072,7 +1072,7 @@ pub const DebugInfo = struct {
10721072 @alignCast(@alignOf(macho.load_command), cmd_ptr),
10731073 );
10741074 cmd_ptr += lc.cmdsize;
1075 if (lc.cmd != macho.LC_SEGMENT_64) continue;
1075 if (lc.cmd != .SEGMENT_64) continue;
10761076
10771077 const segment_cmd = @ptrCast(
10781078 *const std.macho.segment_command_64,
......@@ -1303,14 +1303,14 @@ pub const ModuleDebugInfo = switch (native_os) {
13031303 while (ncmd != 0) : (ncmd -= 1) {
13041304 const lc = @ptrCast(*const std.macho.load_command, ptr);
13051305 switch (lc.cmd) {
1306 std.macho.LC_SEGMENT_64 => {
1306 .SEGMENT_64 => {
13071307 segcmd = @ptrCast(
13081308 *const std.macho.segment_command_64,
13091309 @alignCast(@alignOf(std.macho.segment_command_64), ptr),
13101310 );
13111311 segptr = ptr;
13121312 },
1313 std.macho.LC_SYMTAB => {
1313 .SYMTAB => {
13141314 symtabcmd = @ptrCast(
13151315 *const std.macho.symtab_command,
13161316 @alignCast(@alignOf(std.macho.symtab_command), ptr),
lib/std/macho.zig+162-152
......@@ -43,7 +43,7 @@ pub const fat_arch = extern struct {
4343};
4444
4545pub const load_command = extern struct {
46 cmd: u32,
46 cmd: LC,
4747 cmdsize: u32,
4848};
4949
......@@ -51,7 +51,7 @@ pub const load_command = extern struct {
5151/// identifies an object produced by the static link editor.
5252pub const uuid_command = extern struct {
5353 /// LC_UUID
54 cmd: u32,
54 cmd: LC = .UUID,
5555
5656 /// sizeof(struct uuid_command)
5757 cmdsize: u32,
......@@ -64,7 +64,7 @@ pub const uuid_command = extern struct {
6464/// binary was built to run.
6565pub const version_min_command = extern struct {
6666 /// LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS or LC_VERSION_MIN_WATCHOS or LC_VERSION_MIN_TVOS
67 cmd: u32,
67 cmd: LC,
6868
6969 /// sizeof(struct version_min_command)
7070 cmdsize: u32,
......@@ -80,7 +80,7 @@ pub const version_min_command = extern struct {
8080/// the version of the sources used to build the binary.
8181pub const source_version_command = extern struct {
8282 /// LC_SOURCE_VERSION
83 cmd: u32,
83 cmd: LC = .SOURCE_VERSION,
8484
8585 /// sizeof(source_version_command)
8686 cmdsize: u32,
......@@ -94,14 +94,14 @@ pub const source_version_command = extern struct {
9494/// tool values following it.
9595pub const build_version_command = extern struct {
9696 /// LC_BUILD_VERSION
97 cmd: u32,
97 cmd: LC = .BUILD_VERSION,
9898
9999 /// sizeof(struct build_version_command) plus
100100 /// ntools * sizeof(struct build_version_command)
101101 cmdsize: u32,
102102
103103 /// platform
104 platform: u32,
104 platform: PLATFORM,
105105
106106 /// X.Y.Z is encoded in nibbles xxxx.yy.zz
107107 minos: u32,
......@@ -115,26 +115,32 @@ pub const build_version_command = extern struct {
115115
116116pub const build_tool_version = extern struct {
117117 /// enum for the tool
118 tool: u32,
118 tool: TOOL,
119119
120120 /// version number of the tool
121121 version: u32,
122122};
123123
124pub const PLATFORM_MACOS: u32 = 0x1;
125pub const PLATFORM_IOS: u32 = 0x2;
126pub const PLATFORM_TVOS: u32 = 0x3;
127pub const PLATFORM_WATCHOS: u32 = 0x4;
128pub const PLATFORM_BRIDGEOS: u32 = 0x5;
129pub const PLATFORM_MACCATALYST: u32 = 0x6;
130pub const PLATFORM_IOSSIMULATOR: u32 = 0x7;
131pub const PLATFORM_TVOSSIMULATOR: u32 = 0x8;
132pub const PLATFORM_WATCHOSSIMULATOR: u32 = 0x9;
133pub const PLATFORM_DRIVERKIT: u32 = 0x10;
134
135pub const TOOL_CLANG: u32 = 0x1;
136pub const TOOL_SWIFT: u32 = 0x2;
137pub const TOOL_LD: u32 = 0x3;
124pub const PLATFORM = enum(u32) {
125 MACOS = 0x1,
126 IOS = 0x2,
127 TVOS = 0x3,
128 WATCHOS = 0x4,
129 BRIDGEOS = 0x5,
130 MACCATALYST = 0x6,
131 IOSSIMULATOR = 0x7,
132 TVOSSIMULATOR = 0x8,
133 WATCHOSSIMULATOR = 0x9,
134 DRIVERKIT = 0x10,
135 _,
136};
137
138pub const TOOL = enum(u32) {
139 CLANG = 0x1,
140 SWIFT = 0x2,
141 LD = 0x3,
142 _,
143};
138144
139145/// The entry_point_command is a replacement for thread_command.
140146/// It is used for main executables to specify the location (file offset)
......@@ -142,7 +148,7 @@ pub const TOOL_LD: u32 = 0x3;
142148/// field will contain the stack size needed for the main thread.
143149pub const entry_point_command = extern struct {
144150 /// LC_MAIN only used in MH_EXECUTE filetypes
145 cmd: u32,
151 cmd: LC = .MAIN,
146152
147153 /// sizeof(struct entry_point_command)
148154 cmdsize: u32,
......@@ -159,7 +165,7 @@ pub const entry_point_command = extern struct {
159165/// <nlist.h> and <stab.h>.
160166pub const symtab_command = extern struct {
161167 /// LC_SYMTAB
162 cmd: u32,
168 cmd: LC = .SYMTAB,
163169
164170 /// sizeof(struct symtab_command)
165171 cmdsize: u32,
......@@ -217,7 +223,7 @@ pub const symtab_command = extern struct {
217223/// off the section structures.
218224pub const dysymtab_command = extern struct {
219225 /// LC_DYSYMTAB
220 cmd: u32,
226 cmd: LC = .DYSYMTAB,
221227
222228 /// sizeof(struct dysymtab_command)
223229 cmdsize: u32,
......@@ -357,7 +363,7 @@ pub const dysymtab_command = extern struct {
357363/// of data in the __LINKEDIT segment.
358364pub const linkedit_data_command = extern struct {
359365 /// LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_DYLIB_CODE_SIGN_DRS or LC_LINKER_OPTIMIZATION_HINT.
360 cmd: u32,
366 cmd: LC,
361367
362368 /// sizeof(struct linkedit_data_command)
363369 cmdsize: u32,
......@@ -377,7 +383,7 @@ pub const linkedit_data_command = extern struct {
377383/// to interpret it.
378384pub const dyld_info_command = extern struct {
379385 /// LC_DYLD_INFO or LC_DYLD_INFO_ONLY
380 cmd: u32,
386 cmd: LC,
381387
382388 /// sizeof(struct dyld_info_command)
383389 cmdsize: u32,
......@@ -498,7 +504,7 @@ pub const dyld_info_command = extern struct {
498504/// string for dyld to treat like an environment variable.
499505pub const dylinker_command = extern struct {
500506 /// LC_ID_DYLINKER, LC_LOAD_DYLINKER, or LC_DYLD_ENVIRONMENT
501 cmd: u32,
507 cmd: LC,
502508
503509 /// includes pathname string
504510 cmdsize: u32,
......@@ -519,7 +525,7 @@ pub const dylinker_command = extern struct {
519525/// LC_REEXPORT_DYLIB) for each library it uses.
520526pub const dylib_command = extern struct {
521527 /// LC_ID_DYLIB, LC_LOAD_WEAK_DYLIB, LC_LOAD_DYLIB, LC_REEXPORT_DYLIB
522 cmd: u32,
528 cmd: LC,
523529
524530 /// includes pathname string
525531 cmdsize: u32,
......@@ -553,7 +559,7 @@ pub const dylib = extern struct {
553559/// run path used to find @rpath prefixed dylibs.
554560pub const rpath_command = extern struct {
555561 /// LC_RPATH
556 cmd: u32,
562 cmd: LC = .RPATH,
557563
558564 /// includes string
559565 cmdsize: u32,
......@@ -574,7 +580,7 @@ pub const rpath_command = extern struct {
574580/// reflected in cmdsize.
575581pub const segment_command = extern struct {
576582 /// LC_SEGMENT
577 cmd: u32,
583 cmd: LC = .SEGMENT,
578584
579585 /// includes sizeof section structs
580586 cmdsize: u32,
......@@ -611,7 +617,7 @@ pub const segment_command = extern struct {
611617/// command and their size is reflected in cmdsize.
612618pub const segment_command_64 = extern struct {
613619 /// LC_SEGMENT_64
614 cmd: u32 = LC_SEGMENT_64,
620 cmd: LC = .SEGMENT_64,
615621
616622 /// includes sizeof section_64 structs
617623 cmdsize: u32 = @sizeOf(segment_command_64),
......@@ -882,159 +888,163 @@ pub const relocation_info = packed struct {
882888/// simply be ignored.
883889pub const LC_REQ_DYLD = 0x80000000;
884890
885/// segment of this file to be mapped
886pub const LC_SEGMENT = 0x1;
891pub const LC = enum(u32) {
892 /// segment of this file to be mapped
893 SEGMENT = 0x1,
887894
888/// link-edit stab symbol table info
889pub const LC_SYMTAB = 0x2;
895 /// link-edit stab symbol table info
896 SYMTAB = 0x2,
890897
891/// link-edit gdb symbol table info (obsolete)
892pub const LC_SYMSEG = 0x3;
898 /// link-edit gdb symbol table info (obsolete)
899 SYMSEG = 0x3,
893900
894/// thread
895pub const LC_THREAD = 0x4;
901 /// thread
902 THREAD = 0x4,
896903
897/// unix thread (includes a stack)
898pub const LC_UNIXTHREAD = 0x5;
904 /// unix thread (includes a stack)
905 UNIXTHREAD = 0x5,
899906
900/// load a specified fixed VM shared library
901pub const LC_LOADFVMLIB = 0x6;
907 /// load a specified fixed VM shared library
908 LOADFVMLIB = 0x6,
902909
903/// fixed VM shared library identification
904pub const LC_IDFVMLIB = 0x7;
910 /// fixed VM shared library identification
911 IDFVMLIB = 0x7,
905912
906/// object identification info (obsolete)
907pub const LC_IDENT = 0x8;
913 /// object identification info (obsolete)
914 IDENT = 0x8,
908915
909/// fixed VM file inclusion (internal use)
910pub const LC_FVMFILE = 0x9;
916 /// fixed VM file inclusion (internal use)
917 FVMFILE = 0x9,
911918
912/// prepage command (internal use)
913pub const LC_PREPAGE = 0xa;
919 /// prepage command (internal use)
920 PREPAGE = 0xa,
914921
915/// dynamic link-edit symbol table info
916pub const LC_DYSYMTAB = 0xb;
922 /// dynamic link-edit symbol table info
923 DYSYMTAB = 0xb,
917924
918/// load a dynamically linked shared library
919pub const LC_LOAD_DYLIB = 0xc;
925 /// load a dynamically linked shared library
926 LOAD_DYLIB = 0xc,
920927
921/// dynamically linked shared lib ident
922pub const LC_ID_DYLIB = 0xd;
928 /// dynamically linked shared lib ident
929 ID_DYLIB = 0xd,
923930
924/// load a dynamic linker
925pub const LC_LOAD_DYLINKER = 0xe;
931 /// load a dynamic linker
932 LOAD_DYLINKER = 0xe,
926933
927/// dynamic linker identification
928pub const LC_ID_DYLINKER = 0xf;
934 /// dynamic linker identification
935 ID_DYLINKER = 0xf,
929936
930/// modules prebound for a dynamically
931pub const LC_PREBOUND_DYLIB = 0x10;
937 /// modules prebound for a dynamically
938 PREBOUND_DYLIB = 0x10,
932939
933/// image routines
934pub const LC_ROUTINES = 0x11;
940 /// image routines
941 ROUTINES = 0x11,
935942
936/// sub framework
937pub const LC_SUB_FRAMEWORK = 0x12;
943 /// sub framework
944 SUB_FRAMEWORK = 0x12,
938945
939/// sub umbrella
940pub const LC_SUB_UMBRELLA = 0x13;
946 /// sub umbrella
947 SUB_UMBRELLA = 0x13,
941948
942/// sub client
943pub const LC_SUB_CLIENT = 0x14;
949 /// sub client
950 SUB_CLIENT = 0x14,
944951
945/// sub library
946pub const LC_SUB_LIBRARY = 0x15;
952 /// sub library
953 SUB_LIBRARY = 0x15,
947954
948/// two-level namespace lookup hints
949pub const LC_TWOLEVEL_HINTS = 0x16;
955 /// two-level namespace lookup hints
956 TWOLEVEL_HINTS = 0x16,
950957
951/// prebind checksum
952pub const LC_PREBIND_CKSUM = 0x17;
958 /// prebind checksum
959 PREBIND_CKSUM = 0x17,
953960
954/// load a dynamically linked shared library that is allowed to be missing
955/// (all symbols are weak imported).
956pub const LC_LOAD_WEAK_DYLIB = (0x18 | LC_REQ_DYLD);
961 /// load a dynamically linked shared library that is allowed to be missing
962 /// (all symbols are weak imported).
963 LOAD_WEAK_DYLIB = (0x18 | LC_REQ_DYLD),
957964
958/// 64-bit segment of this file to be mapped
959pub const LC_SEGMENT_64 = 0x19;
965 /// 64-bit segment of this file to be mapped
966 SEGMENT_64 = 0x19,
960967
961/// 64-bit image routines
962pub const LC_ROUTINES_64 = 0x1a;
968 /// 64-bit image routines
969 ROUTINES_64 = 0x1a,
963970
964/// the uuid
965pub const LC_UUID = 0x1b;
971 /// the uuid
972 UUID = 0x1b,
966973
967/// runpath additions
968pub const LC_RPATH = (0x1c | LC_REQ_DYLD);
974 /// runpath additions
975 RPATH = (0x1c | LC_REQ_DYLD),
969976
970/// local of code signature
971pub const LC_CODE_SIGNATURE = 0x1d;
977 /// local of code signature
978 CODE_SIGNATURE = 0x1d,
972979
973/// local of info to split segments
974pub const LC_SEGMENT_SPLIT_INFO = 0x1e;
980 /// local of info to split segments
981 SEGMENT_SPLIT_INFO = 0x1e,
975982
976/// load and re-export dylib
977pub const LC_REEXPORT_DYLIB = (0x1f | LC_REQ_DYLD);
983 /// load and re-export dylib
984 REEXPORT_DYLIB = (0x1f | LC_REQ_DYLD),
978985
979/// delay load of dylib until first use
980pub const LC_LAZY_LOAD_DYLIB = 0x20;
986 /// delay load of dylib until first use
987 LAZY_LOAD_DYLIB = 0x20,
981988
982/// encrypted segment information
983pub const LC_ENCRYPTION_INFO = 0x21;
989 /// encrypted segment information
990 ENCRYPTION_INFO = 0x21,
984991
985/// compressed dyld information
986pub const LC_DYLD_INFO = 0x22;
992 /// compressed dyld information
993 DYLD_INFO = 0x22,
987994
988/// compressed dyld information only
989pub const LC_DYLD_INFO_ONLY = (0x22 | LC_REQ_DYLD);
995 /// compressed dyld information only
996 DYLD_INFO_ONLY = (0x22 | LC_REQ_DYLD),
990997
991/// load upward dylib
992pub const LC_LOAD_UPWARD_DYLIB = (0x23 | LC_REQ_DYLD);
998 /// load upward dylib
999 LOAD_UPWARD_DYLIB = (0x23 | LC_REQ_DYLD),
9931000
994/// build for MacOSX min OS version
995pub const LC_VERSION_MIN_MACOSX = 0x24;
1001 /// build for MacOSX min OS version
1002 VERSION_MIN_MACOSX = 0x24,
9961003
997/// build for iPhoneOS min OS version
998pub const LC_VERSION_MIN_IPHONEOS = 0x25;
1004 /// build for iPhoneOS min OS version
1005 VERSION_MIN_IPHONEOS = 0x25,
9991006
1000/// compressed table of function start addresses
1001pub const LC_FUNCTION_STARTS = 0x26;
1007 /// compressed table of function start addresses
1008 FUNCTION_STARTS = 0x26,
10021009
1003/// string for dyld to treat like environment variable
1004pub const LC_DYLD_ENVIRONMENT = 0x27;
1010 /// string for dyld to treat like environment variable
1011 DYLD_ENVIRONMENT = 0x27,
10051012
1006/// replacement for LC_UNIXTHREAD
1007pub const LC_MAIN = (0x28 | LC_REQ_DYLD);
1013 /// replacement for LC_UNIXTHREAD
1014 MAIN = (0x28 | LC_REQ_DYLD),
10081015
1009/// table of non-instructions in __text
1010pub const LC_DATA_IN_CODE = 0x29;
1016 /// table of non-instructions in __text
1017 DATA_IN_CODE = 0x29,
10111018
1012/// source version used to build binary
1013pub const LC_SOURCE_VERSION = 0x2A;
1019 /// source version used to build binary
1020 SOURCE_VERSION = 0x2A,
10141021
1015/// Code signing DRs copied from linked dylibs
1016pub const LC_DYLIB_CODE_SIGN_DRS = 0x2B;
1022 /// Code signing DRs copied from linked dylibs
1023 DYLIB_CODE_SIGN_DRS = 0x2B,
10171024
1018/// 64-bit encrypted segment information
1019pub const LC_ENCRYPTION_INFO_64 = 0x2C;
1025 /// 64-bit encrypted segment information
1026 ENCRYPTION_INFO_64 = 0x2C,
10201027
1021/// linker options in MH_OBJECT files
1022pub const LC_LINKER_OPTION = 0x2D;
1028 /// linker options in MH_OBJECT files
1029 LINKER_OPTION = 0x2D,
10231030
1024/// optimization hints in MH_OBJECT files
1025pub const LC_LINKER_OPTIMIZATION_HINT = 0x2E;
1031 /// optimization hints in MH_OBJECT files
1032 LINKER_OPTIMIZATION_HINT = 0x2E,
10261033
1027/// build for AppleTV min OS version
1028pub const LC_VERSION_MIN_TVOS = 0x2F;
1034 /// build for AppleTV min OS version
1035 VERSION_MIN_TVOS = 0x2F,
10291036
1030/// build for Watch min OS version
1031pub const LC_VERSION_MIN_WATCHOS = 0x30;
1037 /// build for Watch min OS version
1038 VERSION_MIN_WATCHOS = 0x30,
10321039
1033/// arbitrary data included within a Mach-O file
1034pub const LC_NOTE = 0x31;
1040 /// arbitrary data included within a Mach-O file
1041 NOTE = 0x31,
10351042
1036/// build for platform min OS version
1037pub const LC_BUILD_VERSION = 0x32;
1043 /// build for platform min OS version
1044 BUILD_VERSION = 0x32,
1045
1046 _,
1047};
10381048
10391049/// the mach magic number
10401050pub const MH_MAGIC = 0xfeedface;
......@@ -1537,7 +1547,7 @@ pub const reloc_type_x86_64 = enum(u4) {
15371547
15381548pub const reloc_type_arm64 = enum(u4) {
15391549 /// For pointers.
1540 ARM64_RELOC_UNSIGNED,
1550 ARM64_RELOC_UNSIGNED = 0,
15411551
15421552 /// Must be followed by a ARM64_RELOC_UNSIGNED.
15431553 ARM64_RELOC_SUBTRACTOR,
......@@ -1840,43 +1850,43 @@ pub const LoadCommand = union(enum) {
18401850 var stream = io.fixedBufferStream(buffer);
18411851
18421852 return switch (header.cmd) {
1843 LC_SEGMENT_64 => LoadCommand{
1853 .SEGMENT_64 => LoadCommand{
18441854 .segment = try SegmentCommand.read(allocator, stream.reader()),
18451855 },
1846 LC_DYLD_INFO, LC_DYLD_INFO_ONLY => LoadCommand{
1856 .DYLD_INFO, .DYLD_INFO_ONLY => LoadCommand{
18471857 .dyld_info_only = try stream.reader().readStruct(dyld_info_command),
18481858 },
1849 LC_SYMTAB => LoadCommand{
1859 .SYMTAB => LoadCommand{
18501860 .symtab = try stream.reader().readStruct(symtab_command),
18511861 },
1852 LC_DYSYMTAB => LoadCommand{
1862 .DYSYMTAB => LoadCommand{
18531863 .dysymtab = try stream.reader().readStruct(dysymtab_command),
18541864 },
1855 LC_ID_DYLINKER, LC_LOAD_DYLINKER, LC_DYLD_ENVIRONMENT => LoadCommand{
1865 .ID_DYLINKER, .LOAD_DYLINKER, .DYLD_ENVIRONMENT => LoadCommand{
18561866 .dylinker = try GenericCommandWithData(dylinker_command).read(allocator, stream.reader()),
18571867 },
1858 LC_ID_DYLIB, LC_LOAD_WEAK_DYLIB, LC_LOAD_DYLIB, LC_REEXPORT_DYLIB => LoadCommand{
1868 .ID_DYLIB, .LOAD_WEAK_DYLIB, .LOAD_DYLIB, .REEXPORT_DYLIB => LoadCommand{
18591869 .dylib = try GenericCommandWithData(dylib_command).read(allocator, stream.reader()),
18601870 },
1861 LC_MAIN => LoadCommand{
1871 .MAIN => LoadCommand{
18621872 .main = try stream.reader().readStruct(entry_point_command),
18631873 },
1864 LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_WATCHOS, LC_VERSION_MIN_TVOS => LoadCommand{
1874 .VERSION_MIN_MACOSX, .VERSION_MIN_IPHONEOS, .VERSION_MIN_WATCHOS, .VERSION_MIN_TVOS => LoadCommand{
18651875 .version_min = try stream.reader().readStruct(version_min_command),
18661876 },
1867 LC_SOURCE_VERSION => LoadCommand{
1877 .SOURCE_VERSION => LoadCommand{
18681878 .source_version = try stream.reader().readStruct(source_version_command),
18691879 },
1870 LC_BUILD_VERSION => LoadCommand{
1880 .BUILD_VERSION => LoadCommand{
18711881 .build_version = try GenericCommandWithData(build_version_command).read(allocator, stream.reader()),
18721882 },
1873 LC_UUID => LoadCommand{
1883 .UUID => LoadCommand{
18741884 .uuid = try stream.reader().readStruct(uuid_command),
18751885 },
1876 LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_CODE_SIGNATURE => LoadCommand{
1886 .FUNCTION_STARTS, .DATA_IN_CODE, .CODE_SIGNATURE => LoadCommand{
18771887 .linkedit_data = try stream.reader().readStruct(linkedit_data_command),
18781888 },
1879 LC_RPATH => LoadCommand{
1889 .RPATH => LoadCommand{
18801890 .rpath = try GenericCommandWithData(rpath_command).read(allocator, stream.reader()),
18811891 },
18821892 else => LoadCommand{
......@@ -1904,7 +1914,7 @@ pub const LoadCommand = union(enum) {
19041914 };
19051915 }
19061916
1907 pub fn cmd(self: LoadCommand) u32 {
1917 pub fn cmd(self: LoadCommand) LC {
19081918 return switch (self) {
19091919 .dyld_info_only => |x| x.cmd,
19101920 .symtab => |x| x.cmd,
......@@ -2078,7 +2088,7 @@ pub fn createLoadDylibCommand(
20782088 ));
20792089
20802090 var dylib_cmd = emptyGenericCommandWithData(dylib_command{
2081 .cmd = LC_LOAD_DYLIB,
2091 .cmd = .LOAD_DYLIB,
20822092 .cmdsize = cmdsize,
20832093 .dylib = .{
20842094 .name = @sizeOf(dylib_command),
......@@ -2189,7 +2199,7 @@ test "read-write generic command with data" {
21892199 };
21902200 var cmd = GenericCommandWithData(dylib_command){
21912201 .inner = .{
2192 .cmd = LC_LOAD_DYLIB,
2202 .cmd = .LOAD_DYLIB,
21932203 .cmdsize = 32,
21942204 .dylib = .{
21952205 .name = 24,
......@@ -2227,7 +2237,7 @@ test "read-write C struct command" {
22272237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // stacksize
22282238 };
22292239 const cmd = .{
2230 .cmd = LC_MAIN,
2240 .cmd = .MAIN,
22312241 .cmdsize = 24,
22322242 .entryoff = 16644,
22332243 .stacksize = 0,
src/link/MachO.zig+11-18
......@@ -783,7 +783,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
783783 @sizeOf(u64),
784784 ));
785785 var rpath_cmd = macho.emptyGenericCommandWithData(macho.rpath_command{
786 .cmd = macho.LC_RPATH,
787786 .cmdsize = cmdsize,
788787 .path = @sizeOf(macho.rpath_command),
789788 });
......@@ -3174,7 +3173,7 @@ fn addCodeSignatureLC(self: *MachO) !void {
31743173 self.code_signature_cmd_index = @intCast(u16, self.load_commands.items.len);
31753174 try self.load_commands.append(self.base.allocator, .{
31763175 .linkedit_data = .{
3177 .cmd = macho.LC_CODE_SIGNATURE,
3176 .cmd = .CODE_SIGNATURE,
31783177 .cmdsize = @sizeOf(macho.linkedit_data_command),
31793178 .dataoff = 0,
31803179 .datasize = 0,
......@@ -4203,7 +4202,7 @@ fn populateMissingMetadata(self: *MachO) !void {
42034202 self.dyld_info_cmd_index = @intCast(u16, self.load_commands.items.len);
42044203 try self.load_commands.append(self.base.allocator, .{
42054204 .dyld_info_only = .{
4206 .cmd = macho.LC_DYLD_INFO_ONLY,
4205 .cmd = .DYLD_INFO_ONLY,
42074206 .cmdsize = @sizeOf(macho.dyld_info_command),
42084207 .rebase_off = 0,
42094208 .rebase_size = 0,
......@@ -4224,7 +4223,6 @@ fn populateMissingMetadata(self: *MachO) !void {
42244223 self.symtab_cmd_index = @intCast(u16, self.load_commands.items.len);
42254224 try self.load_commands.append(self.base.allocator, .{
42264225 .symtab = .{
4227 .cmd = macho.LC_SYMTAB,
42284226 .cmdsize = @sizeOf(macho.symtab_command),
42294227 .symoff = 0,
42304228 .nsyms = 0,
......@@ -4239,7 +4237,6 @@ fn populateMissingMetadata(self: *MachO) !void {
42394237 self.dysymtab_cmd_index = @intCast(u16, self.load_commands.items.len);
42404238 try self.load_commands.append(self.base.allocator, .{
42414239 .dysymtab = .{
4242 .cmd = macho.LC_DYSYMTAB,
42434240 .cmdsize = @sizeOf(macho.dysymtab_command),
42444241 .ilocalsym = 0,
42454242 .nlocalsym = 0,
......@@ -4272,7 +4269,7 @@ fn populateMissingMetadata(self: *MachO) !void {
42724269 @sizeOf(u64),
42734270 ));
42744271 var dylinker_cmd = macho.emptyGenericCommandWithData(macho.dylinker_command{
4275 .cmd = macho.LC_LOAD_DYLINKER,
4272 .cmd = .LOAD_DYLINKER,
42764273 .cmdsize = cmdsize,
42774274 .name = @sizeOf(macho.dylinker_command),
42784275 });
......@@ -4287,7 +4284,6 @@ fn populateMissingMetadata(self: *MachO) !void {
42874284 self.main_cmd_index = @intCast(u16, self.load_commands.items.len);
42884285 try self.load_commands.append(self.base.allocator, .{
42894286 .main = .{
4290 .cmd = macho.LC_MAIN,
42914287 .cmdsize = @sizeOf(macho.entry_point_command),
42924288 .entryoff = 0x0,
42934289 .stacksize = 0,
......@@ -4314,7 +4310,7 @@ fn populateMissingMetadata(self: *MachO) !void {
43144310 compat_version.major << 16 | compat_version.minor << 8 | compat_version.patch,
43154311 );
43164312 errdefer dylib_cmd.deinit(self.base.allocator);
4317 dylib_cmd.inner.cmd = macho.LC_ID_DYLIB;
4313 dylib_cmd.inner.cmd = .ID_DYLIB;
43184314 try self.load_commands.append(self.base.allocator, .{ .dylib = dylib_cmd });
43194315 self.load_commands_dirty = true;
43204316 }
......@@ -4323,7 +4319,6 @@ fn populateMissingMetadata(self: *MachO) !void {
43234319 self.source_version_cmd_index = @intCast(u16, self.load_commands.items.len);
43244320 try self.load_commands.append(self.base.allocator, .{
43254321 .source_version = .{
4326 .cmd = macho.LC_SOURCE_VERSION,
43274322 .cmdsize = @sizeOf(macho.source_version_command),
43284323 .version = 0x0,
43294324 },
......@@ -4350,13 +4345,12 @@ fn populateMissingMetadata(self: *MachO) !void {
43504345 } else platform_version;
43514346 const is_simulator_abi = self.base.options.target.abi == .simulator;
43524347 var cmd = macho.emptyGenericCommandWithData(macho.build_version_command{
4353 .cmd = macho.LC_BUILD_VERSION,
43544348 .cmdsize = cmdsize,
43554349 .platform = switch (self.base.options.target.os.tag) {
4356 .macos => macho.PLATFORM_MACOS,
4357 .ios => if (is_simulator_abi) macho.PLATFORM_IOSSIMULATOR else macho.PLATFORM_IOS,
4358 .watchos => if (is_simulator_abi) macho.PLATFORM_WATCHOSSIMULATOR else macho.PLATFORM_WATCHOS,
4359 .tvos => if (is_simulator_abi) macho.PLATFORM_TVOSSIMULATOR else macho.PLATFORM_TVOS,
4350 .macos => .MACOS,
4351 .ios => if (is_simulator_abi) macho.PLATFORM.IOSSIMULATOR else macho.PLATFORM.IOS,
4352 .watchos => if (is_simulator_abi) macho.PLATFORM.WATCHOSSIMULATOR else macho.PLATFORM.WATCHOS,
4353 .tvos => if (is_simulator_abi) macho.PLATFORM.TVOSSIMULATOR else macho.PLATFORM.TVOS,
43604354 else => unreachable,
43614355 },
43624356 .minos = platform_version,
......@@ -4364,7 +4358,7 @@ fn populateMissingMetadata(self: *MachO) !void {
43644358 .ntools = 1,
43654359 });
43664360 const ld_ver = macho.build_tool_version{
4367 .tool = macho.TOOL_LD,
4361 .tool = .LD,
43684362 .version = 0x0,
43694363 };
43704364 cmd.data = try self.base.allocator.alloc(u8, cmdsize - @sizeOf(macho.build_version_command));
......@@ -4377,7 +4371,6 @@ fn populateMissingMetadata(self: *MachO) !void {
43774371 if (self.uuid_cmd_index == null) {
43784372 self.uuid_cmd_index = @intCast(u16, self.load_commands.items.len);
43794373 var uuid_cmd: macho.uuid_command = .{
4380 .cmd = macho.LC_UUID,
43814374 .cmdsize = @sizeOf(macho.uuid_command),
43824375 .uuid = undefined,
43834376 };
......@@ -4390,7 +4383,7 @@ fn populateMissingMetadata(self: *MachO) !void {
43904383 self.function_starts_cmd_index = @intCast(u16, self.load_commands.items.len);
43914384 try self.load_commands.append(self.base.allocator, .{
43924385 .linkedit_data = .{
4393 .cmd = macho.LC_FUNCTION_STARTS,
4386 .cmd = .FUNCTION_STARTS,
43944387 .cmdsize = @sizeOf(macho.linkedit_data_command),
43954388 .dataoff = 0,
43964389 .datasize = 0,
......@@ -4403,7 +4396,7 @@ fn populateMissingMetadata(self: *MachO) !void {
44034396 self.data_in_code_cmd_index = @intCast(u16, self.load_commands.items.len);
44044397 try self.load_commands.append(self.base.allocator, .{
44054398 .linkedit_data = .{
4406 .cmd = macho.LC_DATA_IN_CODE,
4399 .cmd = .DATA_IN_CODE,
44074400 .cmdsize = @sizeOf(macho.linkedit_data_command),
44084401 .dataoff = 0,
44094402 .datasize = 0,
src/link/MachO/DebugSymbols.zig-1
......@@ -122,7 +122,6 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: Allocator) !void
122122
123123 try self.load_commands.append(allocator, .{
124124 .symtab = .{
125 .cmd = macho.LC_SYMTAB,
126125 .cmdsize = @sizeOf(macho.symtab_command),
127126 .symoff = @intCast(u32, symtab_off),
128127 .nsyms = base_cmd.nsyms,
src/link/MachO/Dylib.zig+4-4
......@@ -177,16 +177,16 @@ fn readLoadCommands(self: *Dylib, allocator: Allocator, reader: anytype, depende
177177 while (i < self.header.?.ncmds) : (i += 1) {
178178 var cmd = try macho.LoadCommand.read(allocator, reader);
179179 switch (cmd.cmd()) {
180 macho.LC_SYMTAB => {
180 .SYMTAB => {
181181 self.symtab_cmd_index = i;
182182 },
183 macho.LC_DYSYMTAB => {
183 .DYSYMTAB => {
184184 self.dysymtab_cmd_index = i;
185185 },
186 macho.LC_ID_DYLIB => {
186 .ID_DYLIB => {
187187 self.id_cmd_index = i;
188188 },
189 macho.LC_REEXPORT_DYLIB => {
189 .REEXPORT_DYLIB => {
190190 if (should_lookup_reexports) {
191191 // Parse install_name to dependent dylib.
192192 var id = try Id.fromLoadCommand(allocator, cmd.dylib);
src/link/MachO/Object.zig+5-5
......@@ -269,7 +269,7 @@ pub fn readLoadCommands(self: *Object, allocator: Allocator, reader: anytype) !v
269269 while (i < header.ncmds) : (i += 1) {
270270 var cmd = try macho.LoadCommand.read(allocator, reader);
271271 switch (cmd.cmd()) {
272 macho.LC_SEGMENT_64 => {
272 .SEGMENT_64 => {
273273 self.segment_cmd_index = i;
274274 var seg = cmd.segment;
275275 for (seg.sections.items) |*sect, j| {
......@@ -302,18 +302,18 @@ pub fn readLoadCommands(self: *Object, allocator: Allocator, reader: anytype) !v
302302
303303 seg.inner.fileoff += offset;
304304 },
305 macho.LC_SYMTAB => {
305 .SYMTAB => {
306306 self.symtab_cmd_index = i;
307307 cmd.symtab.symoff += offset;
308308 cmd.symtab.stroff += offset;
309309 },
310 macho.LC_DYSYMTAB => {
310 .DYSYMTAB => {
311311 self.dysymtab_cmd_index = i;
312312 },
313 macho.LC_BUILD_VERSION => {
313 .BUILD_VERSION => {
314314 self.build_version_cmd_index = i;
315315 },
316 macho.LC_DATA_IN_CODE => {
316 .DATA_IN_CODE => {
317317 self.data_in_code_cmd_index = i;
318318 cmd.linkedit_data.dataoff += offset;
319319 },