Commit e00b9d6192

Jakub Konka <kubkon@jakubkonka.com>
2021-09-08 13:17:43
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.
1 parent e229202
Changed files (2)
src
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(
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";