commit 876071b50b1d23a59b3d3e5acedf4161029f5f2b (tree)
parent 9e7b2fb894cf4021ec188fbb64b11d750f4354fa
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Mon, 23 Aug 2021 23:23:00 +0200
macho: fix writing stubs (on x86_64 only) and lazy ptrs
Diffstat:
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
@@ -816,8 +816,8 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
const laptr_atom = try self.createLazyPointerAtom(stub_atom.local_sym_index);
try self.allocateAtomStage1(laptr_atom, .{
- .seg = self.text_segment_cmd_index.?,
- .sect = self.stub_helper_section_index.?,
+ .seg = self.data_segment_cmd_index.?,
+ .sect = self.la_symbol_ptr_section_index.?,
});
}
try self.allocateTextSegment();
@@ -2183,6 +2183,11 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {
.aarch64 => 3 * @sizeOf(u32),
else => unreachable,
};
+ const alignment: u2 = switch (arch) {
+ .x86_64 => 0,
+ .aarch64 => 2,
+ else => unreachable,
+ };
const local_sym_index = @intCast(u32, self.locals.items.len);
try self.locals.append(self.base.allocator, .{
.n_strx = try self.makeString("stub_in_stub_helper"),
@@ -2194,7 +2199,7 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {
const atom = try self.createEmptyAtom(.{
.seg = self.text_segment_cmd_index.?,
.sect = self.stub_helper_section_index.?,
- }, local_sym_index, stub_size, 2);
+ }, local_sym_index, stub_size, alignment);
try atom.relocs.ensureTotalCapacity(self.base.allocator, 1);
switch (arch) {