authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-03 21:57:26+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-03 21:57:26+01:00
logd3be4992708e7e6631df52fb5f4ccb0f521a77de
tree98a510e9642674b50d703f406db9d57ef3c42269
parent5cba16c707fd4c46aeeabebdcc85d06b9149d6e4

lld+macho: address review comments


3 files changed, 16 insertions(+), 20 deletions(-)

src/link.zig+8
...@@ -238,6 +238,14 @@ pub const File = struct {...@@ -238,6 +238,14 @@ pub const File = struct {
238 }238 }
239239
240 pub fn makeExecutable(base: *File) !void {240 pub fn makeExecutable(base: *File) !void {
241 switch (base.options.output_mode) {
242 .Obj => return,
243 .Lib => switch (base.options.link_mode) {
244 .Static => return,
245 .Dynamic => {},
246 },
247 .Exe => {},
248 }
241 switch (base.tag) {249 switch (base.tag) {
242 .macho => if (base.file) |f| {250 .macho => if (base.file) |f| {
243 if (base.intermediary_basename != null) {251 if (base.intermediary_basename != null) {
src/link/MachO.zig+6-6
...@@ -681,7 +681,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -681,7 +681,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
681 if (result.term != .Exited or result.term.Exited != 0) {681 if (result.term != .Exited or result.term.Exited != 0) {
682 // TODO parse this output and surface with the Compilation API rather than682 // TODO parse this output and surface with the Compilation API rather than
683 // directly outputting to stderr here.683 // directly outputting to stderr here.
684 std.debug.print("{}", .{result.stderr});684 std.log.err("{}", .{result.stderr});
685 return error.LDReportedFailure;685 return error.LDReportedFailure;
686 }686 }
687 } else {687 } else {
...@@ -716,7 +716,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -716,7 +716,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
716 if (!ok) {716 if (!ok) {
717 // TODO parse this output and surface with the Compilation API rather than717 // TODO parse this output and surface with the Compilation API rather than
718 // directly outputting to stderr here.718 // directly outputting to stderr here.
719 std.debug.print("{}", .{stderr_context.data.items});719 std.log.err("{}", .{stderr_context.data.items});
720 return error.LLDReportedFailure;720 return error.LLDReportedFailure;
721 }721 }
722 if (stderr_context.data.items.len != 0) {722 if (stderr_context.data.items.len != 0) {
...@@ -736,10 +736,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -736,10 +736,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
736 // TODO We are in the position to be able to increase the padding by moving all sections736 // TODO We are in the position to be able to increase the padding by moving all sections
737 // by the required offset, but this requires a little bit more thinking and bookkeeping.737 // by the required offset, but this requires a little bit more thinking and bookkeeping.
738 // For now, return an error informing the user of the problem.738 // For now, return an error informing the user of the problem.
739 std.debug.print("Not enough padding between load commands and start of __text section:\n", .{});739 std.log.err("Not enough padding between load commands and start of __text section:\n", .{});
740 std.debug.print("Offset after last load command: 0x{x}\n", .{after_last_cmd_offset});740 std.log.err("Offset after last load command: 0x{x}\n", .{after_last_cmd_offset});
741 std.debug.print("Beginning of __text section: 0x{x}\n", .{text_section.offset});741 std.log.err("Beginning of __text section: 0x{x}\n", .{text_section.offset});
742 std.debug.print("Needed size: 0x{x}\n", .{needed_size});742 std.log.err("Needed size: 0x{x}\n", .{needed_size});
743 return error.NotEnoughPadding;743 return error.NotEnoughPadding;
744 }744 }
745 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;745 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
src/main.zig+2-14
...@@ -1773,17 +1773,7 @@ fn buildOutputType(...@@ -1773,17 +1773,7 @@ fn buildOutputType(
1773 error.SemanticAnalyzeFail => process.exit(1),1773 error.SemanticAnalyzeFail => process.exit(1),
1774 else => |e| return e,1774 else => |e| return e,
1775 };1775 };
1776 switch (output_mode) {1776 try comp.makeBinFileExecutable();
1777 .Exe => try comp.makeBinFileExecutable(),
1778 .Lib => {
1779 if (link_mode) |lm| {
1780 if (lm == .Dynamic) {
1781 try comp.makeBinFileExecutable();
1782 }
1783 }
1784 },
1785 else => {},
1786 }
17871777
1788 if (build_options.is_stage1 and comp.stage1_lock != null and watch) {1778 if (build_options.is_stage1 and comp.stage1_lock != null and watch) {
1789 warn("--watch is not recommended with the stage1 backend; it leaks memory and is not capable of incremental compilation", .{});1779 warn("--watch is not recommended with the stage1 backend; it leaks memory and is not capable of incremental compilation", .{});
...@@ -1882,9 +1872,7 @@ fn buildOutputType(...@@ -1882,9 +1872,7 @@ fn buildOutputType(
18821872
1883 while (watch) {1873 while (watch) {
1884 try stderr.print("(zig) ", .{});1874 try stderr.print("(zig) ", .{});
1885 if (output_mode == .Exe) {1875 try comp.makeBinFileExecutable();
1886 try comp.makeBinFileExecutable();
1887 }
1888 if (stdin.readUntilDelimiterOrEof(&repl_buf, '\n') catch |err| {1876 if (stdin.readUntilDelimiterOrEof(&repl_buf, '\n') catch |err| {
1889 try stderr.print("\nUnable to parse command: {}\n", .{@errorName(err)});1877 try stderr.print("\nUnable to parse command: {}\n", .{@errorName(err)});
1890 continue;1878 continue;