diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 32d4d382356865033a042f8583fbe3ed49d9701b..3ee34682e939a06e07e0781d3a616e65d6521cf0 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -134,16 +134,14 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option return createEmpty(allocator, options); } + const self = try createEmpty(allocator, options); + errdefer self.base.destroy(); + const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = false, .read = true, .mode = link.determineMode(options), }); - errdefer file.close(); - - const self = try createEmpty(allocator, options); - errdefer self.base.destroy(); - self.base.file = file; // TODO Write object specific relocations, COFF symbol table, then enable object file output. diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 467bbeee54d346a87f9b3ec45d6c28de55990eb1..08903f7c05e9489728d3a5f1051fd63e7289b165 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -299,15 +299,14 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option return createEmpty(allocator, options); } + const self = try createEmpty(allocator, options); + errdefer self.base.destroy(); + const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = false, .read = true, .mode = link.determineMode(options), }); - errdefer file.close(); - - const self = try createEmpty(allocator, options); - errdefer self.base.destroy(); self.base.file = file; self.shdr_table_dirty = true; diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index 4eaa6ed26b162c1f6fd627f389c36ce2d1de35d7..4648a6a673f7d8e398ccad2964d41f2d36b8d7d5 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -643,14 +643,16 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option if (options.use_llvm) return error.LLVMBackendDoesNotSupportPlan9; assert(options.object_format == .plan9); + + const self = try createEmpty(allocator, options); + errdefer self.base.destroy(); + const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .read = true, .mode = link.determineMode(options), }); errdefer file.close(); - - const self = try createEmpty(allocator, options); - errdefer self.base.destroy(); + self.base.file = file; self.bases = defaultBaseAddrs(options.target.cpu.arch); @@ -673,7 +675,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option }, }); - self.base.file = file; return self; } diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig index ee3205c9f50950c593e8951185713ac2a54259b9..19cb1373ef19525fd33a01f8a4a1aa9492b6b5cf 100644 --- a/src/link/SpirV.zig +++ b/src/link/SpirV.zig @@ -104,13 +104,11 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option if (options.use_llvm) return error.LLVM_BackendIsTODO_ForSpirV; // TODO: LLVM Doesn't support SpirV at all. if (options.use_lld) return error.LLD_LinkingIsTODO_ForSpirV; // TODO: LLD Doesn't support SpirV at all. - // TODO: read the file and keep valid parts instead of truncating - const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = true, .read = true }); - errdefer file.close(); - const spirv = try createEmpty(allocator, options); errdefer spirv.base.destroy(); + // TODO: read the file and keep valid parts instead of truncating + const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = true, .read = true }); spirv.base.file = file; return spirv; } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 81d77d5b66094aef25914b2fffc475d0c826d8dc..8f6dfacf4619c1e31e6491d27b793fbf23861227 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -105,13 +105,11 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option return createEmpty(allocator, options); } - // TODO: read the file and keep valid parts instead of truncating - const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = true, .read = true }); - errdefer file.close(); - const wasm_bin = try createEmpty(allocator, options); errdefer wasm_bin.base.destroy(); + // TODO: read the file and keep valid parts instead of truncating + const file = try options.emit.?.directory.handle.createFile(sub_path, .{ .truncate = true, .read = true }); wasm_bin.base.file = file; try file.writeAll(&(wasm.magic ++ wasm.version));