diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-06 13:47:39 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-06 13:47:39 +0100 |
| commit | 281dabaa880a8099b0fff752c8e1f4bdd5eec423 (patch) | |
| tree | 366e50e1236804bd792c9fd7373ada7bf4eaca9d /src | |
| parent | 205f8214d8ddbc0d2bc0c7ba75e10688e260acfa (diff) | |
| download | zig-281dabaa880a8099b0fff752c8e1f4bdd5eec423.tar.gz zig-281dabaa880a8099b0fff752c8e1f4bdd5eec423.zip | |
Compilation: unconditionally close open file handles for writable dance
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 10 | ||||
| -rw-r--r-- | src/link/Elf.zig | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index f2a0fb5e63..e7216abe56 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2295,10 +2295,16 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void defer comp.gpa.free(o_sub_path); // Work around windows `AccessDenied` if any files within this directory are open - // by doing the makeExecutable/makeWritable dance. + // by closing and reopening the file handles. const need_writable_dance = builtin.os.tag == .windows and comp.bin_file.file != null; if (need_writable_dance) { - try comp.bin_file.makeExecutable(); + // We cannot just call `makeExecutable` as it makes a false assumption that we have a + // file handle open only when linking an executable file. This used to be true when + // our linkers were incapable of emitting relocatables and static archive. Now that + // they are capable, we need to unconditionally close the file handle and re-open it + // in the follow up call to `makeWritable`. + comp.bin_file.file.?.close(); + comp.bin_file.file = null; } try comp.bin_file.renameTmpIntoCache(comp.local_cache_directory, tmp_dir_sub_path, o_sub_path); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 786f5eacac..969ba53d87 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -943,7 +943,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node if (self.isObject() and self.zig_object_index == null) { // TODO this will become -r route I guess. For now, just copy the object file. - assert(self.base.file == null); // TODO uncomment once we implement -r const the_object_path = blk: { if (self.base.options.objects.len != 0) { break :blk self.base.options.objects[0].path; |
