authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-10 21:48:06+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-15 18:49:47+02:00
log714e0c47612e375ac7148bc177ac7bc543c80243
tree9f80bbfd377fd959e438c69c61c1ed6cce707b7d
parent7aefea614f570f489366a7fbde1a98eaf2551fc6

zld: re-enable logging of TextBlocks


1 files changed, 24 insertions(+), 27 deletions(-)

src/link/MachO/Zld.zig+24-27
......@@ -171,52 +171,49 @@ pub const TextBlock = struct {
171171 }
172172 }
173173
174 pub fn format(self: *const TextBlock, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
175 _ = fmt;
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] });
174 pub fn print_this(self: *const TextBlock, zld: *Zld) void {
175 log.warn("TextBlock", .{});
176 log.warn(" {}: {}", .{ self.local_sym_index, zld.locals.items[self.local_sym_index] });
179177 if (self.aliases) |aliases| {
180 try std.fmt.format(writer, " aliases:\n", .{});
178 log.warn(" aliases:", .{});
181179 for (aliases) |index| {
182 try std.fmt.format(writer, " {}: {}\n", .{ index, zld.locals.items[index] });
180 log.warn(" {}: {}", .{ index, zld.locals.items[index] });
183181 }
184182 }
185183 if (self.references.count() > 0) {
186 try std.fmt.format(writer, " references:\n", .{});
184 log.warn(" references:", .{});
187185 for (self.references.keys()) |index| {
188 try std.fmt.format(writer, " {}: {}\n", .{ index, zld.locals.items[index] });
186 log.warn(" {}: {}", .{ index, zld.locals.items[index] });
189187 }
190188 }
191189 if (self.contained) |contained| {
192 try std.fmt.format(writer, " contained symbols:\n", .{});
190 log.warn(" contained symbols:", .{});
193191 for (contained) |sym_at_off| {
194 try std.fmt.format(writer, " {}: {}\n", .{
192 log.warn(" {}: {}\n", .{
195193 sym_at_off.offset,
196194 zld.locals.items[sym_at_off.local_sym_index],
197195 });
198196 }
199197 }
200 try std.fmt.format(writer, " code.len = {}\n", .{self.code.len});
198 log.warn(" code.len = {}", .{self.code.len});
201199 if (self.relocs.items.len > 0) {
202 try std.fmt.format(writer, " relocations:\n", .{});
200 log.warn(" relocations:", .{});
203201 for (self.relocs.items) |rel| {
204 try std.fmt.format(writer, " {}\n", .{rel});
202 log.warn(" {}", .{rel});
205203 }
206204 }
207205 if (self.rebases.items.len > 0) {
208 try std.fmt.format(writer, " rebases: {any}\n", .{self.rebases.items});
206 log.warn(" rebases: {any}", .{self.rebases.items});
209207 }
210 try std.fmt.format(writer, " size = {}\n", .{self.size});
211 try std.fmt.format(writer, " align = {}\n", .{self.alignment});
212 try std.fmt.format(writer, "}}", .{});
208 log.warn(" size = {}", .{self.size});
209 log.warn(" align = {}", .{self.alignment});
213210 }
214211
215212 pub fn print(self: *const TextBlock, zld: *Zld) void {
216213 if (self.prev) |prev| {
217214 prev.print(zld);
218215 }
219 log.warn("{}\n", .{self});
216 self.print_this(zld);
220217 }
221218};
222219
......@@ -323,15 +320,15 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg
323320 self.allocateLinkeditSegment();
324321 try self.allocateTextBlocks();
325322
326 // var it = self.blocks.iterator();
327 // while (it.next()) |entry| {
328 // const seg = self.load_commands.items[entry.key_ptr.seg].Segment;
329 // const sect = seg.sections.items[entry.key_ptr.sect];
323 var it = self.blocks.iterator();
324 while (it.next()) |entry| {
325 const seg = self.load_commands.items[entry.key_ptr.seg].Segment;
326 const sect = seg.sections.items[entry.key_ptr.sect];
330327
331 // log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) });
332 // log.warn(" {}", .{sect});
333 // entry.value_ptr.*.print(self);
334 // }
328 log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) });
329 log.warn(" {}", .{sect});
330 entry.value_ptr.*.print(self);
331 }
335332
336333 try self.flush();
337334}