authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-13 07:56:14+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
loge5a66184eda96d8571ea5abaf7d5623d092bfac2
tree8c5606d6a0056f7eee2a04b3b13e638f39c409ab
parent01fc33c949cb8609324cfbcdf7f0524b93ff2561

macho: pretty print relocation types in logs and errors


1 files changed, 14 insertions(+), 8 deletions(-)

src/link/MachO/Atom.zig+14-8
...@@ -593,8 +593,14 @@ pub fn resolveRelocs(self: Atom, macho_file: *MachO, buffer: []u8) !void {...@@ -593,8 +593,14 @@ pub fn resolveRelocs(self: Atom, macho_file: *MachO, buffer: []u8) !void {
593 };593 };
594 try macho_file.reportParseError2(594 try macho_file.reportParseError2(
595 file.getIndex(),595 file.getIndex(),
596 "{s}: 0x{x}: 0x{x}: failed to relax relocation: type {s}, target {s}",596 "{s}: 0x{x}: 0x{x}: failed to relax relocation: type {}, target {s}",
597 .{ name, self.getAddress(macho_file), rel.offset, @tagName(rel.type), target },597 .{
598 name,
599 self.getAddress(macho_file),
600 rel.offset,
601 rel.fmtPretty(macho_file.getTarget().cpu.arch),
602 target,
603 },
598 );604 );
599 has_error = true;605 has_error = true;
600 },606 },
...@@ -650,17 +656,17 @@ fn resolveRelocInner(...@@ -650,17 +656,17 @@ fn resolveRelocInner(
650 }.divExact;656 }.divExact;
651657
652 switch (rel.tag) {658 switch (rel.tag) {
653 .local => relocs_log.debug(" {x}<+{d}>: {s}: [=> {x}] atom({d})", .{659 .local => relocs_log.debug(" {x}<+{d}>: {}: [=> {x}] atom({d})", .{
654 P,660 P,
655 rel_offset,661 rel_offset,
656 @tagName(rel.type),662 rel.fmtPretty(cpu_arch),
657 S + A - SUB,663 S + A - SUB,
658 rel.getTargetAtom(self, macho_file).atom_index,664 rel.getTargetAtom(self, macho_file).atom_index,
659 }),665 }),
660 .@"extern" => relocs_log.debug(" {x}<+{d}>: {s}: [=> {x}] G({x}) ZG({x}) ({s})", .{666 .@"extern" => relocs_log.debug(" {x}<+{d}>: {}: [=> {x}] G({x}) ZG({x}) ({s})", .{
661 P,667 P,
662 rel_offset,668 rel_offset,
663 @tagName(rel.type),669 rel.fmtPretty(cpu_arch),
664 S + A - SUB,670 S + A - SUB,
665 G + A,671 G + A,
666 ZIG_GOT + A,672 ZIG_GOT + A,
...@@ -900,11 +906,11 @@ const x86_64 = struct {...@@ -900,11 +906,11 @@ const x86_64 = struct {
900 },906 },
901 else => |x| {907 else => |x| {
902 var err = try macho_file.addErrorWithNotes(2);908 var err = try macho_file.addErrorWithNotes(2);
903 try err.addMsg(macho_file, "{s}: 0x{x}: 0x{x}: failed to relax relocation of type {s}", .{909 try err.addMsg(macho_file, "{s}: 0x{x}: 0x{x}: failed to relax relocation of type {}", .{
904 self.getName(macho_file),910 self.getName(macho_file),
905 self.getAddress(macho_file),911 self.getAddress(macho_file),
906 rel.offset,912 rel.offset,
907 @tagName(rel.type),913 rel.fmtPretty(.x86_64),
908 });914 });
909 try err.addNote(macho_file, "expected .mov instruction but found .{s}", .{@tagName(x)});915 try err.addNote(macho_file, "expected .mov instruction but found .{s}", .{@tagName(x)});
910 try err.addNote(macho_file, "while parsing {}", .{self.getFile(macho_file).fmtPath()});916 try err.addNote(macho_file, "while parsing {}", .{self.getFile(macho_file).fmtPath()});