mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
macho: move getAtomData switch into Atom
This commit is contained in:
parent
6337ce16ae
commit
8cdaaa7b4f
@ -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 atom_size = math.cast(usize, atom.size) orelse return error.Overflow;
|
||||||
const code = try gpa.alloc(u8, atom_size);
|
const code = try gpa.alloc(u8, atom_size);
|
||||||
defer gpa.free(code);
|
defer gpa.free(code);
|
||||||
zo.getAtomData(self, atom.*, code) catch |err| switch (err) {
|
atom.getData(self, code) catch |err| switch (err) {
|
||||||
error.InputOutput => {
|
error.InputOutput => {
|
||||||
try self.reportUnexpectedError("fetching code for '{s}' failed", .{
|
try self.reportUnexpectedError("fetching code for '{s}' failed", .{
|
||||||
atom.getName(self),
|
atom.getName(self),
|
||||||
@ -2591,12 +2591,7 @@ fn writeAtoms(self: *MachO) !void {
|
|||||||
assert(atom.flags.alive);
|
assert(atom.flags.alive);
|
||||||
const off = math.cast(usize, atom.value - header.addr) orelse return error.Overflow;
|
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;
|
const atom_size = math.cast(usize, atom.size) orelse return error.Overflow;
|
||||||
switch (atom.getFile(self)) {
|
try atom.getData(self, buffer[off..][0..atom_size]);
|
||||||
.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,
|
|
||||||
}
|
|
||||||
atom.resolveRelocs(self, buffer[off..][0..atom_size]) catch |err| switch (err) {
|
atom.resolveRelocs(self, buffer[off..][0..atom_size]) catch |err| switch (err) {
|
||||||
error.ResolveFailed => has_resolve_error = true,
|
error.ResolveFailed => has_resolve_error = true,
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
|
|||||||
@ -54,6 +54,16 @@ pub fn getFile(self: Atom, macho_file: *MachO) File {
|
|||||||
return macho_file.getFile(self.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 {
|
pub fn getRelocs(self: Atom, macho_file: *MachO) []const Relocation {
|
||||||
return switch (self.getFile(macho_file)) {
|
return switch (self.getFile(macho_file)) {
|
||||||
.dylib => unreachable,
|
.dylib => unreachable,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user