| author | |
| committer | |
| log | 68680bbd00ae43cd25d8c613d666bd1554d67131 |
| tree | 7c94918b36dd64ddc974e2bad0f9103f5d226945 |
| parent | 5dab6a4533dbb5222be5b6309eea25115659bacf |
3 files changed, 19 insertions(+), 18 deletions(-)
src/Compilation.zig+3-2| ... | ... | @@ -3528,7 +3528,7 @@ fn emitFromCObject( |
| 3528 | 3528 | /// Having the file open for writing is problematic as far as executing the |
| 3529 | 3529 | /// binary is concerned. This will remove the write flag, or close the file, |
| 3530 | 3530 | /// or whatever is needed so that it can be executed. |
| 3531 | /// After this, one must call` makeFileWritable` before calling `update`. | |
| 3531 | /// After this, one must call `makeFileWritable` before calling `update`. | |
| 3532 | 3532 | pub fn makeBinFileExecutable(comp: *Compilation) !void { |
| 3533 | 3533 | if (!dev.env.supports(.make_executable)) return; |
| 3534 | 3534 | const lf = comp.bin_file orelse return; |
| ... | ... | @@ -3537,7 +3537,8 @@ pub fn makeBinFileExecutable(comp: *Compilation) !void { |
| 3537 | 3537 | |
| 3538 | 3538 | pub fn makeBinFileWritable(comp: *Compilation) !void { |
| 3539 | 3539 | const lf = comp.bin_file orelse return; |
| 3540 | return lf.makeWritable(); | |
| 3540 | if (lf.canMakeExecutable()) | |
| 3541 | try lf.makeWritable(); | |
| 3541 | 3542 | } |
| 3542 | 3543 | |
| 3543 | 3544 | const Header = extern struct { |
src/link.zig+14-8| ... | ... | @@ -689,18 +689,24 @@ pub const File = struct { |
| 689 | 689 | return macho.reopenDebugInfo(); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | pub fn canMakeExecutable(base: *File) bool { | |
| 693 | const comp = base.comp; | |
| 694 | return switch (comp.config.output_mode) { | |
| 695 | .Obj => false, | |
| 696 | .Lib => switch (comp.config.link_mode) { | |
| 697 | .static => false, | |
| 698 | .dynamic => true, | |
| 699 | }, | |
| 700 | .Exe => true, | |
| 701 | }; | |
| 702 | } | |
| 703 | ||
| 692 | 704 | pub fn makeExecutable(base: *File) !void { |
| 693 | 705 | dev.check(.make_executable); |
| 694 | 706 | const comp = base.comp; |
| 695 | 707 | const io = comp.io; |
| 696 | switch (comp.config.output_mode) { | |
| 697 | .Obj => return, | |
| 698 | .Lib => switch (comp.config.link_mode) { | |
| 699 | .static => return, | |
| 700 | .dynamic => {}, | |
| 701 | }, | |
| 702 | .Exe => {}, | |
| 703 | } | |
| 708 | if (!base.canMakeExecutable()) | |
| 709 | return; | |
| 704 | 710 | switch (base.tag) { |
| 705 | 711 | .lld => assert(base.file == null), |
| 706 | 712 | .elf => if (base.file) |f| { |
src/main.zig+2-8| ... | ... | @@ -4440,12 +4440,8 @@ fn serve( |
| 4440 | 4440 | continue; |
| 4441 | 4441 | } |
| 4442 | 4442 | |
| 4443 | if (comp.config.output_mode == .Exe) { | |
| 4444 | try comp.makeBinFileWritable(); | |
| 4445 | } | |
| 4446 | ||
| 4443 | try comp.makeBinFileWritable(); | |
| 4447 | 4444 | try comp.update(main_progress_node); |
| 4448 | ||
| 4449 | 4445 | try comp.makeBinFileExecutable(); |
| 4450 | 4446 | try serveUpdateResults(&server, comp); |
| 4451 | 4447 | }, |
| ... | ... | @@ -4476,9 +4472,7 @@ fn serve( |
| 4476 | 4472 | try comp.hotCodeSwap(main_progress_node, pid); |
| 4477 | 4473 | try serveUpdateResults(&server, comp); |
| 4478 | 4474 | } else { |
| 4479 | if (comp.config.output_mode == .Exe) { | |
| 4480 | try comp.makeBinFileWritable(); | |
| 4481 | } | |
| 4475 | try comp.makeBinFileWritable(); | |
| 4482 | 4476 | try comp.update(main_progress_node); |
| 4483 | 4477 | try comp.makeBinFileExecutable(); |
| 4484 | 4478 | try serveUpdateResults(&server, comp); |