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