| ... | @@ -1,3 +1,4 @@ | ... | @@ -1,3 +1,4 @@ |
| | 1 | data: std.ArrayListUnmanaged(u8) = .{}, |
| 1 | /// Externally owned memory. | 2 | /// Externally owned memory. |
| 2 | path: []const u8, | 3 | path: []const u8, |
| 3 | index: File.Index, | 4 | index: File.Index, |
| ... | @@ -57,6 +58,7 @@ pub fn init(self: *ZigObject, macho_file: *MachO) !void { | ... | @@ -57,6 +58,7 @@ pub fn init(self: *ZigObject, macho_file: *MachO) !void { |
| 57 | } | 58 | } |
| 58 | | 59 | |
| 59 | pub fn deinit(self: *ZigObject, allocator: Allocator) void { | 60 | pub fn deinit(self: *ZigObject, allocator: Allocator) void { |
| | 61 | self.data.deinit(allocator); |
| 60 | self.symtab.deinit(allocator); | 62 | self.symtab.deinit(allocator); |
| 61 | self.strtab.deinit(allocator); | 63 | self.strtab.deinit(allocator); |
| 62 | self.symbols.deinit(allocator); | 64 | self.symbols.deinit(allocator); |
| ... | @@ -279,6 +281,22 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo | ... | @@ -279,6 +281,22 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo |
| 279 | } | 281 | } |
| 280 | } | 282 | } |
| 281 | | 283 | |
| | 284 | /// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer. |
| | 285 | /// We need this so that we can write to an archive. |
| | 286 | /// TODO implement writing ZigObject data directly to a buffer instead. |
| | 287 | pub fn readFileContents(self: *ZigObject, macho_file: *MachO) !void { |
| | 288 | const gpa = macho_file.base.comp.gpa; |
| | 289 | var end_pos: u64 = 0; |
| | 290 | for (macho_file.segments.items) |seg| { |
| | 291 | end_pos = @max(end_pos, seg.fileoff + seg.filesize); |
| | 292 | } |
| | 293 | const size = std.math.cast(usize, end_pos) orelse return error.Overflow; |
| | 294 | try self.data.resize(gpa, size); |
| | 295 | |
| | 296 | const amt = try macho_file.base.file.?.preadAll(self.data.items, 0); |
| | 297 | if (amt != size) return error.InputOutput; |
| | 298 | } |
| | 299 | |
| 282 | pub fn scanRelocs(self: *ZigObject, macho_file: *MachO) !void { | 300 | pub fn scanRelocs(self: *ZigObject, macho_file: *MachO) !void { |
| 283 | for (self.atoms.items) |atom_index| { | 301 | for (self.atoms.items) |atom_index| { |
| 284 | const atom = macho_file.getAtom(atom_index) orelse continue; | 302 | const atom = macho_file.getAtom(atom_index) orelse continue; |