authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-10 14:33:17+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-15 18:49:47+02:00
log3bdb3b574e36962528d203a69ee1de4b39e17830
treefda7b492a7f17d0f40b02fe2f181518ed445cb85
parentdd5c7588d105c544289b6344b652133538e7e898

zld: turn logging off


3 files changed, 45 insertions(+), 39 deletions(-)

src/link/MachO/Object.zig+4-4
...@@ -451,7 +451,7 @@ const TextBlockParser = struct {...@@ -451,7 +451,7 @@ const TextBlockParser = struct {
451pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {451pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
452 const seg = self.load_commands.items[self.segment_cmd_index.?].Segment;452 const seg = self.load_commands.items[self.segment_cmd_index.?].Segment;
453453
454 log.warn("analysing {s}", .{self.name.?});454 log.debug("analysing {s}", .{self.name.?});
455455
456 const dysymtab = self.load_commands.items[self.dysymtab_cmd_index.?].Dysymtab;456 const dysymtab = self.load_commands.items[self.dysymtab_cmd_index.?].Dysymtab;
457 // We only care about defined symbols, so filter every other out.457 // We only care about defined symbols, so filter every other out.
...@@ -472,14 +472,14 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {...@@ -472,14 +472,14 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
472472
473 for (seg.sections.items) |sect, id| {473 for (seg.sections.items) |sect, id| {
474 const sect_id = @intCast(u8, id);474 const sect_id = @intCast(u8, id);
475 log.warn("putting section '{s},{s}' as a TextBlock", .{475 log.debug("putting section '{s},{s}' as a TextBlock", .{
476 segmentName(sect),476 segmentName(sect),
477 sectionName(sect),477 sectionName(sect),
478 });478 });
479479
480 // Get matching segment/section in the final artifact.480 // Get matching segment/section in the final artifact.
481 const match = (try zld.getMatchingSection(sect)) orelse {481 const match = (try zld.getMatchingSection(sect)) orelse {
482 log.warn("unhandled section", .{});482 log.debug("unhandled section", .{});
483 continue;483 continue;
484 };484 };
485485
...@@ -523,7 +523,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {...@@ -523,7 +523,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
523 const reg = &sym.payload.regular;523 const reg = &sym.payload.regular;
524 if (reg.file) |file| {524 if (reg.file) |file| {
525 if (file != self) {525 if (file != self) {
526 log.warn("deduping definition of {s} in {s}", .{ sym.name, self.name.? });526 log.debug("deduping definition of {s} in {s}", .{ sym.name, self.name.? });
527 block.deinit();527 block.deinit();
528 self.allocator.destroy(block);528 self.allocator.destroy(block);
529 continue;529 continue;
src/link/MachO/Zld.zig+38-32
...@@ -171,46 +171,52 @@ pub const TextBlock = struct {...@@ -171,46 +171,52 @@ pub const TextBlock = struct {
171 }171 }
172 }172 }
173173
174 pub fn print_this(self: *const TextBlock, zld: *Zld) void {174 pub fn format(self: *const TextBlock, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
175 log.warn("TextBlock", .{});175 _ = fmt;
176 log.warn(" | {}: {}", .{ self.local_sym_index, zld.locals.items[self.local_sym_index] });176 _ = options;
177 try std.fmt.format(writer, "TextBlock {{\n", .{});
178 try std.fmt.format(writer, " {}: {}\n", .{ self.local_sym_index, zld.locals.items[self.local_sym_index] });
177 if (self.aliases) |aliases| {179 if (self.aliases) |aliases| {
178 log.warn(" | aliases:", .{});180 try std.fmt.format(writer, " aliases:\n", .{});
179 for (aliases) |index| {181 for (aliases) |index| {
180 log.warn(" | {}: {}", .{ index, zld.locals.items[index] });182 try std.fmt.format(writer, " {}: {}\n", .{ index, zld.locals.items[index] });
181 }183 }
182 }184 }
183 if (self.references.count() > 0) {185 if (self.references.count() > 0) {
184 log.warn(" | references:", .{});186 try std.fmt.format(writer, " references:\n", .{});
185 for (self.references.keys()) |index| {187 for (self.references.keys()) |index| {
186 log.warn(" | {}: {}", .{ index, zld.locals.items[index] });188 try std.fmt.format(writer, " {}: {}\n", .{ index, zld.locals.items[index] });
187 }189 }
188 }190 }
189 if (self.contained) |contained| {191 if (self.contained) |contained| {
190 log.warn(" | contained symbols:", .{});192 try std.fmt.format(writer, " contained symbols:\n", .{});
191 for (contained) |sym_at_off| {193 for (contained) |sym_at_off| {
192 log.warn(" | {}: {}", .{ sym_at_off.offset, zld.locals.items[sym_at_off.local_sym_index] });194 try std.fmt.format(writer, " {}: {}\n", .{
195 sym_at_off.offset,
196 zld.locals.items[sym_at_off.local_sym_index],
197 });
193 }198 }
194 }199 }
195 log.warn(" | code.len = {}", .{self.code.len});200 try std.fmt.format(writer, " code.len = {}\n", .{self.code.len});
196 if (self.relocs.items.len > 0) {201 if (self.relocs.items.len > 0) {
197 log.warn(" | relocations:", .{});202 try std.fmt.format(writer, " relocations:\n", .{});
198 for (self.relocs.items) |rel| {203 for (self.relocs.items) |rel| {
199 log.warn(" | {}", .{rel});204 try std.fmt.format(writer, " {}\n", .{rel});
200 }205 }
201 }206 }
202 if (self.rebases.items.len > 0) {207 if (self.rebases.items.len > 0) {
203 log.warn(" | rebases: {any}", .{self.rebases.items});208 try std.fmt.format(writer, " rebases: {any}\n", .{self.rebases.items});
204 }209 }
205 log.warn(" | size = {}", .{self.size});210 try std.fmt.format(writer, " size = {}\n", .{self.size});
206 log.warn(" | align = {}", .{self.alignment});211 try std.fmt.format(writer, " align = {}\n", .{self.alignment});
212 try std.fmt.format(writer, "}}", .{});
207 }213 }
208214
209 pub fn print(self: *const TextBlock, zld: *Zld) void {215 pub fn print(self: *const TextBlock, zld: *Zld) void {
210 if (self.prev) |prev| {216 if (self.prev) |prev| {
211 prev.print(zld);217 prev.print(zld);
212 }218 }
213 self.print_this(zld);219 log.warn("{}\n", .{self});
214 }220 }
215};221};
216222
...@@ -317,15 +323,15 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg...@@ -317,15 +323,15 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg
317 self.allocateLinkeditSegment();323 self.allocateLinkeditSegment();
318 try self.allocateTextBlocks();324 try self.allocateTextBlocks();
319325
320 var it = self.blocks.iterator();326 // var it = self.blocks.iterator();
321 while (it.next()) |entry| {327 // while (it.next()) |entry| {
322 const seg = self.load_commands.items[entry.key_ptr.seg].Segment;328 // const seg = self.load_commands.items[entry.key_ptr.seg].Segment;
323 const sect = seg.sections.items[entry.key_ptr.sect];329 // const sect = seg.sections.items[entry.key_ptr.sect];
324330
325 log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) });331 // log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) });
326 log.warn(" {}", .{sect});332 // log.warn(" {}", .{sect});
327 entry.value_ptr.*.print(self);333 // entry.value_ptr.*.print(self);
328 }334 // }
329335
330 try self.flush();336 try self.flush();
331}337}
...@@ -1036,7 +1042,7 @@ fn allocateSegment(self: *Zld, index: u16, offset: u64) !void {...@@ -1036,7 +1042,7 @@ fn allocateSegment(self: *Zld, index: u16, offset: u64) !void {
1036}1042}
10371043
1038fn allocateTextBlocks(self: *Zld) !void {1044fn allocateTextBlocks(self: *Zld) !void {
1039 log.warn("allocating text blocks", .{});1045 log.debug("allocating text blocks", .{});
10401046
1041 var it = self.blocks.iterator();1047 var it = self.blocks.iterator();
1042 while (it.next()) |entry| {1048 while (it.next()) |entry| {
...@@ -1047,8 +1053,8 @@ fn allocateTextBlocks(self: *Zld) !void {...@@ -1047,8 +1053,8 @@ fn allocateTextBlocks(self: *Zld) !void {
1047 const sect = seg.sections.items[match.sect];1053 const sect = seg.sections.items[match.sect];
1048 var base_addr: u64 = sect.addr + sect.size;1054 var base_addr: u64 = sect.addr + sect.size;
10491055
1050 log.warn(" within section {s},{s}", .{ segmentName(sect), sectionName(sect) });1056 log.debug(" within section {s},{s}", .{ segmentName(sect), sectionName(sect) });
1051 log.warn(" {}", .{sect});1057 log.debug(" {}", .{sect});
10521058
1053 while (true) {1059 while (true) {
1054 const block_alignment = try math.powi(u32, 2, block.alignment);1060 const block_alignment = try math.powi(u32, 2, block.alignment);
...@@ -1058,7 +1064,7 @@ fn allocateTextBlocks(self: *Zld) !void {...@@ -1058,7 +1064,7 @@ fn allocateTextBlocks(self: *Zld) !void {
1058 assert(sym.payload == .regular);1064 assert(sym.payload == .regular);
1059 sym.payload.regular.address = base_addr;1065 sym.payload.regular.address = base_addr;
10601066
1061 log.warn(" {s}: start=0x{x}, end=0x{x}, size={}, align={}", .{1067 log.debug(" {s}: start=0x{x}, end=0x{x}, size={}, align={}", .{
1062 sym.name,1068 sym.name,
1063 base_addr,1069 base_addr,
1064 base_addr + block.size,1070 base_addr + block.size,
...@@ -1092,7 +1098,7 @@ fn allocateTextBlocks(self: *Zld) !void {...@@ -1092,7 +1098,7 @@ fn allocateTextBlocks(self: *Zld) !void {
1092}1098}
10931099
1094fn writeTextBlocks(self: *Zld) !void {1100fn writeTextBlocks(self: *Zld) !void {
1095 log.warn("writing text blocks", .{});1101 log.debug("writing text blocks", .{});
10961102
1097 var it = self.blocks.iterator();1103 var it = self.blocks.iterator();
1098 while (it.next()) |entry| {1104 while (it.next()) |entry| {
...@@ -1103,8 +1109,8 @@ fn writeTextBlocks(self: *Zld) !void {...@@ -1103,8 +1109,8 @@ fn writeTextBlocks(self: *Zld) !void {
1103 const sect = seg.sections.items[match.sect];1109 const sect = seg.sections.items[match.sect];
1104 const sect_type = sectionType(sect);1110 const sect_type = sectionType(sect);
11051111
1106 log.warn(" for section {s},{s}", .{ segmentName(sect), sectionName(sect) });1112 log.debug(" for section {s},{s}", .{ segmentName(sect), sectionName(sect) });
1107 log.warn(" {}", .{sect});1113 log.debug(" {}", .{sect});
11081114
1109 var code = try self.allocator.alloc(u8, sect.size);1115 var code = try self.allocator.alloc(u8, sect.size);
1110 defer self.allocator.free(code);1116 defer self.allocator.free(code);
...@@ -1120,7 +1126,7 @@ fn writeTextBlocks(self: *Zld) !void {...@@ -1120,7 +1126,7 @@ fn writeTextBlocks(self: *Zld) !void {
1120 const aligned_base_off = mem.alignBackwardGeneric(u64, unaligned_base_off, block_alignment);1126 const aligned_base_off = mem.alignBackwardGeneric(u64, unaligned_base_off, block_alignment);
11211127
1122 const sym = self.locals.items[block.local_sym_index];1128 const sym = self.locals.items[block.local_sym_index];
1123 log.warn(" {s}: start=0x{x}, end=0x{x}, size={}, align={}", .{1129 log.debug(" {s}: start=0x{x}, end=0x{x}, size={}, align={}", .{
1124 sym.name,1130 sym.name,
1125 aligned_base_off,1131 aligned_base_off,
1126 aligned_base_off + block.size,1132 aligned_base_off + block.size,
src/link/MachO/reloc.zig+3-3
...@@ -491,9 +491,9 @@ pub const Relocation = struct {...@@ -491,9 +491,9 @@ pub const Relocation = struct {
491 }491 }
492 };492 };
493493
494 log.warn("relocating {}", .{self});494 log.debug("relocating {}", .{self});
495 log.warn(" | source_addr = 0x{x}", .{source_addr});495 log.debug(" | source_addr = 0x{x}", .{source_addr});
496 log.warn(" | target_addr = 0x{x}", .{target_addr});496 log.debug(" | target_addr = 0x{x}", .{target_addr});
497497
498 switch (self.payload) {498 switch (self.payload) {
499 .unsigned => |unsigned| try unsigned.resolve(self, source_addr, target_addr),499 .unsigned => |unsigned| try unsigned.resolve(self, source_addr, target_addr),