| ... | ... | @@ -419,6 +419,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 419 | 419 | &dependent_libs, |
| 420 | 420 | &parse_error_ctx, |
| 421 | 421 | ) catch |err| switch (err) { |
| 422 | error.DylibAlreadyExists => {}, |
| 422 | 423 | error.UnknownFileType => try self.reportParseError(path, "unknown file type", .{}), |
| 423 | 424 | error.MissingArchFatLib => try self.reportParseError( |
| 424 | 425 | path, |
| ... | ... | @@ -723,6 +724,22 @@ fn resolveLib( |
| 723 | 724 | return full_path; |
| 724 | 725 | } |
| 725 | 726 | |
| 727 | const ParseError = error{ |
| 728 | UnknownFileType, |
| 729 | MissingArchFatLib, |
| 730 | InvalidArch, |
| 731 | DylibAlreadyExists, |
| 732 | IncompatibleDylibVersion, |
| 733 | OutOfMemory, |
| 734 | Overflow, |
| 735 | InputOutput, |
| 736 | MalformedArchive, |
| 737 | NotLibStub, |
| 738 | EndOfStream, |
| 739 | FileSystem, |
| 740 | NotSupported, |
| 741 | } || std.os.SeekError || std.fs.File.OpenError || std.fs.File.ReadError || tapi.TapiError; |
| 742 | |
| 726 | 743 | pub fn parsePositional( |
| 727 | 744 | self: *MachO, |
| 728 | 745 | file: std.fs.File, |
| ... | ... | @@ -730,7 +747,7 @@ pub fn parsePositional( |
| 730 | 747 | must_link: bool, |
| 731 | 748 | dependent_libs: anytype, |
| 732 | 749 | error_ctx: anytype, |
| 733 | | ) !void { |
| 750 | ) ParseError!void { |
| 734 | 751 | const tracy = trace(@src()); |
| 735 | 752 | defer tracy.end(); |
| 736 | 753 | |
| ... | ... | @@ -750,7 +767,7 @@ fn parseObject( |
| 750 | 767 | file: std.fs.File, |
| 751 | 768 | path: []const u8, |
| 752 | 769 | error_ctx: anytype, |
| 753 | | ) !void { |
| 770 | ) ParseError!void { |
| 754 | 771 | const tracy = trace(@src()); |
| 755 | 772 | defer tracy.end(); |
| 756 | 773 | |
| ... | ... | @@ -793,7 +810,7 @@ pub fn parseLibrary( |
| 793 | 810 | must_link: bool, |
| 794 | 811 | dependent_libs: anytype, |
| 795 | 812 | error_ctx: anytype, |
| 796 | | ) !void { |
| 813 | ) ParseError!void { |
| 797 | 814 | const tracy = trace(@src()); |
| 798 | 815 | defer tracy.end(); |
| 799 | 816 | |
| ... | ... | @@ -829,7 +846,7 @@ pub fn parseLibrary( |
| 829 | 846 | } |
| 830 | 847 | } |
| 831 | 848 | |
| 832 | | pub fn parseFatLibrary(self: *MachO, file: std.fs.File, cpu_arch: std.Target.Cpu.Arch) !u64 { |
| 849 | pub fn parseFatLibrary(self: *MachO, file: std.fs.File, cpu_arch: std.Target.Cpu.Arch) ParseError!u64 { |
| 833 | 850 | _ = self; |
| 834 | 851 | var buffer: [2]fat.Arch = undefined; |
| 835 | 852 | const fat_archs = try fat.parseArchs(file, &buffer); |
| ... | ... | @@ -846,7 +863,7 @@ fn parseArchive( |
| 846 | 863 | must_link: bool, |
| 847 | 864 | cpu_arch: std.Target.Cpu.Arch, |
| 848 | 865 | error_ctx: anytype, |
| 849 | | ) !void { |
| 866 | ) ParseError!void { |
| 850 | 867 | const gpa = self.base.allocator; |
| 851 | 868 | |
| 852 | 869 | // We take ownership of the file so that we can store it for the duration of symbol resolution. |
| ... | ... | @@ -915,7 +932,7 @@ fn parseDylib( |
| 915 | 932 | dependent_libs: anytype, |
| 916 | 933 | dylib_options: DylibOpts, |
| 917 | 934 | error_ctx: anytype, |
| 918 | | ) !void { |
| 935 | ) ParseError!void { |
| 919 | 936 | const gpa = self.base.allocator; |
| 920 | 937 | const self_cpu_arch = self.base.options.target.cpu.arch; |
| 921 | 938 | |
| ... | ... | @@ -948,13 +965,10 @@ fn parseDylib( |
| 948 | 965 | |
| 949 | 966 | // TODO verify platform |
| 950 | 967 | |
| 951 | | self.addDylib(dylib, .{ |
| 968 | try self.addDylib(dylib, .{ |
| 952 | 969 | .needed = dylib_options.needed, |
| 953 | 970 | .weak = dylib_options.weak, |
| 954 | | }) catch |err| switch (err) { |
| 955 | | error.DylibAlreadyExists => dylib.deinit(gpa), |
| 956 | | else => |e| return e, |
| 957 | | }; |
| 971 | }); |
| 958 | 972 | } |
| 959 | 973 | |
| 960 | 974 | fn parseLibStub( |
| ... | ... | @@ -963,7 +977,7 @@ fn parseLibStub( |
| 963 | 977 | path: []const u8, |
| 964 | 978 | dependent_libs: anytype, |
| 965 | 979 | dylib_options: DylibOpts, |
| 966 | | ) !void { |
| 980 | ) ParseError!void { |
| 967 | 981 | const gpa = self.base.allocator; |
| 968 | 982 | var lib_stub = try LibStub.loadFromFile(gpa, file); |
| 969 | 983 | defer lib_stub.deinit(); |
| ... | ... | @@ -984,16 +998,13 @@ fn parseLibStub( |
| 984 | 998 | path, |
| 985 | 999 | ); |
| 986 | 1000 | |
| 987 | | self.addDylib(dylib, .{ |
| 1001 | try self.addDylib(dylib, .{ |
| 988 | 1002 | .needed = dylib_options.needed, |
| 989 | 1003 | .weak = dylib_options.weak, |
| 990 | | }) catch |err| switch (err) { |
| 991 | | error.DylibAlreadyExists => dylib.deinit(gpa), |
| 992 | | else => |e| return e, |
| 993 | | }; |
| 1004 | }); |
| 994 | 1005 | } |
| 995 | 1006 | |
| 996 | | fn addDylib(self: *MachO, dylib: Dylib, dylib_options: DylibOpts) !void { |
| 1007 | fn addDylib(self: *MachO, dylib: Dylib, dylib_options: DylibOpts) ParseError!void { |
| 997 | 1008 | if (dylib_options.id) |id| { |
| 998 | 1009 | if (dylib.id.?.current_version < id.compatibility_version) { |
| 999 | 1010 | // TODO convert into an error |
| ... | ... | @@ -1022,7 +1033,7 @@ fn addDylib(self: *MachO, dylib: Dylib, dylib_options: DylibOpts) !void { |
| 1022 | 1033 | } |
| 1023 | 1034 | } |
| 1024 | 1035 | |
| 1025 | | pub fn parseDependentLibs(self: *MachO, dependent_libs: anytype, error_ctx: anytype) !void { |
| 1036 | pub fn parseDependentLibs(self: *MachO, dependent_libs: anytype, error_ctx: anytype) ParseError!void { |
| 1026 | 1037 | const tracy = trace(@src()); |
| 1027 | 1038 | defer tracy.end(); |
| 1028 | 1039 | |
| ... | ... | @@ -5145,6 +5156,7 @@ const link = @import("../link.zig"); |
| 5145 | 5156 | const llvm_backend = @import("../codegen/llvm.zig"); |
| 5146 | 5157 | const load_commands = @import("MachO/load_commands.zig"); |
| 5147 | 5158 | const stubs = @import("MachO/stubs.zig"); |
| 5159 | const tapi = @import("tapi.zig"); |
| 5148 | 5160 | const target_util = @import("../target.zig"); |
| 5149 | 5161 | const thunks = @import("MachO/thunks.zig"); |
| 5150 | 5162 | const trace = @import("../tracy.zig").trace; |
| ... | ... | @@ -5162,7 +5174,7 @@ const DwarfInfo = @import("MachO/DwarfInfo.zig"); |
| 5162 | 5174 | const Dylib = @import("MachO/Dylib.zig"); |
| 5163 | 5175 | const File = link.File; |
| 5164 | 5176 | const Object = @import("MachO/Object.zig"); |
| 5165 | | const LibStub = @import("tapi.zig").LibStub; |
| 5177 | const LibStub = tapi.LibStub; |
| 5166 | 5178 | const Liveness = @import("../Liveness.zig"); |
| 5167 | 5179 | const LlvmObject = @import("../codegen/llvm.zig").Object; |
| 5168 | 5180 | const Md5 = std.crypto.hash.Md5; |