| ... | @@ -171,52 +171,49 @@ pub const TextBlock = struct { | ... | @@ -171,52 +171,49 @@ pub const TextBlock = struct { |
| 171 | } | 171 | } |
| 172 | } | 172 | } |
| 173 | | 173 | |
| 174 | pub fn format(self: *const TextBlock, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { | 174 | pub fn print_this(self: *const TextBlock, zld: *Zld) void { |
| 175 | _ = fmt; | 175 | log.warn("TextBlock", .{}); |
| 176 | _ = options; | 176 | log.warn(" {}: {}", .{ self.local_sym_index, zld.locals.items[self.local_sym_index] }); |
| 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] }); | | |
| 179 | if (self.aliases) |aliases| { | 177 | if (self.aliases) |aliases| { |
| 180 | try std.fmt.format(writer, " aliases:\n", .{}); | 178 | log.warn(" aliases:", .{}); |
| 181 | for (aliases) |index| { | 179 | for (aliases) |index| { |
| 182 | try std.fmt.format(writer, " {}: {}\n", .{ index, zld.locals.items[index] }); | 180 | log.warn(" {}: {}", .{ index, zld.locals.items[index] }); |
| 183 | } | 181 | } |
| 184 | } | 182 | } |
| 185 | if (self.references.count() > 0) { | 183 | if (self.references.count() > 0) { |
| 186 | try std.fmt.format(writer, " references:\n", .{}); | 184 | log.warn(" references:", .{}); |
| 187 | for (self.references.keys()) |index| { | 185 | 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] }); |
| 189 | } | 187 | } |
| 190 | } | 188 | } |
| 191 | if (self.contained) |contained| { | 189 | if (self.contained) |contained| { |
| 192 | try std.fmt.format(writer, " contained symbols:\n", .{}); | 190 | log.warn(" contained symbols:", .{}); |
| 193 | for (contained) |sym_at_off| { | 191 | for (contained) |sym_at_off| { |
| 194 | try std.fmt.format(writer, " {}: {}\n", .{ | 192 | log.warn(" {}: {}\n", .{ |
| 195 | sym_at_off.offset, | 193 | sym_at_off.offset, |
| 196 | zld.locals.items[sym_at_off.local_sym_index], | 194 | zld.locals.items[sym_at_off.local_sym_index], |
| 197 | }); | 195 | }); |
| 198 | } | 196 | } |
| 199 | } | 197 | } |
| 200 | try std.fmt.format(writer, " code.len = {}\n", .{self.code.len}); | 198 | log.warn(" code.len = {}", .{self.code.len}); |
| 201 | if (self.relocs.items.len > 0) { | 199 | if (self.relocs.items.len > 0) { |
| 202 | try std.fmt.format(writer, " relocations:\n", .{}); | 200 | log.warn(" relocations:", .{}); |
| 203 | for (self.relocs.items) |rel| { | 201 | for (self.relocs.items) |rel| { |
| 204 | try std.fmt.format(writer, " {}\n", .{rel}); | 202 | log.warn(" {}", .{rel}); |
| 205 | } | 203 | } |
| 206 | } | 204 | } |
| 207 | if (self.rebases.items.len > 0) { | 205 | 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}); |
| 209 | } | 207 | } |
| 210 | try std.fmt.format(writer, " size = {}\n", .{self.size}); | 208 | log.warn(" size = {}", .{self.size}); |
| 211 | try std.fmt.format(writer, " align = {}\n", .{self.alignment}); | 209 | log.warn(" align = {}", .{self.alignment}); |
| 212 | try std.fmt.format(writer, "}}", .{}); | | |
| 213 | } | 210 | } |
| 214 | | 211 | |
| 215 | pub fn print(self: *const TextBlock, zld: *Zld) void { | 212 | pub fn print(self: *const TextBlock, zld: *Zld) void { |
| 216 | if (self.prev) |prev| { | 213 | if (self.prev) |prev| { |
| 217 | prev.print(zld); | 214 | prev.print(zld); |
| 218 | } | 215 | } |
| 219 | log.warn("{}\n", .{self}); | 216 | self.print_this(zld); |
| 220 | } | 217 | } |
| 221 | }; | 218 | }; |
| 222 | | 219 | |
| ... | @@ -323,15 +320,15 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg | ... | @@ -323,15 +320,15 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg |
| 323 | self.allocateLinkeditSegment(); | 320 | self.allocateLinkeditSegment(); |
| 324 | try self.allocateTextBlocks(); | 321 | try self.allocateTextBlocks(); |
| 325 | | 322 | |
| 326 | // var it = self.blocks.iterator(); | 323 | var it = self.blocks.iterator(); |
| 327 | // while (it.next()) |entry| { | 324 | while (it.next()) |entry| { |
| 328 | // const seg = self.load_commands.items[entry.key_ptr.seg].Segment; | 325 | const seg = self.load_commands.items[entry.key_ptr.seg].Segment; |
| 329 | // const sect = seg.sections.items[entry.key_ptr.sect]; | 326 | const sect = seg.sections.items[entry.key_ptr.sect]; |
| 330 | | 327 | |
| 331 | // log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) }); | 328 | log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) }); |
| 332 | // log.warn(" {}", .{sect}); | 329 | log.warn(" {}", .{sect}); |
| 333 | // entry.value_ptr.*.print(self); | 330 | entry.value_ptr.*.print(self); |
| 334 | // } | 331 | } |
| 335 | | 332 | |
| 336 | try self.flush(); | 333 | try self.flush(); |
| 337 | } | 334 | } |