| ... | ... | @@ -385,8 +385,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node |
| 385 | 385 | error.MalformedDylib, |
| 386 | 386 | error.InvalidCpuArch, |
| 387 | 387 | error.InvalidTarget, |
| 388 | | error.UnknownFileType, |
| 389 | 388 | => continue, // already reported |
| 389 | error.UnknownFileType => try self.reportParseError(obj.path, "unknown file type for an object file", .{}), |
| 390 | 390 | else => |e| try self.reportParseError( |
| 391 | 391 | obj.path, |
| 392 | 392 | "unexpected error: parsing input file failed with error {s}", |
| ... | ... | @@ -436,8 +436,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node |
| 436 | 436 | error.MalformedArchive, |
| 437 | 437 | error.MalformedDylib, |
| 438 | 438 | error.InvalidCpuArch, |
| 439 | | error.UnknownFileType, |
| 440 | 439 | => continue, // already reported |
| 440 | error.UnknownFileType => try self.reportParseError(lib.path, "unknown file type for a library", .{}), |
| 441 | 441 | else => |e| try self.reportParseError( |
| 442 | 442 | lib.path, |
| 443 | 443 | "unexpected error: parsing library failed with error {s}", |
| ... | ... | @@ -458,8 +458,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node |
| 458 | 458 | error.MalformedArchive, |
| 459 | 459 | error.InvalidCpuArch, |
| 460 | 460 | error.InvalidTarget, |
| 461 | | error.UnknownFileType, |
| 462 | 461 | => {}, // already reported |
| 462 | error.UnknownFileType => try self.reportParseError(path, "unknown file type for a library", .{}), |
| 463 | 463 | else => |e| try self.reportParseError( |
| 464 | 464 | path, |
| 465 | 465 | "unexpected error: parsing input file failed with error {s}", |
| ... | ... | @@ -762,6 +762,7 @@ const ParseError = error{ |
| 762 | 762 | MalformedObject, |
| 763 | 763 | MalformedArchive, |
| 764 | 764 | MalformedDylib, |
| 765 | MalformedTbd, |
| 765 | 766 | NotLibStub, |
| 766 | 767 | InvalidCpuArch, |
| 767 | 768 | InvalidTarget, |
| ... | ... | @@ -796,16 +797,16 @@ fn parseLibrary(self: *MachO, lib: SystemLib, must_link: bool) ParseError!void { |
| 796 | 797 | try self.parseArchive(lib, must_link, fat_arch); |
| 797 | 798 | } else if (try Dylib.isDylib(lib.path, fat_arch)) { |
| 798 | 799 | _ = try self.parseDylib(lib, true, fat_arch); |
| 799 | | } else { |
| 800 | | try self.reportParseError(lib.path, "unknown file type for a library", .{}); |
| 801 | | return error.UnknownFileType; |
| 802 | | } |
| 800 | } else return error.UnknownFileType; |
| 803 | 801 | } else if (try Archive.isArchive(lib.path, null)) { |
| 804 | 802 | try self.parseArchive(lib, must_link, null); |
| 805 | 803 | } else if (try Dylib.isDylib(lib.path, null)) { |
| 806 | 804 | _ = try self.parseDylib(lib, true, null); |
| 807 | 805 | } else { |
| 808 | | try self.parseTbd(lib, true); |
| 806 | _ = self.parseTbd(lib, true) catch |err| switch (err) { |
| 807 | error.MalformedTbd => return error.UnknownFileType, |
| 808 | else => |e| return e, |
| 809 | }; |
| 809 | 810 | } |
| 810 | 811 | } |
| 811 | 812 | |
| ... | ... | @@ -925,11 +926,32 @@ fn parseDylib(self: *MachO, lib: SystemLib, explicit: bool, fat_arch: ?fat.Arch) |
| 925 | 926 | return index; |
| 926 | 927 | } |
| 927 | 928 | |
| 928 | | fn parseTbd(self: *MachO, lib: SystemLib, explicit: bool) ParseError!void { |
| 929 | | _ = self; |
| 930 | | _ = lib; |
| 931 | | _ = explicit; |
| 932 | | return error.Unhandled; |
| 929 | fn parseTbd(self: *MachO, lib: SystemLib, explicit: bool) ParseError!File.Index { |
| 930 | const tracy = trace(@src()); |
| 931 | defer tracy.end(); |
| 932 | |
| 933 | const gpa = self.base.comp.gpa; |
| 934 | const file = try std.fs.cwd().openFile(lib.path, .{}); |
| 935 | defer file.close(); |
| 936 | |
| 937 | var lib_stub = LibStub.loadFromFile(gpa, file) catch return error.MalformedTbd; // TODO actually handle different errors |
| 938 | defer lib_stub.deinit(); |
| 939 | |
| 940 | const index = @as(File.Index, @intCast(try self.files.addOne(gpa))); |
| 941 | self.files.set(index, .{ .dylib = .{ |
| 942 | .path = try gpa.dupe(u8, lib.path), |
| 943 | .data = &[0]u8{}, |
| 944 | .index = index, |
| 945 | .needed = lib.needed, |
| 946 | .weak = lib.weak, |
| 947 | .reexport = lib.reexport, |
| 948 | .explicit = explicit, |
| 949 | } }); |
| 950 | const dylib = &self.files.items(.data)[index].dylib; |
| 951 | try dylib.parseTbd(self.getTarget().cpu.arch, self.platform, lib_stub, self); |
| 952 | try self.dylibs.append(gpa, index); |
| 953 | |
| 954 | return index; |
| 933 | 955 | } |
| 934 | 956 | |
| 935 | 957 | fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void { |