motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit e00b9d6192a09305c4160ccbeeb761a1f1af855a (tree)
parent e229202cb87a895401f2813f0f12227a0d715c09
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Wed,  8 Sep 2021 13:17:43 +0200

macho: use smaller padding until we have branch islands on arm64

Without branch islands, it is impossible to link self-hosted using
the common linker path.

Diffstat:
Msrc/link/MachO.zig | 2+-
Msrc/link/MachO/TextBlock.zig | 15+++++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/link/MachO.zig b/src/link/MachO.zig @@ -262,7 +262,7 @@ pub const GotIndirectionKey = struct { /// When allocating, the ideal_capacity is calculated by /// actual_capacity + (actual_capacity / ideal_factor) -const ideal_factor = 2; +const ideal_factor = 4; /// Default path to dyld const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld"; diff --git a/src/link/MachO/TextBlock.zig b/src/link/MachO/TextBlock.zig @@ -243,10 +243,21 @@ pub const Relocation = struct { pub fn resolve(self: Branch, args: ResolveArgs) !void { switch (self.arch) { .aarch64 => { - const displacement = try math.cast( + const displacement = math.cast( i28, @intCast(i64, args.target_addr) - @intCast(i64, args.source_addr), - ); + ) catch |err| switch (err) { + error.Overflow => { + log.err("jump too big to encode as i28 displacement value", .{}); + log.err(" (target - source) = displacement => 0x{x} - 0x{x} = 0x{x}", .{ + args.target_addr, + args.source_addr, + @intCast(i64, args.target_addr) - @intCast(i64, args.source_addr), + }); + log.err(" TODO implement branch islands to extend jump distance for arm64", .{}); + return error.TODOImplementBranchIslands; + }, + }; const code = args.block.code.items[args.offset..][0..4]; var inst = aarch64.Instruction{ .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(