diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-26 20:57:22 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-26 21:07:47 +0200 |
| commit | e30f396b732f7fcb68a701f1b385bb47eba48b89 (patch) | |
| tree | 1cc9dd4111307feff3ba80ddf1265dd174fc4a82 /src/link.zig | |
| parent | 7617486f1d3d79f08d9d7a8641674c2525e83235 (diff) | |
| download | zig-e30f396b732f7fcb68a701f1b385bb47eba48b89.tar.gz zig-e30f396b732f7fcb68a701f1b385bb47eba48b89.zip | |
elf: properly close the output file when linking
Diffstat (limited to 'src/link.zig')
| -rw-r--r-- | src/link.zig | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/link.zig b/src/link.zig index fb71262f66..214d538df9 100644 --- a/src/link.zig +++ b/src/link.zig @@ -456,9 +456,10 @@ pub const File = struct { .Exe => {}, } switch (base.tag) { - .coff, .elf, .macho, .plan9, .wasm => if (base.file) |f| { + .elf => if (base.file) |f| { if (build_options.only_c) unreachable; - if (base.intermediary_basename != null) { + const use_lld = build_options.have_llvm and base.options.use_lld; + if (base.intermediary_basename != null and use_lld) { // The file we have open is not the final file that we want to // make executable, so we don't have to close it. return; @@ -471,6 +472,22 @@ pub const File = struct { .linux => std.os.ptrace(std.os.linux.PTRACE.DETACH, pid, 0, 0) catch |err| { log.warn("ptrace failure: {s}", .{@errorName(err)}); }, + else => return error.HotSwapUnavailableOnHostOperatingSystem, + } + } + }, + .coff, .macho, .plan9, .wasm => if (base.file) |f| { + if (build_options.only_c) unreachable; + if (base.intermediary_basename != null) { + // The file we have open is not the final file that we want to + // make executable, so we don't have to close it. + return; + } + f.close(); + base.file = null; + + if (base.child_pid) |pid| { + switch (builtin.os.tag) { .macos => base.cast(MachO).?.ptraceDetach(pid) catch |err| { log.warn("detaching failed with error: {s}", .{@errorName(err)}); }, |
