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 {
593593 };
594594 try macho_file.reportParseError2(
595595 file.getIndex(),
596 "{s}: 0x{x}: 0x{x}: failed to relax relocation: type {s}, target {s}",
597 .{ name, self.getAddress(macho_file), rel.offset, @tagName(rel.type), target },
596 "{s}: 0x{x}: 0x{x}: failed to relax relocation: type {}, target {s}",
597 .{
598 name,
599 self.getAddress(macho_file),
600 rel.offset,
601 rel.fmtPretty(macho_file.getTarget().cpu.arch),
602 target,
603 },
598604 );
599605 has_error = true;
600606 },
......@@ -650,17 +656,17 @@ fn resolveRelocInner(
650656 }.divExact;
651657
652658 switch (rel.tag) {
653 .local => relocs_log.debug(" {x}<+{d}>: {s}: [=> {x}] atom({d})", .{
659 .local => relocs_log.debug(" {x}<+{d}>: {}: [=> {x}] atom({d})", .{
654660 P,
655661 rel_offset,
656 @tagName(rel.type),
662 rel.fmtPretty(cpu_arch),
657663 S + A - SUB,
658664 rel.getTargetAtom(self, macho_file).atom_index,
659665 }),
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})", .{
661667 P,
662668 rel_offset,
663 @tagName(rel.type),
669 rel.fmtPretty(cpu_arch),
664670 S + A - SUB,
665671 G + A,
666672 ZIG_GOT + A,
......@@ -900,11 +906,11 @@ const x86_64 = struct {
900906 },
901907 else => |x| {
902908 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 {}", .{
904910 self.getName(macho_file),
905911 self.getAddress(macho_file),
906912 rel.offset,
907 @tagName(rel.type),
913 rel.fmtPretty(.x86_64),
908914 });
909915 try err.addNote(macho_file, "expected .mov instruction but found .{s}", .{@tagName(x)});
910916 try err.addNote(macho_file, "while parsing {}", .{self.getFile(macho_file).fmtPath()});