macho: handle ZigObject when calculating dyld relocs

This commit is contained in:
Jakub Konka 2024-07-05 20:02:11 +02:00
parent e2bfd6fc69
commit d136d06a77
2 changed files with 18 additions and 3 deletions

View File

@ -25,9 +25,10 @@ pub fn updateSize(rebase: *Rebase, macho_file: *MachO) !void {
const gpa = macho_file.base.comp.gpa;
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 1);
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 2);
defer objects.deinit();
objects.appendSliceAssumeCapacity(macho_file.objects.items);
if (macho_file.getZigObject()) |obj| objects.appendAssumeCapacity(obj.index);
if (macho_file.getInternalObject()) |obj| objects.appendAssumeCapacity(obj.index);
for (objects.items) |index| {
@ -55,6 +56,18 @@ pub fn updateSize(rebase: *Rebase, macho_file: *MachO) !void {
}
}
if (macho_file.zig_got_sect_index) |sid| {
const seg_id = macho_file.sections.items(.segment_id)[sid];
const seg = macho_file.segments.items[seg_id];
for (0..macho_file.zig_got.entries.items.len) |idx| {
const addr = macho_file.zig_got.entryAddress(@intCast(idx), macho_file);
try rebase.entries.append(gpa, .{
.offset = addr - seg.vmaddr,
.segment_id = seg_id,
});
}
}
if (macho_file.got_sect_index) |sid| {
const seg_id = macho_file.sections.items(.segment_id)[sid];
const seg = macho_file.segments.items[seg_id];

View File

@ -35,9 +35,10 @@ pub const Bind = struct {
const gpa = macho_file.base.comp.gpa;
const cpu_arch = macho_file.getTarget().cpu.arch;
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 1);
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 2);
defer objects.deinit();
objects.appendSliceAssumeCapacity(macho_file.objects.items);
if (macho_file.getZigObject()) |obj| objects.appendAssumeCapacity(obj.index);
if (macho_file.getInternalObject()) |obj| objects.appendAssumeCapacity(obj.index);
for (objects.items) |index| {
@ -286,9 +287,10 @@ pub const WeakBind = struct {
const gpa = macho_file.base.comp.gpa;
const cpu_arch = macho_file.getTarget().cpu.arch;
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 1);
var objects = try std.ArrayList(File.Index).initCapacity(gpa, macho_file.objects.items.len + 2);
defer objects.deinit();
objects.appendSliceAssumeCapacity(macho_file.objects.items);
if (macho_file.getZigObject()) |obj| objects.appendAssumeCapacity(obj.index);
if (macho_file.getInternalObject()) |obj| objects.appendAssumeCapacity(obj.index);
for (objects.items) |index| {