aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-02-07 18:05:20 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-02-07 19:27:26 +0100
commit82144a9073aa06f037e248f332608f94caed59b9 (patch)
treee2c94442c45b34a8119d2821d71296ed731e2168 /src
parent35ac066f1d550445519aceb098d7e3f517f98c55 (diff)
downloadzig-82144a9073aa06f037e248f332608f94caed59b9.tar.gz
zig-82144a9073aa06f037e248f332608f94caed59b9.zip
macho: fix invalid ZigObject size calculation
Diffstat (limited to 'src')
-rw-r--r--src/link/MachO/ZigObject.zig8
-rw-r--r--src/link/MachO/relocatable.zig2
2 files changed, 2 insertions, 8 deletions
diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig
index 1017203bbe..ecd2470733 100644
--- a/src/link/MachO/ZigObject.zig
+++ b/src/link/MachO/ZigObject.zig
@@ -285,15 +285,9 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo
/// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer.
/// We need this so that we can write to an archive.
/// TODO implement writing ZigObject data directly to a buffer instead.
-pub fn readFileContents(self: *ZigObject, macho_file: *MachO) !void {
+pub fn readFileContents(self: *ZigObject, size: usize, macho_file: *MachO) !void {
const gpa = macho_file.base.comp.gpa;
- var end_pos: u64 = 0;
- for (macho_file.segments.items) |seg| {
- end_pos = @max(end_pos, seg.fileoff + seg.filesize);
- }
- const size = std.math.cast(usize, end_pos) orelse return error.Overflow;
try self.data.resize(gpa, size);
-
const amt = try macho_file.base.file.?.preadAll(self.data.items, 0);
if (amt != size) return error.InputOutput;
}
diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig
index d7d4469f7f..c190c1fdcc 100644
--- a/src/link/MachO/relocatable.zig
+++ b/src/link/MachO/relocatable.zig
@@ -152,7 +152,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
// TODO we can avoid reading in the file contents we just wrote if we give the linker
// ability to write directly to a buffer.
- try zo.readFileContents(macho_file);
+ try zo.readFileContents(off, macho_file);
}
var files = std.ArrayList(File.Index).init(gpa);