| author | |
| committer | |
| log | f1af53f68ec629ca091452aeeeb2f7f7596e63b7 |
| tree | daf6ffa68ea9aeb1b98738b1fe3e9008d176e320 |
| parent | 7c37c55161b718ff3df0b6c76480a4d538519a84 |
This avoids mixing preads with reads which do not mix well especially
on Windows.3 files changed, 14 insertions(+), 5 deletions(-)
src/link/MachO.zig+1-1| ... | ... | @@ -914,6 +914,7 @@ fn parseInputFileWorker(self: *MachO, file: File) void { |
| 914 | 914 | switch (err) { |
| 915 | 915 | error.MalformedObject, |
| 916 | 916 | error.MalformedDylib, |
| 917 | error.MalformedTbd, | |
| 917 | 918 | error.InvalidCpuArch, |
| 918 | 919 | error.InvalidTarget, |
| 919 | 920 | => {}, // already reported |
| ... | ... | @@ -4637,7 +4638,6 @@ const ObjcStubsSection = synthetic.ObjcStubsSection; |
| 4637 | 4638 | const Object = @import("MachO/Object.zig"); |
| 4638 | 4639 | const LazyBind = bind.LazyBind; |
| 4639 | 4640 | const LaSymbolPtrSection = synthetic.LaSymbolPtrSection; |
| 4640 | const LibStub = tapi.LibStub; | |
| 4641 | 4641 | const Liveness = @import("../Liveness.zig"); |
| 4642 | 4642 | const LlvmObject = @import("../codegen/llvm.zig").Object; |
| 4643 | 4643 | const Md5 = std.crypto.hash.Md5; |
src/link/MachO/Dylib.zig+4-1| ... | ... | @@ -270,7 +270,10 @@ fn parseTbd(self: *Dylib, macho_file: *MachO) !void { |
| 270 | 270 | log.debug("parsing dylib from stub: {s}", .{self.path}); |
| 271 | 271 | |
| 272 | 272 | const file = macho_file.getFileHandle(self.file_handle); |
| 273 | var lib_stub = LibStub.loadFromFile(gpa, file) catch return error.NotLibStub; | |
| 273 | var lib_stub = LibStub.loadFromFile(gpa, file) catch |err| { | |
| 274 | try macho_file.reportParseError2(self.index, "failed to parse TBD file: {s}", .{@errorName(err)}); | |
| 275 | return error.MalformedTbd; | |
| 276 | }; | |
| 274 | 277 | defer lib_stub.deinit(); |
| 275 | 278 | const umbrella_lib = lib_stub.inner[0]; |
| 276 | 279 |
src/link/tapi.zig+9-3| ... | ... | @@ -129,8 +129,8 @@ pub const Tbd = union(enum) { |
| 129 | 129 | |
| 130 | 130 | pub const TapiError = error{ |
| 131 | 131 | NotLibStub, |
| 132 | FileTooBig, | |
| 133 | } || yaml.YamlError || std.fs.File.ReadError; | |
| 132 | InputOutput, | |
| 133 | } || yaml.YamlError || std.fs.File.PReadError; | |
| 134 | 134 | |
| 135 | 135 | pub const LibStub = struct { |
| 136 | 136 | /// Underlying memory for stub's contents. |
| ... | ... | @@ -140,8 +140,14 @@ pub const LibStub = struct { |
| 140 | 140 | inner: []Tbd, |
| 141 | 141 | |
| 142 | 142 | pub fn loadFromFile(allocator: Allocator, file: fs.File) TapiError!LibStub { |
| 143 | const source = try file.readToEndAlloc(allocator, std.math.maxInt(u32)); | |
| 143 | const filesize = blk: { | |
| 144 | const stat = file.stat() catch break :blk std.math.maxInt(u32); | |
| 145 | break :blk @min(stat.size, std.math.maxInt(u32)); | |
| 146 | }; | |
| 147 | const source = try allocator.alloc(u8, filesize); | |
| 144 | 148 | defer allocator.free(source); |
| 149 | const amt = try file.preadAll(source, 0); | |
| 150 | if (amt != filesize) return error.InputOutput; | |
| 145 | 151 | |
| 146 | 152 | var lib_stub = LibStub{ |
| 147 | 153 | .yaml = try Yaml.load(allocator, source), |