diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-03-16 23:07:23 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-03-17 12:10:39 +0100 |
| commit | 3df2ae1f9da3655462d668ec16088f43a4a11ce4 (patch) | |
| tree | ca2820bcce3768e7ef2f667e55884c42227d952c /src | |
| parent | 643b4898f592c7193402dcf9a7ca465edb2d430a (diff) | |
| download | zig-3df2ae1f9da3655462d668ec16088f43a4a11ce4.tar.gz zig-3df2ae1f9da3655462d668ec16088f43a4a11ce4.zip | |
macho: clean up writing of stub helper section
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index a69ce31b85..80afdc6408 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -2602,8 +2602,10 @@ fn writeStubInStubHelper(self: *MachO, index: u32) !void { else => unreachable, }; const stub_off = self.stub_helper_stubs_start_off.? + index * stub_size; + var code = try self.base.allocator.alloc(u8, stub_size); defer self.base.allocator.free(code); + switch (self.base.options.target.cpu.arch) { .x86_64 => { const displacement = try math.cast( @@ -2618,12 +2620,19 @@ fn writeStubInStubHelper(self: *MachO, index: u32) !void { mem.writeIntLittle(u32, code[6..][0..4], @bitCast(u32, displacement)); }, .aarch64 => { - const displacement = try math.cast(i28, @intCast(i64, stub_helper.offset) - @intCast(i64, stub_off) - 4); + const literal = blk: { + const div_res = try math.divExact(u64, stub_size - @sizeOf(u32), 4); + break :blk try math.cast(u18, div_res); + }; + // ldr w16, literal mem.writeIntLittle(u32, code[0..4], aarch64.Instruction.ldr(.w16, .{ - .literal = @divExact(stub_size - @sizeOf(u32), 4), + .literal = literal, }).toU32()); + const displacement = try math.cast(i28, @intCast(i64, stub_helper.offset) - @intCast(i64, stub_off) - 4); + // b disp mem.writeIntLittle(u32, code[4..8], aarch64.Instruction.b(displacement).toU32()); - mem.writeIntLittle(u32, code[8..12], 0x0); // Just a placeholder populated in `populateLazyBindOffsetsInStubHelper`. + // Just a placeholder populated in `populateLazyBindOffsetsInStubHelper`. + mem.writeIntLittle(u32, code[8..12], 0x0); }, else => unreachable, } |
