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 {
238238 }
239239
240240 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 }
241249 switch (base.tag) {
242250 .macho => if (base.file) |f| {
243251 if (base.intermediary_basename != null) {
src/link/MachO.zig+6-6
......@@ -681,7 +681,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
681681 if (result.term != .Exited or result.term.Exited != 0) {
682682 // TODO parse this output and surface with the Compilation API rather than
683683 // directly outputting to stderr here.
684 std.debug.print("{}", .{result.stderr});
684 std.log.err("{}", .{result.stderr});
685685 return error.LDReportedFailure;
686686 }
687687 } else {
......@@ -716,7 +716,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
716716 if (!ok) {
717717 // TODO parse this output and surface with the Compilation API rather than
718718 // directly outputting to stderr here.
719 std.debug.print("{}", .{stderr_context.data.items});
719 std.log.err("{}", .{stderr_context.data.items});
720720 return error.LLDReportedFailure;
721721 }
722722 if (stderr_context.data.items.len != 0) {
......@@ -736,10 +736,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
736736 // TODO We are in the position to be able to increase the padding by moving all sections
737737 // by the required offset, but this requires a little bit more thinking and bookkeeping.
738738 // 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", .{});
740 std.debug.print("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});
742 std.debug.print("Needed size: 0x{x}\n", .{needed_size});
739 std.log.err("Not enough padding between load commands and start of __text section:\n", .{});
740 std.log.err("Offset after last load command: 0x{x}\n", .{after_last_cmd_offset});
741 std.log.err("Beginning of __text section: 0x{x}\n", .{text_section.offset});
742 std.log.err("Needed size: 0x{x}\n", .{needed_size});
743743 return error.NotEnoughPadding;
744744 }
745745 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
src/main.zig+2-14
......@@ -1773,17 +1773,7 @@ fn buildOutputType(
17731773 error.SemanticAnalyzeFail => process.exit(1),
17741774 else => |e| return e,
17751775 };
1776 switch (output_mode) {
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 }
1776 try comp.makeBinFileExecutable();
17871777
17881778 if (build_options.is_stage1 and comp.stage1_lock != null and watch) {
17891779 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(
18821872
18831873 while (watch) {
18841874 try stderr.print("(zig) ", .{});
1885 if (output_mode == .Exe) {
1886 try comp.makeBinFileExecutable();
1887 }
1875 try comp.makeBinFileExecutable();
18881876 if (stdin.readUntilDelimiterOrEof(&repl_buf, '\n') catch |err| {
18891877 try stderr.print("\nUnable to parse command: {}\n", .{@errorName(err)});
18901878 continue;