Skip to content

Commit

Permalink
macho: calculate alloc section sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 28, 2023
1 parent 47d98bf commit 9b7ac8f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/MachO/relocatable.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,24 @@ fn initOutputSections(macho_file: *MachO) !void {
}

fn calcSectionSizes(macho_file: *MachO) !void {
_ = macho_file;
const slice = macho_file.sections.slice();
for (slice.items(.header), slice.items(.atoms)) |*header, atoms| {
if (atoms.items.len == 0) continue;
for (atoms.items) |atom_index| {
const atom = macho_file.getAtom(atom_index).?;
const atom_alignment = try math.powi(u32, 2, atom.alignment);
const offset = mem.alignForward(u64, header.size, atom_alignment);
const padding = offset - header.size;
atom.value = offset;
header.size += padding + atom.size;
header.@"align" = @max(header.@"align", atom.alignment);
}
}
}

const assert = std.debug.assert;
const math = std.math;
const mem = std.mem;
const state_log = std.log.scoped(.state);
const std = @import("std");

Expand Down

0 comments on commit 9b7ac8f

Please sign in to comment.