| author | |
| committer | |
| log | ace9b3de642ab89dd356d877ee6b46ce88640e1d |
| tree | 7548aa57cb64984780b9f86a569817d75c51afe0 |
| parent | 049ff45430f7d556d1c6947c0bc44f3df67a8b00 |
5 files changed, 46 insertions(+), 55 deletions(-)
src/link/MachO.zig+6-17| ... | @@ -995,7 +995,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { | ... | @@ -995,7 +995,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { |
| 995 | } | 995 | } |
| 996 | 996 | ||
| 997 | fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const u8) !void { | 997 | fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const u8) !void { |
| 998 | const arch = self.base.options.target.cpu.arch; | ||
| 999 | for (files) |file_name| { | 998 | for (files) |file_name| { |
| 1000 | const full_path = full_path: { | 999 | const full_path = full_path: { |
| 1001 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; | 1000 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| ... | @@ -1004,17 +1003,17 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const | ... | @@ -1004,17 +1003,17 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const |
| 1004 | }; | 1003 | }; |
| 1005 | defer self.base.allocator.free(full_path); | 1004 | defer self.base.allocator.free(full_path); |
| 1006 | 1005 | ||
| 1007 | if (try Object.createAndParseFromPath(self.base.allocator, arch, full_path)) |object| { | 1006 | if (try Object.createAndParseFromPath(self.base.allocator, self.base.options.target, full_path)) |object| { |
| 1008 | try self.objects.append(self.base.allocator, object); | 1007 | try self.objects.append(self.base.allocator, object); |
| 1009 | continue; | 1008 | continue; |
| 1010 | } | 1009 | } |
| 1011 | 1010 | ||
| 1012 | if (try Archive.createAndParseFromPath(self.base.allocator, arch, full_path)) |archive| { | 1011 | if (try Archive.createAndParseFromPath(self.base.allocator, self.base.options.target, full_path)) |archive| { |
| 1013 | try self.archives.append(self.base.allocator, archive); | 1012 | try self.archives.append(self.base.allocator, archive); |
| 1014 | continue; | 1013 | continue; |
| 1015 | } | 1014 | } |
| 1016 | 1015 | ||
| 1017 | if (try Dylib.createAndParseFromPath(self.base.allocator, arch, full_path, .{ | 1016 | if (try Dylib.createAndParseFromPath(self.base.allocator, self.base.options.target, full_path, .{ |
| 1018 | .syslibroot = syslibroot, | 1017 | .syslibroot = syslibroot, |
| 1019 | })) |dylibs| { | 1018 | })) |dylibs| { |
| 1020 | defer self.base.allocator.free(dylibs); | 1019 | defer self.base.allocator.free(dylibs); |
| ... | @@ -1032,9 +1031,8 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const | ... | @@ -1032,9 +1031,8 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const |
| 1032 | } | 1031 | } |
| 1033 | 1032 | ||
| 1034 | fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !void { | 1033 | fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !void { |
| 1035 | const arch = self.base.options.target.cpu.arch; | ||
| 1036 | for (libs) |lib| { | 1034 | for (libs) |lib| { |
| 1037 | if (try Dylib.createAndParseFromPath(self.base.allocator, arch, lib, .{ | 1035 | if (try Dylib.createAndParseFromPath(self.base.allocator, self.base.options.target, lib, .{ |
| 1038 | .syslibroot = syslibroot, | 1036 | .syslibroot = syslibroot, |
| 1039 | })) |dylibs| { | 1037 | })) |dylibs| { |
| 1040 | defer self.base.allocator.free(dylibs); | 1038 | defer self.base.allocator.free(dylibs); |
| ... | @@ -1047,7 +1045,7 @@ fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !v | ... | @@ -1047,7 +1045,7 @@ fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !v |
| 1047 | continue; | 1045 | continue; |
| 1048 | } | 1046 | } |
| 1049 | 1047 | ||
| 1050 | if (try Archive.createAndParseFromPath(self.base.allocator, arch, lib)) |archive| { | 1048 | if (try Archive.createAndParseFromPath(self.base.allocator, self.base.options.target, lib)) |archive| { |
| 1051 | try self.archives.append(self.base.allocator, archive); | 1049 | try self.archives.append(self.base.allocator, archive); |
| 1052 | continue; | 1050 | continue; |
| 1053 | } | 1051 | } |
| ... | @@ -2236,11 +2234,7 @@ fn resolveSymbols(self: *MachO) !void { | ... | @@ -2236,11 +2234,7 @@ fn resolveSymbols(self: *MachO) !void { |
| 2236 | 2234 | ||
| 2237 | const object_id = @intCast(u16, self.objects.items.len); | 2235 | const object_id = @intCast(u16, self.objects.items.len); |
| 2238 | const object = try self.objects.addOne(self.base.allocator); | 2236 | const object = try self.objects.addOne(self.base.allocator); |
| 2239 | object.* = try archive.parseObject( | 2237 | object.* = try archive.parseObject(self.base.allocator, self.base.options.target, offsets.items[0]); |
| 2240 | self.base.allocator, | ||
| 2241 | self.base.options.target.cpu.arch, | ||
| 2242 | offsets.items[0], | ||
| 2243 | ); | ||
| 2244 | try self.resolveSymbolsInObject(object_id); | 2238 | try self.resolveSymbolsInObject(object_id); |
| 2245 | 2239 | ||
| 2246 | continue :loop; | 2240 | continue :loop; |
| ... | @@ -2885,11 +2879,6 @@ fn flushZld(self: *MachO) !void { | ... | @@ -2885,11 +2879,6 @@ fn flushZld(self: *MachO) !void { |
| 2885 | if (self.base.options.target.cpu.arch == .aarch64) { | 2879 | if (self.base.options.target.cpu.arch == .aarch64) { |
| 2886 | try self.writeCodeSignature(); | 2880 | try self.writeCodeSignature(); |
| 2887 | } | 2881 | } |
| 2888 | |||
| 2889 | // if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64) { | ||
| 2890 | // const out_path = self.output.?.path; | ||
| 2891 | // try fs.cwd().copyFile(out_path, fs.cwd(), out_path, .{}); | ||
| 2892 | // } | ||
| 2893 | } | 2882 | } |
| 2894 | 2883 | ||
| 2895 | fn writeGotEntries(self: *MachO) !void { | 2884 | fn writeGotEntries(self: *MachO) !void { |
src/link/MachO/Archive.zig+6-7| ... | @@ -9,7 +9,6 @@ const mem = std.mem; | ... | @@ -9,7 +9,6 @@ const mem = std.mem; |
| 9 | const fat = @import("fat.zig"); | 9 | const fat = @import("fat.zig"); |
| 10 | 10 | ||
| 11 | const Allocator = mem.Allocator; | 11 | const Allocator = mem.Allocator; |
| 12 | const Arch = std.Target.Cpu.Arch; | ||
| 13 | const Object = @import("Object.zig"); | 12 | const Object = @import("Object.zig"); |
| 14 | 13 | ||
| 15 | file: fs.File, | 14 | file: fs.File, |
| ... | @@ -104,7 +103,7 @@ pub fn deinit(self: *Archive, allocator: *Allocator) void { | ... | @@ -104,7 +103,7 @@ pub fn deinit(self: *Archive, allocator: *Allocator) void { |
| 104 | allocator.free(self.name); | 103 | allocator.free(self.name); |
| 105 | } | 104 | } |
| 106 | 105 | ||
| 107 | pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u8) !?Archive { | 106 | pub fn createAndParseFromPath(allocator: *Allocator, target: std.Target, path: []const u8) !?Archive { |
| 108 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { | 107 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { |
| 109 | error.FileNotFound => return null, | 108 | error.FileNotFound => return null, |
| 110 | else => |e| return e, | 109 | else => |e| return e, |
| ... | @@ -119,7 +118,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u | ... | @@ -119,7 +118,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u |
| 119 | .file = file, | 118 | .file = file, |
| 120 | }; | 119 | }; |
| 121 | 120 | ||
| 122 | archive.parse(allocator, arch) catch |err| switch (err) { | 121 | archive.parse(allocator, target) catch |err| switch (err) { |
| 123 | error.EndOfStream, error.NotArchive => { | 122 | error.EndOfStream, error.NotArchive => { |
| 124 | archive.deinit(allocator); | 123 | archive.deinit(allocator); |
| 125 | return null; | 124 | return null; |
| ... | @@ -130,9 +129,9 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u | ... | @@ -130,9 +129,9 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u |
| 130 | return archive; | 129 | return archive; |
| 131 | } | 130 | } |
| 132 | 131 | ||
| 133 | pub fn parse(self: *Archive, allocator: *Allocator, arch: Arch) !void { | 132 | pub fn parse(self: *Archive, allocator: *Allocator, target: std.Target) !void { |
| 134 | const reader = self.file.reader(); | 133 | const reader = self.file.reader(); |
| 135 | self.library_offset = try fat.getLibraryOffset(reader, arch); | 134 | self.library_offset = try fat.getLibraryOffset(reader, target); |
| 136 | try self.file.seekTo(self.library_offset); | 135 | try self.file.seekTo(self.library_offset); |
| 137 | 136 | ||
| 138 | const magic = try reader.readBytesNoEof(SARMAG); | 137 | const magic = try reader.readBytesNoEof(SARMAG); |
| ... | @@ -215,7 +214,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) | ... | @@ -215,7 +214,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) |
| 215 | } | 214 | } |
| 216 | } | 215 | } |
| 217 | 216 | ||
| 218 | pub fn parseObject(self: Archive, allocator: *Allocator, arch: Arch, offset: u32) !Object { | 217 | pub fn parseObject(self: Archive, allocator: *Allocator, target: std.Target, offset: u32) !Object { |
| 219 | const reader = self.file.reader(); | 218 | const reader = self.file.reader(); |
| 220 | try reader.context.seekTo(offset + self.library_offset); | 219 | try reader.context.seekTo(offset + self.library_offset); |
| 221 | 220 | ||
| ... | @@ -244,7 +243,7 @@ pub fn parseObject(self: Archive, allocator: *Allocator, arch: Arch, offset: u32 | ... | @@ -244,7 +243,7 @@ pub fn parseObject(self: Archive, allocator: *Allocator, arch: Arch, offset: u32 |
| 244 | .mtime = try self.header.?.date(), | 243 | .mtime = try self.header.?.date(), |
| 245 | }; | 244 | }; |
| 246 | 245 | ||
| 247 | try object.parse(allocator, arch); | 246 | try object.parse(allocator, target); |
| 248 | try reader.context.seekTo(0); | 247 | try reader.context.seekTo(0); |
| 249 | 248 | ||
| 250 | return object; | 249 | return object; |
src/link/MachO/Dylib.zig+24-18| ... | @@ -12,7 +12,6 @@ const fat = @import("fat.zig"); | ... | @@ -12,7 +12,6 @@ const fat = @import("fat.zig"); |
| 12 | const commands = @import("commands.zig"); | 12 | const commands = @import("commands.zig"); |
| 13 | 13 | ||
| 14 | const Allocator = mem.Allocator; | 14 | const Allocator = mem.Allocator; |
| 15 | const Arch = std.Target.Cpu.Arch; | ||
| 16 | const LibStub = @import("../tapi.zig").LibStub; | 15 | const LibStub = @import("../tapi.zig").LibStub; |
| 17 | const LoadCommand = commands.LoadCommand; | 16 | const LoadCommand = commands.LoadCommand; |
| 18 | const MachO = @import("../MachO.zig"); | 17 | const MachO = @import("../MachO.zig"); |
| ... | @@ -139,11 +138,12 @@ pub const Error = error{ | ... | @@ -139,11 +138,12 @@ pub const Error = error{ |
| 139 | pub const CreateOpts = struct { | 138 | pub const CreateOpts = struct { |
| 140 | syslibroot: ?[]const u8 = null, | 139 | syslibroot: ?[]const u8 = null, |
| 141 | id: ?Id = null, | 140 | id: ?Id = null, |
| 141 | target: ?std.Target = null, | ||
| 142 | }; | 142 | }; |
| 143 | 143 | ||
| 144 | pub fn createAndParseFromPath( | 144 | pub fn createAndParseFromPath( |
| 145 | allocator: *Allocator, | 145 | allocator: *Allocator, |
| 146 | arch: Arch, | 146 | target: std.Target, |
| 147 | path: []const u8, | 147 | path: []const u8, |
| 148 | opts: CreateOpts, | 148 | opts: CreateOpts, |
| 149 | ) Error!?[]Dylib { | 149 | ) Error!?[]Dylib { |
| ... | @@ -161,7 +161,7 @@ pub fn createAndParseFromPath( | ... | @@ -161,7 +161,7 @@ pub fn createAndParseFromPath( |
| 161 | .file = file, | 161 | .file = file, |
| 162 | }; | 162 | }; |
| 163 | 163 | ||
| 164 | dylib.parse(allocator, arch) catch |err| switch (err) { | 164 | dylib.parse(allocator, target) catch |err| switch (err) { |
| 165 | error.EndOfStream, error.NotDylib => { | 165 | error.EndOfStream, error.NotDylib => { |
| 166 | try file.seekTo(0); | 166 | try file.seekTo(0); |
| 167 | 167 | ||
| ... | @@ -171,7 +171,7 @@ pub fn createAndParseFromPath( | ... | @@ -171,7 +171,7 @@ pub fn createAndParseFromPath( |
| 171 | }; | 171 | }; |
| 172 | defer lib_stub.deinit(); | 172 | defer lib_stub.deinit(); |
| 173 | 173 | ||
| 174 | try dylib.parseFromStub(allocator, arch, lib_stub); | 174 | try dylib.parseFromStub(allocator, target, lib_stub); |
| 175 | }, | 175 | }, |
| 176 | else => |e| return e, | 176 | else => |e| return e, |
| 177 | }; | 177 | }; |
| ... | @@ -195,7 +195,7 @@ pub fn createAndParseFromPath( | ... | @@ -195,7 +195,7 @@ pub fn createAndParseFromPath( |
| 195 | try dylibs.append(dylib); | 195 | try dylibs.append(dylib); |
| 196 | // TODO this should not be performed if the user specifies `-flat_namespace` flag. | 196 | // TODO this should not be performed if the user specifies `-flat_namespace` flag. |
| 197 | // See ld64 manpages. | 197 | // See ld64 manpages. |
| 198 | try dylib.parseDependentLibs(allocator, arch, &dylibs, opts.syslibroot); | 198 | try dylib.parseDependentLibs(allocator, target, &dylibs, opts.syslibroot); |
| 199 | 199 | ||
| 200 | return dylibs.toOwnedSlice(); | 200 | return dylibs.toOwnedSlice(); |
| 201 | } | 201 | } |
| ... | @@ -222,10 +222,10 @@ pub fn deinit(self: *Dylib, allocator: *Allocator) void { | ... | @@ -222,10 +222,10 @@ pub fn deinit(self: *Dylib, allocator: *Allocator) void { |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | pub fn parse(self: *Dylib, allocator: *Allocator, arch: Arch) !void { | 225 | pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void { |
| 226 | log.debug("parsing shared library '{s}'", .{self.name}); | 226 | log.debug("parsing shared library '{s}'", .{self.name}); |
| 227 | 227 | ||
| 228 | self.library_offset = try fat.getLibraryOffset(self.file.reader(), arch); | 228 | self.library_offset = try fat.getLibraryOffset(self.file.reader(), target); |
| 229 | 229 | ||
| 230 | try self.file.seekTo(self.library_offset); | 230 | try self.file.seekTo(self.library_offset); |
| 231 | 231 | ||
| ... | @@ -237,10 +237,10 @@ pub fn parse(self: *Dylib, allocator: *Allocator, arch: Arch) !void { | ... | @@ -237,10 +237,10 @@ pub fn parse(self: *Dylib, allocator: *Allocator, arch: Arch) !void { |
| 237 | return error.NotDylib; | 237 | return error.NotDylib; |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | const this_arch: Arch = try fat.decodeArch(self.header.?.cputype, true); | 240 | const this_arch: std.Target.Cpu.Arch = try fat.decodeArch(self.header.?.cputype, true); |
| 241 | 241 | ||
| 242 | if (this_arch != arch) { | 242 | if (this_arch != target.cpu.arch) { |
| 243 | log.err("mismatched cpu architecture: expected {s}, found {s}", .{ arch, this_arch }); | 243 | log.err("mismatched cpu architecture: expected {s}, found {s}", .{ target.cpu.arch, this_arch }); |
| 244 | return error.MismatchedCpuArchitecture; | 244 | return error.MismatchedCpuArchitecture; |
| 245 | } | 245 | } |
| 246 | 246 | ||
| ... | @@ -334,7 +334,16 @@ fn addObjCClassSymbols(self: *Dylib, allocator: *Allocator, sym_name: []const u8 | ... | @@ -334,7 +334,16 @@ fn addObjCClassSymbols(self: *Dylib, allocator: *Allocator, sym_name: []const u8 |
| 334 | } | 334 | } |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | pub fn parseFromStub(self: *Dylib, allocator: *Allocator, arch: Arch, lib_stub: LibStub) !void { | 337 | fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 { |
| 338 | const arch = switch (target.cpu.arch) { | ||
| 339 | .aarch64 => "arm64", | ||
| 340 | .x86_64 => "x86_64", | ||
| 341 | else => unreachable, | ||
| 342 | }; | ||
| 343 | return std.fmt.allocPrint(allocator, "{s}-{s}", .{ arch, @tagName(target.os.tag) }); | ||
| 344 | } | ||
| 345 | |||
| 346 | pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, lib_stub: LibStub) !void { | ||
| 338 | if (lib_stub.inner.len == 0) return error.EmptyStubFile; | 347 | if (lib_stub.inner.len == 0) return error.EmptyStubFile; |
| 339 | 348 | ||
| 340 | log.debug("parsing shared library from stub '{s}'", .{self.name}); | 349 | log.debug("parsing shared library from stub '{s}'", .{self.name}); |
| ... | @@ -350,11 +359,8 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, arch: Arch, lib_stub: | ... | @@ -350,11 +359,8 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, arch: Arch, lib_stub: |
| 350 | } | 359 | } |
| 351 | self.id = id; | 360 | self.id = id; |
| 352 | 361 | ||
| 353 | const target_string: []const u8 = switch (arch) { | 362 | const target_string = try targetToAppleString(allocator, target); |
| 354 | .aarch64 => "arm64-macos", | 363 | defer allocator.free(target_string); |
| 355 | .x86_64 => "x86_64-macos", | ||
| 356 | else => unreachable, | ||
| 357 | }; | ||
| 358 | 364 | ||
| 359 | var umbrella_libs = std.StringHashMap(void).init(allocator); | 365 | var umbrella_libs = std.StringHashMap(void).init(allocator); |
| 360 | defer umbrella_libs.deinit(); | 366 | defer umbrella_libs.deinit(); |
| ... | @@ -443,7 +449,7 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, arch: Arch, lib_stub: | ... | @@ -443,7 +449,7 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, arch: Arch, lib_stub: |
| 443 | pub fn parseDependentLibs( | 449 | pub fn parseDependentLibs( |
| 444 | self: *Dylib, | 450 | self: *Dylib, |
| 445 | allocator: *Allocator, | 451 | allocator: *Allocator, |
| 446 | arch: Arch, | 452 | target: std.Target, |
| 447 | out: *std.ArrayList(Dylib), | 453 | out: *std.ArrayList(Dylib), |
| 448 | syslibroot: ?[]const u8, | 454 | syslibroot: ?[]const u8, |
| 449 | ) !void { | 455 | ) !void { |
| ... | @@ -475,7 +481,7 @@ pub fn parseDependentLibs( | ... | @@ -475,7 +481,7 @@ pub fn parseDependentLibs( |
| 475 | 481 | ||
| 476 | const dylibs = (try createAndParseFromPath( | 482 | const dylibs = (try createAndParseFromPath( |
| 477 | allocator, | 483 | allocator, |
| 478 | arch, | 484 | target, |
| 479 | full_path, | 485 | full_path, |
| 480 | .{ | 486 | .{ |
| 481 | .id = id, | 487 | .id = id, |
src/link/MachO/Object.zig+6-7| ... | @@ -15,7 +15,6 @@ const segmentName = commands.segmentName; | ... | @@ -15,7 +15,6 @@ const segmentName = commands.segmentName; |
| 15 | const sectionName = commands.sectionName; | 15 | const sectionName = commands.sectionName; |
| 16 | 16 | ||
| 17 | const Allocator = mem.Allocator; | 17 | const Allocator = mem.Allocator; |
| 18 | const Arch = std.Target.Cpu.Arch; | ||
| 19 | const LoadCommand = commands.LoadCommand; | 18 | const LoadCommand = commands.LoadCommand; |
| 20 | const MachO = @import("../MachO.zig"); | 19 | const MachO = @import("../MachO.zig"); |
| 21 | const TextBlock = @import("TextBlock.zig"); | 20 | const TextBlock = @import("TextBlock.zig"); |
| ... | @@ -154,7 +153,7 @@ pub fn deinit(self: *Object, allocator: *Allocator) void { | ... | @@ -154,7 +153,7 @@ pub fn deinit(self: *Object, allocator: *Allocator) void { |
| 154 | } | 153 | } |
| 155 | } | 154 | } |
| 156 | 155 | ||
| 157 | pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u8) !?Object { | 156 | pub fn createAndParseFromPath(allocator: *Allocator, target: std.Target, path: []const u8) !?Object { |
| 158 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { | 157 | const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) { |
| 159 | error.FileNotFound => return null, | 158 | error.FileNotFound => return null, |
| 160 | else => |e| return e, | 159 | else => |e| return e, |
| ... | @@ -169,7 +168,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u | ... | @@ -169,7 +168,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u |
| 169 | .file = file, | 168 | .file = file, |
| 170 | }; | 169 | }; |
| 171 | 170 | ||
| 172 | object.parse(allocator, arch) catch |err| switch (err) { | 171 | object.parse(allocator, target) catch |err| switch (err) { |
| 173 | error.EndOfStream, error.NotObject => { | 172 | error.EndOfStream, error.NotObject => { |
| 174 | object.deinit(allocator); | 173 | object.deinit(allocator); |
| 175 | return null; | 174 | return null; |
| ... | @@ -180,7 +179,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u | ... | @@ -180,7 +179,7 @@ pub fn createAndParseFromPath(allocator: *Allocator, arch: Arch, path: []const u |
| 180 | return object; | 179 | return object; |
| 181 | } | 180 | } |
| 182 | 181 | ||
| 183 | pub fn parse(self: *Object, allocator: *Allocator, arch: Arch) !void { | 182 | pub fn parse(self: *Object, allocator: *Allocator, target: std.Target) !void { |
| 184 | const reader = self.file.reader(); | 183 | const reader = self.file.reader(); |
| 185 | if (self.file_offset) |offset| { | 184 | if (self.file_offset) |offset| { |
| 186 | try reader.context.seekTo(offset); | 185 | try reader.context.seekTo(offset); |
| ... | @@ -195,7 +194,7 @@ pub fn parse(self: *Object, allocator: *Allocator, arch: Arch) !void { | ... | @@ -195,7 +194,7 @@ pub fn parse(self: *Object, allocator: *Allocator, arch: Arch) !void { |
| 195 | return error.NotObject; | 194 | return error.NotObject; |
| 196 | } | 195 | } |
| 197 | 196 | ||
| 198 | const this_arch: Arch = switch (header.cputype) { | 197 | const this_arch: std.Target.Cpu.Arch = switch (header.cputype) { |
| 199 | macho.CPU_TYPE_ARM64 => .aarch64, | 198 | macho.CPU_TYPE_ARM64 => .aarch64, |
| 200 | macho.CPU_TYPE_X86_64 => .x86_64, | 199 | macho.CPU_TYPE_X86_64 => .x86_64, |
| 201 | else => |value| { | 200 | else => |value| { |
| ... | @@ -203,8 +202,8 @@ pub fn parse(self: *Object, allocator: *Allocator, arch: Arch) !void { | ... | @@ -203,8 +202,8 @@ pub fn parse(self: *Object, allocator: *Allocator, arch: Arch) !void { |
| 203 | return error.UnsupportedCpuArchitecture; | 202 | return error.UnsupportedCpuArchitecture; |
| 204 | }, | 203 | }, |
| 205 | }; | 204 | }; |
| 206 | if (this_arch != arch) { | 205 | if (this_arch != target.cpu.arch) { |
| 207 | log.err("mismatched cpu architecture: expected {s}, found {s}", .{ arch, this_arch }); | 206 | log.err("mismatched cpu architecture: expected {s}, found {s}", .{ target.cpu.arch, this_arch }); |
| 208 | return error.MismatchedCpuArchitecture; | 207 | return error.MismatchedCpuArchitecture; |
| 209 | } | 208 | } |
| 210 | 209 |
src/link/MachO/fat.zig+4-6| ... | @@ -5,10 +5,8 @@ const macho = std.macho; | ... | @@ -5,10 +5,8 @@ const macho = std.macho; |
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const native_endian = builtin.target.cpu.arch.endian(); | 6 | const native_endian = builtin.target.cpu.arch.endian(); |
| 7 | 7 | ||
| 8 | const Arch = std.Target.Cpu.Arch; | ||
| 9 | |||
| 10 | pub fn decodeArch(cputype: macho.cpu_type_t, comptime logError: bool) !std.Target.Cpu.Arch { | 8 | pub fn decodeArch(cputype: macho.cpu_type_t, comptime logError: bool) !std.Target.Cpu.Arch { |
| 11 | const arch: Arch = switch (cputype) { | 9 | const arch: std.Target.Cpu.Arch = switch (cputype) { |
| 12 | macho.CPU_TYPE_ARM64 => .aarch64, | 10 | macho.CPU_TYPE_ARM64 => .aarch64, |
| 13 | macho.CPU_TYPE_X86_64 => .x86_64, | 11 | macho.CPU_TYPE_X86_64 => .x86_64, |
| 14 | else => { | 12 | else => { |
| ... | @@ -31,7 +29,7 @@ fn readFatStruct(reader: anytype, comptime T: type) !T { | ... | @@ -31,7 +29,7 @@ fn readFatStruct(reader: anytype, comptime T: type) !T { |
| 31 | return res; | 29 | return res; |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | pub fn getLibraryOffset(reader: anytype, arch: Arch) !u64 { | 32 | pub fn getLibraryOffset(reader: anytype, target: std.Target) !u64 { |
| 35 | const fat_header = try readFatStruct(reader, macho.fat_header); | 33 | const fat_header = try readFatStruct(reader, macho.fat_header); |
| 36 | if (fat_header.magic != macho.FAT_MAGIC) return 0; | 34 | if (fat_header.magic != macho.FAT_MAGIC) return 0; |
| 37 | 35 | ||
| ... | @@ -44,12 +42,12 @@ pub fn getLibraryOffset(reader: anytype, arch: Arch) !u64 { | ... | @@ -44,12 +42,12 @@ pub fn getLibraryOffset(reader: anytype, arch: Arch) !u64 { |
| 44 | error.UnsupportedCpuArchitecture => continue, | 42 | error.UnsupportedCpuArchitecture => continue, |
| 45 | else => |e| return e, | 43 | else => |e| return e, |
| 46 | }; | 44 | }; |
| 47 | if (lib_arch == arch) { | 45 | if (lib_arch == target.cpu.arch) { |
| 48 | // We have found a matching architecture! | 46 | // We have found a matching architecture! |
| 49 | return fat_arch.offset; | 47 | return fat_arch.offset; |
| 50 | } | 48 | } |
| 51 | } else { | 49 | } else { |
| 52 | log.err("Could not find matching cpu architecture in fat library: expected {s}", .{arch}); | 50 | log.err("Could not find matching cpu architecture in fat library: expected {s}", .{target.cpu.arch}); |
| 53 | return error.MismatchedCpuArchitecture; | 51 | return error.MismatchedCpuArchitecture; |
| 54 | } | 52 | } |
| 55 | } | 53 | } |