mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
macho: move getAtomData switch into Atom
This commit is contained in:
parent
6337ce16ae
commit
8cdaaa7b4f
2 changed files with 12 additions and 7 deletions
|
|
@ -613,7 +613,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
|
|||
const atom_size = math.cast(usize, atom.size) orelse return error.Overflow;
|
||||
const code = try gpa.alloc(u8, atom_size);
|
||||
defer gpa.free(code);
|
||||
zo.getAtomData(self, atom.*, code) catch |err| switch (err) {
|
||||
atom.getData(self, code) catch |err| switch (err) {
|
||||
error.InputOutput => {
|
||||
try self.reportUnexpectedError("fetching code for '{s}' failed", .{
|
||||
atom.getName(self),
|
||||
|
|
@ -2591,12 +2591,7 @@ fn writeAtoms(self: *MachO) !void {
|
|||
assert(atom.flags.alive);
|
||||
const off = math.cast(usize, atom.value - header.addr) orelse return error.Overflow;
|
||||
const atom_size = math.cast(usize, atom.size) orelse return error.Overflow;
|
||||
switch (atom.getFile(self)) {
|
||||
.internal => |x| try x.getAtomData(atom.*, buffer[off..][0..atom_size]),
|
||||
.object => |x| try x.getAtomData(atom.*, buffer[off..][0..atom_size]),
|
||||
.zig_object => |x| try x.getAtomData(self, atom.*, buffer[off..][0..atom_size]),
|
||||
else => unreachable,
|
||||
}
|
||||
try atom.getData(self, buffer[off..][0..atom_size]);
|
||||
atom.resolveRelocs(self, buffer[off..][0..atom_size]) catch |err| switch (err) {
|
||||
error.ResolveFailed => has_resolve_error = true,
|
||||
else => |e| return e,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@ pub fn getFile(self: Atom, macho_file: *MachO) File {
|
|||
return macho_file.getFile(self.file).?;
|
||||
}
|
||||
|
||||
pub fn getData(self: Atom, macho_file: *MachO, buffer: []u8) !void {
|
||||
assert(buffer.len == self.size);
|
||||
switch (self.getFile(macho_file)) {
|
||||
.internal => |x| try x.getAtomData(self, buffer),
|
||||
.object => |x| try x.getAtomData(self, buffer),
|
||||
.zig_object => |x| try x.getAtomData(macho_file, self, buffer),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getRelocs(self: Atom, macho_file: *MachO) []const Relocation {
|
||||
return switch (self.getFile(macho_file)) {
|
||||
.dylib => unreachable,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue