aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Relocation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-01 18:14:45 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-07 22:43:52 -0700
commitc8fcd2ff2c032b2de8cc1a57e075552d1cab35df (patch)
tree7155f58049ecd0e948533f6b64cba1553dd33ae2 /src/link/MachO/Relocation.zig
parentf71d97e4cbb0e56213cb76657ad6c9edf6134868 (diff)
downloadzig-c8fcd2ff2c032b2de8cc1a57e075552d1cab35df.tar.gz
zig-c8fcd2ff2c032b2de8cc1a57e075552d1cab35df.zip
MachO: update to new std.io APIs
Diffstat (limited to 'src/link/MachO/Relocation.zig')
-rw-r--r--src/link/MachO/Relocation.zig93
1 files changed, 44 insertions, 49 deletions
diff --git a/src/link/MachO/Relocation.zig b/src/link/MachO/Relocation.zig
index c732dc3a89..77f29d2e58 100644
--- a/src/link/MachO/Relocation.zig
+++ b/src/link/MachO/Relocation.zig
@@ -70,57 +70,51 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool {
return lhs.offset < rhs.offset;
}
-const FormatCtx = struct { Relocation, std.Target.Cpu.Arch };
-
-pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(formatPretty) {
+pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(Format, Format.pretty) {
return .{ .data = .{ rel, cpu_arch } };
}
-fn formatPretty(
- ctx: FormatCtx,
- comptime unused_fmt_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- _ = options;
- _ = unused_fmt_string;
- const rel, const cpu_arch = ctx;
- const str = switch (rel.type) {
- .signed => "X86_64_RELOC_SIGNED",
- .signed1 => "X86_64_RELOC_SIGNED_1",
- .signed2 => "X86_64_RELOC_SIGNED_2",
- .signed4 => "X86_64_RELOC_SIGNED_4",
- .got_load => "X86_64_RELOC_GOT_LOAD",
- .tlv => "X86_64_RELOC_TLV",
- .page => "ARM64_RELOC_PAGE21",
- .pageoff => "ARM64_RELOC_PAGEOFF12",
- .got_load_page => "ARM64_RELOC_GOT_LOAD_PAGE21",
- .got_load_pageoff => "ARM64_RELOC_GOT_LOAD_PAGEOFF12",
- .tlvp_page => "ARM64_RELOC_TLVP_LOAD_PAGE21",
- .tlvp_pageoff => "ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
- .branch => switch (cpu_arch) {
- .x86_64 => "X86_64_RELOC_BRANCH",
- .aarch64 => "ARM64_RELOC_BRANCH26",
- else => unreachable,
- },
- .got => switch (cpu_arch) {
- .x86_64 => "X86_64_RELOC_GOT",
- .aarch64 => "ARM64_RELOC_POINTER_TO_GOT",
- else => unreachable,
- },
- .subtractor => switch (cpu_arch) {
- .x86_64 => "X86_64_RELOC_SUBTRACTOR",
- .aarch64 => "ARM64_RELOC_SUBTRACTOR",
- else => unreachable,
- },
- .unsigned => switch (cpu_arch) {
- .x86_64 => "X86_64_RELOC_UNSIGNED",
- .aarch64 => "ARM64_RELOC_UNSIGNED",
- else => unreachable,
- },
- };
- try writer.writeAll(str);
-}
+const Format = struct {
+ relocation: Relocation,
+ arch: std.Target.Cpu.Arch,
+
+ fn pretty(f: Format, w: *Writer) Writer.Error!void {
+ try w.writeAll(switch (f.relocation.type) {
+ .signed => "X86_64_RELOC_SIGNED",
+ .signed1 => "X86_64_RELOC_SIGNED_1",
+ .signed2 => "X86_64_RELOC_SIGNED_2",
+ .signed4 => "X86_64_RELOC_SIGNED_4",
+ .got_load => "X86_64_RELOC_GOT_LOAD",
+ .tlv => "X86_64_RELOC_TLV",
+ .page => "ARM64_RELOC_PAGE21",
+ .pageoff => "ARM64_RELOC_PAGEOFF12",
+ .got_load_page => "ARM64_RELOC_GOT_LOAD_PAGE21",
+ .got_load_pageoff => "ARM64_RELOC_GOT_LOAD_PAGEOFF12",
+ .tlvp_page => "ARM64_RELOC_TLVP_LOAD_PAGE21",
+ .tlvp_pageoff => "ARM64_RELOC_TLVP_LOAD_PAGEOFF12",
+ .branch => switch (f.arch) {
+ .x86_64 => "X86_64_RELOC_BRANCH",
+ .aarch64 => "ARM64_RELOC_BRANCH26",
+ else => unreachable,
+ },
+ .got => switch (f.arch) {
+ .x86_64 => "X86_64_RELOC_GOT",
+ .aarch64 => "ARM64_RELOC_POINTER_TO_GOT",
+ else => unreachable,
+ },
+ .subtractor => switch (f.arch) {
+ .x86_64 => "X86_64_RELOC_SUBTRACTOR",
+ .aarch64 => "ARM64_RELOC_SUBTRACTOR",
+ else => unreachable,
+ },
+ .unsigned => switch (f.arch) {
+ .x86_64 => "X86_64_RELOC_UNSIGNED",
+ .aarch64 => "ARM64_RELOC_UNSIGNED",
+ else => unreachable,
+ },
+ });
+ }
+};
pub const Type = enum {
// x86_64
@@ -164,10 +158,11 @@ pub const Type = enum {
const Tag = enum { local, @"extern" };
+const std = @import("std");
const assert = std.debug.assert;
const macho = std.macho;
const math = std.math;
-const std = @import("std");
+const Writer = std.io.Writer;
const Atom = @import("Atom.zig");
const MachO = @import("../MachO.zig");