| author | |
| committer | |
| log | 9f20a51555169dfcc531b06390001d3dbd78094d |
| tree | 47ae420955c05643de8dcfa556f48585df3fc1fd |
| parent | fccac48a55f91abfa6f04dc7274639a9faf5ab53 |
3 files changed, 56 insertions(+), 55 deletions(-)
src/link/MachO/Object.zig+4-4| ... | @@ -486,7 +486,7 @@ const TextBlockParser = struct { | ... | @@ -486,7 +486,7 @@ const TextBlockParser = struct { |
| 486 | pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | 486 | pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { |
| 487 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; | 487 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; |
| 488 | 488 | ||
| 489 | log.warn("analysing {s}", .{self.name.?}); | 489 | log.debug("analysing {s}", .{self.name.?}); |
| 490 | 490 | ||
| 491 | const dysymtab = self.load_commands.items[self.dysymtab_cmd_index.?].Dysymtab; | 491 | const dysymtab = self.load_commands.items[self.dysymtab_cmd_index.?].Dysymtab; |
| 492 | // We only care about defined symbols, so filter every other out. | 492 | // We only care about defined symbols, so filter every other out. |
| ... | @@ -507,14 +507,14 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | ... | @@ -507,14 +507,14 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { |
| 507 | 507 | ||
| 508 | for (seg.sections.items) |sect, id| { | 508 | for (seg.sections.items) |sect, id| { |
| 509 | const sect_id = @intCast(u8, id); | 509 | const sect_id = @intCast(u8, id); |
| 510 | log.warn("putting section '{s},{s}' as a TextBlock", .{ | 510 | log.debug("putting section '{s},{s}' as a TextBlock", .{ |
| 511 | segmentName(sect), | 511 | segmentName(sect), |
| 512 | sectionName(sect), | 512 | sectionName(sect), |
| 513 | }); | 513 | }); |
| 514 | 514 | ||
| 515 | // Get matching segment/section in the final artifact. | 515 | // Get matching segment/section in the final artifact. |
| 516 | const match = (try zld.getMatchingSection(sect)) orelse { | 516 | const match = (try zld.getMatchingSection(sect)) orelse { |
| 517 | log.warn("unhandled section", .{}); | 517 | log.debug("unhandled section", .{}); |
| 518 | continue; | 518 | continue; |
| 519 | }; | 519 | }; |
| 520 | 520 | ||
| ... | @@ -533,7 +533,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { | ... | @@ -533,7 +533,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void { |
| 533 | const filtered_nlists = NlistWithIndex.filterInSection(sorted_nlists.items, sect); | 533 | const filtered_nlists = NlistWithIndex.filterInSection(sorted_nlists.items, sect); |
| 534 | 534 | ||
| 535 | // Is there any padding between symbols within the section? | 535 | // Is there any padding between symbols within the section? |
| 536 | const is_splittable = self.header.?.flags & macho.MH_SUBSECTIONS_VIA_SYMBOLS != 0; | 536 | // const is_splittable = self.header.?.flags & macho.MH_SUBSECTIONS_VIA_SYMBOLS != 0; |
| 537 | // TODO is it perhaps worth skip parsing subsections in Debug mode and not worry about | 537 | // TODO is it perhaps worth skip parsing subsections in Debug mode and not worry about |
| 538 | // duplicates at all? Need some benchmarks! | 538 | // duplicates at all? Need some benchmarks! |
| 539 | // const is_splittable = false; | 539 | // const is_splittable = false; |
src/link/MachO/TextBlock.zig+6-5| ... | @@ -695,7 +695,7 @@ pub fn parseRelocsFromObject( | ... | @@ -695,7 +695,7 @@ pub fn parseRelocsFromObject( |
| 695 | .ARM64_RELOC_GOT_LOAD_PAGEOFF12, | 695 | .ARM64_RELOC_GOT_LOAD_PAGEOFF12, |
| 696 | .ARM64_RELOC_TLVP_LOAD_PAGEOFF12, | 696 | .ARM64_RELOC_TLVP_LOAD_PAGEOFF12, |
| 697 | => { | 697 | => { |
| 698 | self.parsePageOff(rel, &parsed_rel, addend, ctx); | 698 | self.parsePageOff(rel, &parsed_rel, addend); |
| 699 | if (rel_type == .ARM64_RELOC_PAGEOFF12) | 699 | if (rel_type == .ARM64_RELOC_PAGEOFF12) |
| 700 | addend = 0; | 700 | addend = 0; |
| 701 | }, | 701 | }, |
| ... | @@ -866,6 +866,7 @@ fn parseUnsigned( | ... | @@ -866,6 +866,7 @@ fn parseUnsigned( |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | fn parseBranch(self: TextBlock, rel: macho.relocation_info, out: *Relocation, ctx: RelocContext) void { | 868 | fn parseBranch(self: TextBlock, rel: macho.relocation_info, out: *Relocation, ctx: RelocContext) void { |
| 869 | _ = self; | ||
| 869 | assert(rel.r_pcrel == 1); | 870 | assert(rel.r_pcrel == 1); |
| 870 | assert(rel.r_length == 2); | 871 | assert(rel.r_length == 2); |
| 871 | 872 | ||
| ... | @@ -894,7 +895,7 @@ fn parsePage(self: TextBlock, rel: macho.relocation_info, out: *Relocation, adde | ... | @@ -894,7 +895,7 @@ fn parsePage(self: TextBlock, rel: macho.relocation_info, out: *Relocation, adde |
| 894 | }; | 895 | }; |
| 895 | } | 896 | } |
| 896 | 897 | ||
| 897 | fn parsePageOff(self: TextBlock, rel: macho.relocation_info, out: *Relocation, addend: u32, ctx: RelocContext) void { | 898 | fn parsePageOff(self: TextBlock, rel: macho.relocation_info, out: *Relocation, addend: u32) void { |
| 898 | assert(rel.r_pcrel == 0); | 899 | assert(rel.r_pcrel == 0); |
| 899 | assert(rel.r_length == 2); | 900 | assert(rel.r_length == 2); |
| 900 | 901 | ||
| ... | @@ -987,7 +988,7 @@ fn parseLoad(self: TextBlock, rel: macho.relocation_info, out: *Relocation) void | ... | @@ -987,7 +988,7 @@ fn parseLoad(self: TextBlock, rel: macho.relocation_info, out: *Relocation) void |
| 987 | 988 | ||
| 988 | pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { | 989 | pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { |
| 989 | for (self.relocs.items) |rel| { | 990 | for (self.relocs.items) |rel| { |
| 990 | log.warn("relocating {}", .{rel}); | 991 | log.debug("relocating {}", .{rel}); |
| 991 | 992 | ||
| 992 | const source_addr = blk: { | 993 | const source_addr = blk: { |
| 993 | const sym = zld.locals.items[self.local_sym_index]; | 994 | const sym = zld.locals.items[self.local_sym_index]; |
| ... | @@ -1073,8 +1074,8 @@ pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { | ... | @@ -1073,8 +1074,8 @@ pub fn resolveRelocs(self: *TextBlock, zld: *Zld) !void { |
| 1073 | } | 1074 | } |
| 1074 | }; | 1075 | }; |
| 1075 | 1076 | ||
| 1076 | log.warn(" | source_addr = 0x{x}", .{source_addr}); | 1077 | log.debug(" | source_addr = 0x{x}", .{source_addr}); |
| 1077 | log.warn(" | target_addr = 0x{x}", .{target_addr}); | 1078 | log.debug(" | target_addr = 0x{x}", .{target_addr}); |
| 1078 | 1079 | ||
| 1079 | try rel.resolve(.{ | 1080 | try rel.resolve(.{ |
| 1080 | .block = self, | 1081 | .block = self, |
src/link/MachO/Zld.zig+46-46| ... | @@ -253,58 +253,58 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg | ... | @@ -253,58 +253,58 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg |
| 253 | self.allocateLinkeditSegment(); | 253 | self.allocateLinkeditSegment(); |
| 254 | try self.allocateTextBlocks(); | 254 | try self.allocateTextBlocks(); |
| 255 | 255 | ||
| 256 | log.warn("locals", .{}); | 256 | // log.warn("locals", .{}); |
| 257 | for (self.locals.items) |sym, id| { | 257 | // for (self.locals.items) |sym, id| { |
| 258 | log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); | 258 | // log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); |
| 259 | } | 259 | // } |
| 260 | 260 | ||
| 261 | log.warn("globals", .{}); | 261 | // log.warn("globals", .{}); |
| 262 | for (self.globals.items) |sym, id| { | 262 | // for (self.globals.items) |sym, id| { |
| 263 | log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); | 263 | // log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); |
| 264 | } | 264 | // } |
| 265 | 265 | ||
| 266 | log.warn("tentatives", .{}); | 266 | // log.warn("tentatives", .{}); |
| 267 | for (self.tentatives.items) |sym, id| { | 267 | // for (self.tentatives.items) |sym, id| { |
| 268 | log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); | 268 | // log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); |
| 269 | } | 269 | // } |
| 270 | 270 | ||
| 271 | log.warn("undefines", .{}); | 271 | // log.warn("undefines", .{}); |
| 272 | for (self.undefs.items) |sym, id| { | 272 | // for (self.undefs.items) |sym, id| { |
| 273 | log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); | 273 | // log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); |
| 274 | } | 274 | // } |
| 275 | 275 | ||
| 276 | log.warn("imports", .{}); | 276 | // log.warn("imports", .{}); |
| 277 | for (self.imports.items) |sym, id| { | 277 | // for (self.imports.items) |sym, id| { |
| 278 | log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); | 278 | // log.warn(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym }); |
| 279 | } | 279 | // } |
| 280 | 280 | ||
| 281 | log.warn("symbol resolver", .{}); | 281 | // log.warn("symbol resolver", .{}); |
| 282 | for (self.symbol_resolver.keys()) |key| { | 282 | // for (self.symbol_resolver.keys()) |key| { |
| 283 | log.warn(" {s} => {}", .{ key, self.symbol_resolver.get(key).? }); | 283 | // log.warn(" {s} => {}", .{ key, self.symbol_resolver.get(key).? }); |
| 284 | } | 284 | // } |
| 285 | |||
| 286 | log.warn("mappings", .{}); | ||
| 287 | for (self.objects.items) |object, id| { | ||
| 288 | const object_id = @intCast(u16, id); | ||
| 289 | log.warn(" in object {s}", .{object.name.?}); | ||
| 290 | for (object.symtab.items) |sym, sym_id| { | ||
| 291 | if (object.symbol_mapping.get(@intCast(u32, sym_id))) |local_id| { | ||
| 292 | log.warn(" | {d} => {d}", .{ sym_id, local_id }); | ||
| 293 | } else { | ||
| 294 | log.warn(" | {d} no local mapping for {s}", .{ sym_id, object.getString(sym.n_strx) }); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | } | ||
| 298 | 285 | ||
| 299 | var it = self.blocks.iterator(); | 286 | // log.warn("mappings", .{}); |
| 300 | while (it.next()) |entry| { | 287 | // for (self.objects.items) |object, id| { |
| 301 | const seg = self.load_commands.items[entry.key_ptr.seg].Segment; | 288 | // const object_id = @intCast(u16, id); |
| 302 | const sect = seg.sections.items[entry.key_ptr.sect]; | 289 | // log.warn(" in object {s}", .{object.name.?}); |
| 290 | // for (object.symtab.items) |sym, sym_id| { | ||
| 291 | // if (object.symbol_mapping.get(@intCast(u32, sym_id))) |local_id| { | ||
| 292 | // log.warn(" | {d} => {d}", .{ sym_id, local_id }); | ||
| 293 | // } else { | ||
| 294 | // log.warn(" | {d} no local mapping for {s}", .{ sym_id, object.getString(sym.n_strx) }); | ||
| 295 | // } | ||
| 296 | // } | ||
| 297 | // } | ||
| 303 | 298 | ||
| 304 | log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) }); | 299 | // var it = self.blocks.iterator(); |
| 305 | log.warn(" {}", .{sect}); | 300 | // while (it.next()) |entry| { |
| 306 | entry.value_ptr.*.print(self); | 301 | // const seg = self.load_commands.items[entry.key_ptr.seg].Segment; |
| 307 | } | 302 | // const sect = seg.sections.items[entry.key_ptr.sect]; |
| 303 | |||
| 304 | // log.warn("\n\n{s},{s} contents:", .{ segmentName(sect), sectionName(sect) }); | ||
| 305 | // log.warn(" {}", .{sect}); | ||
| 306 | // entry.value_ptr.*.print(self); | ||
| 307 | // } | ||
| 308 | 308 | ||
| 309 | try self.flush(); | 309 | try self.flush(); |
| 310 | } | 310 | } |
| ... | @@ -1411,7 +1411,7 @@ fn writeStubInStubHelper(self: *Zld, index: u32) !void { | ... | @@ -1411,7 +1411,7 @@ fn writeStubInStubHelper(self: *Zld, index: u32) !void { |
| 1411 | fn resolveSymbolsInObject(self: *Zld, object_id: u16) !void { | 1411 | fn resolveSymbolsInObject(self: *Zld, object_id: u16) !void { |
| 1412 | const object = self.objects.items[object_id]; | 1412 | const object = self.objects.items[object_id]; |
| 1413 | 1413 | ||
| 1414 | log.warn("resolving symbols in '{s}'", .{object.name}); | 1414 | log.debug("resolving symbols in '{s}'", .{object.name}); |
| 1415 | 1415 | ||
| 1416 | for (object.symtab.items) |sym, id| { | 1416 | for (object.symtab.items) |sym, id| { |
| 1417 | const sym_id = @intCast(u32, id); | 1417 | const sym_id = @intCast(u32, id); |