| ... | @@ -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( |