Skip to content

Commit

Permalink
macho: allocate segment in relocatable mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 31, 2023
1 parent d0a85af commit 6d578b1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/MachO/relocatable.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ pub fn flush(macho_file: *MachO) !void {

try allocateSections(macho_file);

{
// Allocate the single segment.
assert(macho_file.segments.items.len == 1);
const seg = &macho_file.segments.items[0];
var vmaddr: u64 = 0;
var fileoff: u64 = load_commands.calcLoadCommandsSizeObject(macho_file);
seg.vmaddr = vmaddr;
seg.fileoff = fileoff;

for (macho_file.sections.items(.header)) |header| {
vmaddr = header.addr + header.size;
if (!header.isZerofill()) {
fileoff = header.offset + header.size;
}
}

seg.vmsize = vmaddr - seg.vmaddr;
seg.filesize = fileoff - seg.fileoff;
}

state_log.debug("{}", .{macho_file.dumpState()});

macho_file.base.fatal("-r mode unimplemented", .{});
Expand Down Expand Up @@ -127,9 +147,8 @@ fn calcCompactUnwindSize(macho_file: *MachO) usize {
}

fn allocateSections(macho_file: *MachO) !void {
const headerpad = load_commands.calcLoadCommandsSizeObject(macho_file);
var fileoff = load_commands.calcLoadCommandsSizeObject(macho_file);
var vmaddr: u64 = 0;
var fileoff = headerpad;
const slice = macho_file.sections.slice();

for (slice.items(.header)) |*header| {
Expand Down

0 comments on commit 6d578b1

Please sign in to comment.