aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/InternalObject.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/InternalObject.zig
parentf71d97e4cbb0e56213cb76657ad6c9edf6134868 (diff)
downloadzig-c8fcd2ff2c032b2de8cc1a57e075552d1cab35df.tar.gz
zig-c8fcd2ff2c032b2de8cc1a57e075552d1cab35df.zip
MachO: update to new std.io APIs
Diffstat (limited to 'src/link/MachO/InternalObject.zig')
-rw-r--r--src/link/MachO/InternalObject.zig69
1 files changed, 28 insertions, 41 deletions
diff --git a/src/link/MachO/InternalObject.zig b/src/link/MachO/InternalObject.zig
index 0218f0c1bb..1329572dc8 100644
--- a/src/link/MachO/InternalObject.zig
+++ b/src/link/MachO/InternalObject.zig
@@ -261,7 +261,7 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil
sect.offset = @intCast(self.objc_methnames.items.len);
try self.objc_methnames.ensureUnusedCapacity(gpa, methname.len + 1);
- self.objc_methnames.writer(gpa).print("{s}\x00", .{methname}) catch unreachable;
+ self.objc_methnames.print(gpa, "{s}\x00", .{methname}) catch unreachable;
const name_str = try self.addString(gpa, "ltmp");
const sym_index = try self.addSymbol(gpa);
@@ -836,62 +836,48 @@ fn needsObjcMsgsendSymbol(self: InternalObject) bool {
return false;
}
-const FormatContext = struct {
+const Format = struct {
self: *InternalObject,
macho_file: *MachO,
+
+ fn atoms(f: Format, w: *Writer) Writer.Error!void {
+ try w.writeAll(" atoms\n");
+ for (f.self.getAtoms()) |atom_index| {
+ const atom = f.self.getAtom(atom_index) orelse continue;
+ try w.print(" {f}\n", .{atom.fmt(f.macho_file)});
+ }
+ }
+
+ fn symtab(f: Format, w: *Writer) Writer.Error!void {
+ const macho_file = f.macho_file;
+ const self = f.self;
+ try w.writeAll(" symbols\n");
+ for (self.symbols.items, 0..) |sym, i| {
+ const ref = self.getSymbolRef(@intCast(i), macho_file);
+ if (ref.getFile(macho_file) == null) {
+ // TODO any better way of handling this?
+ try w.print(" {s} : unclaimed\n", .{sym.getName(macho_file)});
+ } else {
+ try w.print(" {f}\n", .{ref.getSymbol(macho_file).?.fmt(macho_file)});
+ }
+ }
+ }
};
-pub fn fmtAtoms(self: *InternalObject, macho_file: *MachO) std.fmt.Formatter(formatAtoms) {
+pub fn fmtAtoms(self: *InternalObject, macho_file: *MachO) std.fmt.Formatter(Format, Format.atoms) {
return .{ .data = .{
.self = self,
.macho_file = macho_file,
} };
}
-fn formatAtoms(
- ctx: FormatContext,
- comptime unused_fmt_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- _ = unused_fmt_string;
- _ = options;
- try writer.writeAll(" atoms\n");
- for (ctx.self.getAtoms()) |atom_index| {
- const atom = ctx.self.getAtom(atom_index) orelse continue;
- try writer.print(" {}\n", .{atom.fmt(ctx.macho_file)});
- }
-}
-
-pub fn fmtSymtab(self: *InternalObject, macho_file: *MachO) std.fmt.Formatter(formatSymtab) {
+pub fn fmtSymtab(self: *InternalObject, macho_file: *MachO) std.fmt.Formatter(Format, Format.symtab) {
return .{ .data = .{
.self = self,
.macho_file = macho_file,
} };
}
-fn formatSymtab(
- ctx: FormatContext,
- comptime unused_fmt_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- _ = unused_fmt_string;
- _ = options;
- const macho_file = ctx.macho_file;
- const self = ctx.self;
- try writer.writeAll(" symbols\n");
- for (self.symbols.items, 0..) |sym, i| {
- const ref = self.getSymbolRef(@intCast(i), macho_file);
- if (ref.getFile(macho_file) == null) {
- // TODO any better way of handling this?
- try writer.print(" {s} : unclaimed\n", .{sym.getName(macho_file)});
- } else {
- try writer.print(" {}\n", .{ref.getSymbol(macho_file).?.fmt(macho_file)});
- }
- }
-}
-
const Section = struct {
header: macho.section_64,
relocs: std.ArrayListUnmanaged(Relocation) = .empty,
@@ -908,6 +894,7 @@ const macho = std.macho;
const mem = std.mem;
const std = @import("std");
const trace = @import("../../tracy.zig").trace;
+const Writer = std.io.Writer;
const Allocator = std.mem.Allocator;
const Atom = @import("Atom.zig");