authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-08 13:17:43+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-08 13:17:43+02:00
loge00b9d6192a09305c4160ccbeeb761a1f1af855a
tree043e9f31568ee8a577356fd1ac2bb7aedef18e73
parente229202cb87a895401f2813f0f12227a0d715c09

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.

2 files changed, 14 insertions(+), 3 deletions(-)

src/link/MachO.zig+1-1
...@@ -262,7 +262,7 @@ pub const GotIndirectionKey = struct {...@@ -262,7 +262,7 @@ pub const GotIndirectionKey = struct {
262262
263/// When allocating, the ideal_capacity is calculated by263/// When allocating, the ideal_capacity is calculated by
264/// actual_capacity + (actual_capacity / ideal_factor)264/// actual_capacity + (actual_capacity / ideal_factor)
265const ideal_factor = 2;265const ideal_factor = 4;
266266
267/// Default path to dyld267/// Default path to dyld
268const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld";268const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld";
src/link/MachO/TextBlock.zig+13-2
...@@ -243,10 +243,21 @@ pub const Relocation = struct {...@@ -243,10 +243,21 @@ pub const Relocation = struct {
243 pub fn resolve(self: Branch, args: ResolveArgs) !void {243 pub fn resolve(self: Branch, args: ResolveArgs) !void {
244 switch (self.arch) {244 switch (self.arch) {
245 .aarch64 => {245 .aarch64 => {
246 const displacement = try math.cast(246 const displacement = math.cast(
247 i28,247 i28,
248 @intCast(i64, args.target_addr) - @intCast(i64, args.source_addr),248 @intCast(i64, args.target_addr) - @intCast(i64, args.source_addr),
249 );249 ) catch |err| switch (err) {
250 error.Overflow => {
251 log.err("jump too big to encode as i28 displacement value", .{});
252 log.err(" (target - source) = displacement => 0x{x} - 0x{x} = 0x{x}", .{
253 args.target_addr,
254 args.source_addr,
255 @intCast(i64, args.target_addr) - @intCast(i64, args.source_addr),
256 });
257 log.err(" TODO implement branch islands to extend jump distance for arm64", .{});
258 return error.TODOImplementBranchIslands;
259 },
260 };
250 const code = args.block.code.items[args.offset..][0..4];261 const code = args.block.code.items[args.offset..][0..4];
251 var inst = aarch64.Instruction{262 var inst = aarch64.Instruction{
252 .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(263 .unconditional_branch_immediate = mem.bytesToValue(meta.TagPayload(