| ... | @@ -3,6 +3,7 @@ const aarch64 = @import("../../codegen/aarch64.zig"); | ... | @@ -3,6 +3,7 @@ const aarch64 = @import("../../codegen/aarch64.zig"); |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const log = std.log.scoped(.reloc); | 4 | const log = std.log.scoped(.reloc); |
| 5 | const macho = std.macho; | 5 | const macho = std.macho; |
| | 6 | const math = std.math; |
| 6 | const mem = std.mem; | 7 | const mem = std.mem; |
| 7 | const meta = std.meta; | 8 | const meta = std.meta; |
| 8 | | 9 | |
| ... | @@ -10,7 +11,7 @@ const Allocator = mem.Allocator; | ... | @@ -10,7 +11,7 @@ const Allocator = mem.Allocator; |
| 10 | | 11 | |
| 11 | pub const Relocation = struct { | 12 | pub const Relocation = struct { |
| 12 | @"type": Type, | 13 | @"type": Type, |
| 13 | code: *[]u8, | 14 | code: []u8, |
| 14 | offset: u32, | 15 | offset: u32, |
| 15 | target: Target, | 16 | target: Target, |
| 16 | | 17 | |
| ... | @@ -24,20 +25,26 @@ pub const Relocation = struct { | ... | @@ -24,20 +25,26 @@ pub const Relocation = struct { |
| 24 | pub const ResolveArgs = struct { | 25 | pub const ResolveArgs = struct { |
| 25 | source_addr: u64, | 26 | source_addr: u64, |
| 26 | target_addr: u64, | 27 | target_addr: u64, |
| 27 | subtractor: i64 = undefined, | 28 | subtractor: ?u64, |
| 28 | }; | 29 | }; |
| 29 | | 30 | |
| 30 | pub fn resolve(base: *Relocation, args: ResolveArgs) !void { | 31 | pub fn resolve(base: *Relocation, args: ResolveArgs) !void { |
| 31 | switch (base.@"type") { | 32 | log.warn("{s}", .{base.@"type"}); |
| 32 | .branch => try base.cast(Branch).?.resolve(args.source_addr, args.target_addr), | 33 | log.warn(" | offset 0x{x}", .{base.offset}); |
| 33 | .unsigned => try base.cast(Unsigned).?.resolve(args.target_addr, args.subtractor), | 34 | log.warn(" | source address 0x{x}", .{args.source_addr}); |
| 34 | .page => try base.cast(Page).?.resolve(args.source_addr, args.target_addr), | 35 | log.warn(" | target address 0x{x}", .{args.target_addr}); |
| 35 | .page_off => try base.cast(PageOff).?.resolve(args.target_addr), | 36 | log.warn(" | subtractor address 0x{x}", .{args.subtractor}); |
| 36 | .got_page => try base.cast(GotPage).?.resolve(args.source_addr, args.target_addr), | 37 | |
| 37 | .got_page_off => try base.cast(GotPageOff).?.resolve(args.target_addr), | 38 | return switch (base.@"type") { |
| 38 | .tlvp_page => try base.cast(TlvpPage).?.resolve(args.source_addr, args.target_addr), | 39 | .branch => @fieldParentPtr(Branch, "base", base).resolve(args.source_addr, args.target_addr), |
| 39 | .tlvp_page_off => try base.cast(TlvpPageOff).?.resolve(args.target_addr), | 40 | .unsigned => @fieldParentPtr(Unsigned, "base", base).resolve(args.target_addr, args.subtractor), |
| 40 | } | 41 | .page => @fieldParentPtr(Page, "base", base).resolve(args.source_addr, args.target_addr), |
| | 42 | .page_off => @fieldParentPtr(PageOff, "base", base).resolve(args.target_addr), |
| | 43 | .got_page => @fieldParentPtr(GotPage, "base", base).resolve(args.source_addr, args.target_addr), |
| | 44 | .got_page_off => @fieldParentPtr(GotPageOff, "base", base).resolve(args.target_addr), |
| | 45 | .tlvp_page => @fieldParentPtr(TlvpPage, "base", base).resolve(args.source_addr, args.target_addr), |
| | 46 | .tlvp_page_off => @fieldParentPtr(TlvpPageOff, "base", base).resolve(args.target_addr), |
| | 47 | }; |
| 41 | } | 48 | } |
| 42 | | 49 | |
| 43 | pub const Type = enum { | 50 | pub const Type = enum { |
| ... | @@ -73,9 +80,12 @@ pub const Relocation = struct { | ... | @@ -73,9 +80,12 @@ pub const Relocation = struct { |
| 73 | | 80 | |
| 74 | pub fn resolve(branch: Branch, source_addr: u64, target_addr: u64) !void { | 81 | pub fn resolve(branch: Branch, source_addr: u64, target_addr: u64) !void { |
| 75 | const displacement = try math.cast(i28, @intCast(i64, target_addr) - @intCast(i64, source_addr)); | 82 | const displacement = try math.cast(i28, @intCast(i64, target_addr) - @intCast(i64, source_addr)); |
| | 83 | |
| | 84 | log.warn(" | displacement 0x{x}", .{displacement}); |
| | 85 | |
| 76 | var inst = branch.inst; | 86 | var inst = branch.inst; |
| 77 | inst.AddSubtractImmediate.imm26 = @truncate(u26, @bitCast(u28, displacement) >> 2); | 87 | inst.UnconditionalBranchImmediate.imm26 = @truncate(u26, @bitCast(u28, displacement) >> 2); |
| 78 | mem.writeIntLittle(u32, branch.base.code.*[branch.base.offset..], inst.toU32()); | 88 | mem.writeIntLittle(u32, branch.base.code[0..4], inst.toU32()); |
| 79 | } | 89 | } |
| 80 | }; | 90 | }; |
| 81 | | 91 | |
| ... | @@ -92,22 +102,25 @@ pub const Relocation = struct { | ... | @@ -92,22 +102,25 @@ pub const Relocation = struct { |
| 92 | | 102 | |
| 93 | pub const base_type: Relocation.Type = .unsigned; | 103 | pub const base_type: Relocation.Type = .unsigned; |
| 94 | | 104 | |
| 95 | pub fn resolve(unsigned: Unsigned, target_addr: u64, subtractor: i64) !void { | 105 | pub fn resolve(unsigned: Unsigned, target_addr: u64, subtractor: ?u64) !void { |
| 96 | const result = @intCast(i64, target_addr) - subtractor + unsigned.addend; | 106 | const result = if (subtractor) |sub| |
| | 107 | @intCast(i64, target_addr) - @intCast(i64, sub) + unsigned.addend |
| | 108 | else |
| | 109 | @intCast(i64, target_addr) + unsigned.addend; |
| 97 | | 110 | |
| 98 | log.debug(" | calculated addend 0x{x}", .{unsigned.addend}); | 111 | log.warn(" | calculated addend 0x{x}", .{unsigned.addend}); |
| 99 | log.debug(" | calculated unsigned value 0x{x}", .{result}); | 112 | log.warn(" | calculated unsigned value 0x{x}", .{result}); |
| 100 | | 113 | |
| 101 | if (unsigned.is_64bit) { | 114 | if (unsigned.is_64bit) { |
| 102 | mem.writeIntLittle( | 115 | mem.writeIntLittle( |
| 103 | u64, | 116 | u64, |
| 104 | unsigned.base.code.*[unsigned.base.offset..], | 117 | unsigned.base.code[0..8], |
| 105 | @bitCast(u64, result), | 118 | @bitCast(u64, result), |
| 106 | ); | 119 | ); |
| 107 | } else { | 120 | } else { |
| 108 | mem.writeIntLittle( | 121 | mem.writeIntLittle( |
| 109 | u32, | 122 | u32, |
| 110 | unsigned.base.code.*[unsigned.base.offset..], | 123 | unsigned.base.code[0..4], |
| 111 | @truncate(u32, @bitCast(u64, result)), | 124 | @truncate(u32, @bitCast(u64, result)), |
| 112 | ); | 125 | ); |
| 113 | } | 126 | } |
| ... | @@ -128,13 +141,14 @@ pub const Relocation = struct { | ... | @@ -128,13 +141,14 @@ pub const Relocation = struct { |
| 128 | const target_page = @intCast(i32, ta >> 12); | 141 | const target_page = @intCast(i32, ta >> 12); |
| 129 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); | 142 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); |
| 130 | | 143 | |
| 131 | log.debug(" | moving by {} pages", .{pages}); | 144 | log.warn(" | calculated addend 0x{x}", .{page.addend}); |
| | 145 | log.warn(" | moving by {} pages", .{pages}); |
| 132 | | 146 | |
| 133 | var inst = page.inst; | 147 | var inst = page.inst; |
| 134 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); | 148 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); |
| 135 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); | 149 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); |
| 136 | | 150 | |
| 137 | mem.writeIntLittle(u32, page.base.code.*[page.base.offset..], inst.toU32()); | 151 | mem.writeIntLittle(u32, page.base.code[0..4], inst.toU32()); |
| 138 | } | 152 | } |
| 139 | }; | 153 | }; |
| 140 | | 154 | |
| ... | @@ -155,8 +169,8 @@ pub const Relocation = struct { | ... | @@ -155,8 +169,8 @@ pub const Relocation = struct { |
| 155 | const ta = if (page_off.addend) |a| target_addr + a else target_addr; | 169 | const ta = if (page_off.addend) |a| target_addr + a else target_addr; |
| 156 | const narrowed = @truncate(u12, ta); | 170 | const narrowed = @truncate(u12, ta); |
| 157 | | 171 | |
| 158 | log.debug(" | narrowed address within the page 0x{x}", .{narrowed}); | 172 | log.warn(" | narrowed address within the page 0x{x}", .{narrowed}); |
| 159 | log.debug(" | {s} opcode", .{page_off.op_kind}); | 173 | log.warn(" | {s} opcode", .{page_off.op_kind}); |
| 160 | | 174 | |
| 161 | var inst = page_off.inst; | 175 | var inst = page_off.inst; |
| 162 | if (page_off.op_kind == .arithmetic) { | 176 | if (page_off.op_kind == .arithmetic) { |
| ... | @@ -178,7 +192,7 @@ pub const Relocation = struct { | ... | @@ -178,7 +192,7 @@ pub const Relocation = struct { |
| 178 | inst.LoadStoreRegister.offset = offset; | 192 | inst.LoadStoreRegister.offset = offset; |
| 179 | } | 193 | } |
| 180 | | 194 | |
| 181 | mem.writeIntLittle(u32, page_off.base.code.*[page_off.base.offset..], inst.toU32()); | 195 | mem.writeIntLittle(u32, page_off.base.code[0..4], inst.toU32()); |
| 182 | } | 196 | } |
| 183 | }; | 197 | }; |
| 184 | | 198 | |
| ... | @@ -194,13 +208,13 @@ pub const Relocation = struct { | ... | @@ -194,13 +208,13 @@ pub const Relocation = struct { |
| 194 | const target_page = @intCast(i32, target_addr >> 12); | 208 | const target_page = @intCast(i32, target_addr >> 12); |
| 195 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); | 209 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); |
| 196 | | 210 | |
| 197 | log.debug(" | moving by {} pages", .{pages}); | 211 | log.warn(" | moving by {} pages", .{pages}); |
| 198 | | 212 | |
| 199 | var inst = page.inst; | 213 | var inst = page.inst; |
| 200 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); | 214 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); |
| 201 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); | 215 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); |
| 202 | | 216 | |
| 203 | mem.writeIntLittle(u32, page.base.code.*[page.base.offset..], inst.toU32()); | 217 | mem.writeIntLittle(u32, page.base.code[0..4], inst.toU32()); |
| 204 | } | 218 | } |
| 205 | }; | 219 | }; |
| 206 | | 220 | |
| ... | @@ -214,13 +228,13 @@ pub const Relocation = struct { | ... | @@ -214,13 +228,13 @@ pub const Relocation = struct { |
| 214 | pub fn resolve(page_off: GotPageOff, target_addr: u64) !void { | 228 | pub fn resolve(page_off: GotPageOff, target_addr: u64) !void { |
| 215 | const narrowed = @truncate(u12, target_addr); | 229 | const narrowed = @truncate(u12, target_addr); |
| 216 | | 230 | |
| 217 | log.debug(" | narrowed address within the page 0x{x}", .{narrowed}); | 231 | log.warn(" | narrowed address within the page 0x{x}", .{narrowed}); |
| 218 | | 232 | |
| 219 | var inst = page_off.inst; | 233 | var inst = page_off.inst; |
| 220 | const offset = try math.divExact(u12, narrowed, 8); | 234 | const offset = try math.divExact(u12, narrowed, 8); |
| 221 | inst.LoadStoreRegister.offset = offset; | 235 | inst.LoadStoreRegister.offset = offset; |
| 222 | | 236 | |
| 223 | mem.writeIntLittle(u32, page_off.base.code.*[page_off.base.offset..], inst.toU32()); | 237 | mem.writeIntLittle(u32, page_off.base.code[0..4], inst.toU32()); |
| 224 | } | 238 | } |
| 225 | }; | 239 | }; |
| 226 | | 240 | |
| ... | @@ -236,13 +250,13 @@ pub const Relocation = struct { | ... | @@ -236,13 +250,13 @@ pub const Relocation = struct { |
| 236 | const target_page = @intCast(i32, target_addr >> 12); | 250 | const target_page = @intCast(i32, target_addr >> 12); |
| 237 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); | 251 | const pages = @bitCast(u21, @intCast(i21, target_page - source_page)); |
| 238 | | 252 | |
| 239 | log.debug(" | moving by {} pages", .{pages}); | 253 | log.warn(" | moving by {} pages", .{pages}); |
| 240 | | 254 | |
| 241 | var inst = page.inst; | 255 | var inst = page.inst; |
| 242 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); | 256 | inst.PCRelativeAddress.immhi = @truncate(u19, pages >> 2); |
| 243 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); | 257 | inst.PCRelativeAddress.immlo = @truncate(u2, pages); |
| 244 | | 258 | |
| 245 | mem.writeIntLittle(u32, page.base.code.*[page.base.offset..], inst.toU32()); | 259 | mem.writeIntLittle(u32, page.base.code[0..4], inst.toU32()); |
| 246 | } | 260 | } |
| 247 | }; | 261 | }; |
| 248 | | 262 | |
| ... | @@ -258,17 +272,17 @@ pub const Relocation = struct { | ... | @@ -258,17 +272,17 @@ pub const Relocation = struct { |
| 258 | pub fn resolve(page_off: TlvpPageOff, target_addr: u64) !void { | 272 | pub fn resolve(page_off: TlvpPageOff, target_addr: u64) !void { |
| 259 | const narrowed = @truncate(u12, target_addr); | 273 | const narrowed = @truncate(u12, target_addr); |
| 260 | | 274 | |
| 261 | log.debug(" | narrowed address within the page 0x{x}", .{narrowed}); | 275 | log.warn(" | narrowed address within the page 0x{x}", .{narrowed}); |
| 262 | | 276 | |
| 263 | var inst = page_off.inst; | 277 | var inst = page_off.inst; |
| 264 | inst.AddSubtractImmediate.imm12 = narrowed; | 278 | inst.AddSubtractImmediate.imm12 = narrowed; |
| 265 | | 279 | |
| 266 | mem.writeIntLittle(u32, page_off.base.code.*[page_off.base.offset..], inst.toU32()); | 280 | mem.writeIntLittle(u32, page_off.base.code[0..4], inst.toU32()); |
| 267 | } | 281 | } |
| 268 | }; | 282 | }; |
| 269 | }; | 283 | }; |
| 270 | | 284 | |
| 271 | pub fn parse(allocator: *Allocator, code: *[]u8, relocs: []const macho.relocation_info) ![]*Relocation { | 285 | pub fn parse(allocator: *Allocator, code: []u8, relocs: []const macho.relocation_info) ![]*Relocation { |
| 272 | var it = RelocIterator{ | 286 | var it = RelocIterator{ |
| 273 | .buffer = relocs, | 287 | .buffer = relocs, |
| 274 | }; | 288 | }; |
| ... | @@ -280,8 +294,9 @@ pub fn parse(allocator: *Allocator, code: *[]u8, relocs: []const macho.relocatio | ... | @@ -280,8 +294,9 @@ pub fn parse(allocator: *Allocator, code: *[]u8, relocs: []const macho.relocatio |
| 280 | .parsed = std.ArrayList(*Relocation).init(allocator), | 294 | .parsed = std.ArrayList(*Relocation).init(allocator), |
| 281 | }; | 295 | }; |
| 282 | defer parser.deinit(); | 296 | defer parser.deinit(); |
| | 297 | try parser.parse(); |
| 283 | | 298 | |
| 284 | return parser.parse(); | 299 | return parser.parsed.toOwnedSlice(); |
| 285 | } | 300 | } |
| 286 | | 301 | |
| 287 | const RelocIterator = struct { | 302 | const RelocIterator = struct { |
| ... | @@ -292,12 +307,12 @@ const RelocIterator = struct { | ... | @@ -292,12 +307,12 @@ const RelocIterator = struct { |
| 292 | self.index += 1; | 307 | self.index += 1; |
| 293 | if (self.index < self.buffer.len) { | 308 | if (self.index < self.buffer.len) { |
| 294 | const reloc = self.buffer[@intCast(u64, self.index)]; | 309 | const reloc = self.buffer[@intCast(u64, self.index)]; |
| 295 | log.debug("{s}", .{@intToEnum(macho.reloc_type_arm64, reloc.r_type)}); | 310 | log.warn("{s}", .{@intToEnum(macho.reloc_type_arm64, reloc.r_type)}); |
| 296 | log.debug(" | offset = {}", .{reloc.r_address}); | 311 | log.warn(" | offset = {}", .{reloc.r_address}); |
| 297 | log.debug(" | PC = {}", .{reloc.r_pcrel == 1}); | 312 | log.warn(" | PC = {}", .{reloc.r_pcrel == 1}); |
| 298 | log.debug(" | length = {}", .{reloc.r_length}); | 313 | log.warn(" | length = {}", .{reloc.r_length}); |
| 299 | log.debug(" | symbolnum = {}", .{reloc.r_symbolnum}); | 314 | log.warn(" | symbolnum = {}", .{reloc.r_symbolnum}); |
| 300 | log.debug(" | extern = {}", .{reloc.r_extern == 1}); | 315 | log.warn(" | extern = {}", .{reloc.r_extern == 1}); |
| 301 | return reloc; | 316 | return reloc; |
| 302 | } | 317 | } |
| 303 | return null; | 318 | return null; |
| ... | @@ -316,7 +331,7 @@ const RelocIterator = struct { | ... | @@ -316,7 +331,7 @@ const RelocIterator = struct { |
| 316 | const Parser = struct { | 331 | const Parser = struct { |
| 317 | allocator: *Allocator, | 332 | allocator: *Allocator, |
| 318 | it: *RelocIterator, | 333 | it: *RelocIterator, |
| 319 | code: *[]u8, | 334 | code: []u8, |
| 320 | parsed: std.ArrayList(*Relocation), | 335 | parsed: std.ArrayList(*Relocation), |
| 321 | addend: ?u32 = null, | 336 | addend: ?u32 = null, |
| 322 | subtractor: ?Relocation.Target = null, | 337 | subtractor: ?Relocation.Target = null, |
| ... | @@ -325,7 +340,7 @@ const Parser = struct { | ... | @@ -325,7 +340,7 @@ const Parser = struct { |
| 325 | parser.parsed.deinit(); | 340 | parser.parsed.deinit(); |
| 326 | } | 341 | } |
| 327 | | 342 | |
| 328 | fn parse(parser: *Parser) ![]*Relocation { | 343 | fn parse(parser: *Parser) !void { |
| 329 | while (parser.it.next()) |reloc| { | 344 | while (parser.it.next()) |reloc| { |
| 330 | switch (@intToEnum(macho.reloc_type_arm64, reloc.r_type)) { | 345 | switch (@intToEnum(macho.reloc_type_arm64, reloc.r_type)) { |
| 331 | .ARM64_RELOC_BRANCH26 => { | 346 | .ARM64_RELOC_BRANCH26 => { |
| ... | @@ -360,8 +375,6 @@ const Parser = struct { | ... | @@ -360,8 +375,6 @@ const Parser = struct { |
| 360 | }, | 375 | }, |
| 361 | } | 376 | } |
| 362 | } | 377 | } |
| 363 | | | |
| 364 | return parser.parsed.toOwnedSlice(); | | |
| 365 | } | 378 | } |
| 366 | | 379 | |
| 367 | fn parseAddend(parser: *Parser, reloc: macho.relocation_info) !void { | 380 | fn parseAddend(parser: *Parser, reloc: macho.relocation_info) !void { |
| ... | @@ -395,7 +408,7 @@ const Parser = struct { | ... | @@ -395,7 +408,7 @@ const Parser = struct { |
| 395 | assert(reloc.r_length == 2); | 408 | assert(reloc.r_length == 2); |
| 396 | | 409 | |
| 397 | const offset = @intCast(u32, reloc.r_address); | 410 | const offset = @intCast(u32, reloc.r_address); |
| 398 | const inst = parser.code.*[offset..][0..4]; | 411 | const inst = parser.code[offset..][0..4]; |
| 399 | const parsed_inst = aarch64.Instruction{ .UnconditionalBranchImmediate = mem.bytesToValue( | 412 | const parsed_inst = aarch64.Instruction{ .UnconditionalBranchImmediate = mem.bytesToValue( |
| 400 | meta.TagPayload( | 413 | meta.TagPayload( |
| 401 | aarch64.Instruction, | 414 | aarch64.Instruction, |
| ... | @@ -412,14 +425,14 @@ const Parser = struct { | ... | @@ -412,14 +425,14 @@ const Parser = struct { |
| 412 | branch.* = .{ | 425 | branch.* = .{ |
| 413 | .base = .{ | 426 | .base = .{ |
| 414 | .@"type" = .branch, | 427 | .@"type" = .branch, |
| 415 | .code = parser.code, | 428 | .code = inst, |
| 416 | .offset = @intCast(u32, reloc.r_address), | 429 | .offset = @intCast(u32, reloc.r_address), |
| 417 | .target = target, | 430 | .target = target, |
| 418 | }, | 431 | }, |
| 419 | .inst = parsed_inst, | 432 | .inst = parsed_inst, |
| 420 | }; | 433 | }; |
| 421 | | 434 | |
| 422 | log.debug(" | emitting {}", .{branch}); | 435 | log.warn(" | emitting {}", .{branch}); |
| 423 | try parser.parsed.append(&branch.base); | 436 | try parser.parsed.append(&branch.base); |
| 424 | } | 437 | } |
| 425 | | 438 | |
| ... | @@ -431,7 +444,7 @@ const Parser = struct { | ... | @@ -431,7 +444,7 @@ const Parser = struct { |
| 431 | const target = Relocation.Target.from_reloc(reloc); | 444 | const target = Relocation.Target.from_reloc(reloc); |
| 432 | | 445 | |
| 433 | const offset = @intCast(u32, reloc.r_address); | 446 | const offset = @intCast(u32, reloc.r_address); |
| 434 | const inst = parser.code.*[offset..][0..4]; | 447 | const inst = parser.code[offset..][0..4]; |
| 435 | const parsed_inst = aarch64.Instruction{ .PCRelativeAddress = mem.bytesToValue(meta.TagPayload( | 448 | const parsed_inst = aarch64.Instruction{ .PCRelativeAddress = mem.bytesToValue(meta.TagPayload( |
| 436 | aarch64.Instruction, | 449 | aarch64.Instruction, |
| 437 | aarch64.Instruction.PCRelativeAddress, | 450 | aarch64.Instruction.PCRelativeAddress, |
| ... | @@ -450,7 +463,7 @@ const Parser = struct { | ... | @@ -450,7 +463,7 @@ const Parser = struct { |
| 450 | page.* = .{ | 463 | page.* = .{ |
| 451 | .base = .{ | 464 | .base = .{ |
| 452 | .@"type" = .page, | 465 | .@"type" = .page, |
| 453 | .code = parser.code, | 466 | .code = inst, |
| 454 | .offset = offset, | 467 | .offset = offset, |
| 455 | .target = target, | 468 | .target = target, |
| 456 | }, | 469 | }, |
| ... | @@ -458,7 +471,7 @@ const Parser = struct { | ... | @@ -458,7 +471,7 @@ const Parser = struct { |
| 458 | .inst = parsed_inst, | 471 | .inst = parsed_inst, |
| 459 | }; | 472 | }; |
| 460 | | 473 | |
| 461 | log.debug(" | emitting {}", .{page}); | 474 | log.warn(" | emitting {}", .{page}); |
| 462 | | 475 | |
| 463 | break :ptr &page.base; | 476 | break :ptr &page.base; |
| 464 | }, | 477 | }, |
| ... | @@ -469,14 +482,14 @@ const Parser = struct { | ... | @@ -469,14 +482,14 @@ const Parser = struct { |
| 469 | page.* = .{ | 482 | page.* = .{ |
| 470 | .base = .{ | 483 | .base = .{ |
| 471 | .@"type" = .got_page, | 484 | .@"type" = .got_page, |
| 472 | .code = parser.code, | 485 | .code = inst, |
| 473 | .offset = offset, | 486 | .offset = offset, |
| 474 | .target = target, | 487 | .target = target, |
| 475 | }, | 488 | }, |
| 476 | .inst = parsed_inst, | 489 | .inst = parsed_inst, |
| 477 | }; | 490 | }; |
| 478 | | 491 | |
| 479 | log.debug(" | emitting {}", .{page}); | 492 | log.warn(" | emitting {}", .{page}); |
| 480 | | 493 | |
| 481 | break :ptr &page.base; | 494 | break :ptr &page.base; |
| 482 | }, | 495 | }, |
| ... | @@ -487,14 +500,14 @@ const Parser = struct { | ... | @@ -487,14 +500,14 @@ const Parser = struct { |
| 487 | page.* = .{ | 500 | page.* = .{ |
| 488 | .base = .{ | 501 | .base = .{ |
| 489 | .@"type" = .tlvp_page, | 502 | .@"type" = .tlvp_page, |
| 490 | .code = parser.code, | 503 | .code = inst, |
| 491 | .offset = offset, | 504 | .offset = offset, |
| 492 | .target = target, | 505 | .target = target, |
| 493 | }, | 506 | }, |
| 494 | .inst = parsed_inst, | 507 | .inst = parsed_inst, |
| 495 | }; | 508 | }; |
| 496 | | 509 | |
| 497 | log.debug(" | emitting {}", .{page}); | 510 | log.warn(" | emitting {}", .{page}); |
| 498 | | 511 | |
| 499 | break :ptr &page.base; | 512 | break :ptr &page.base; |
| 500 | }, | 513 | }, |
| ... | @@ -517,7 +530,7 @@ const Parser = struct { | ... | @@ -517,7 +530,7 @@ const Parser = struct { |
| 517 | assert(reloc.r_length == 2); | 530 | assert(reloc.r_length == 2); |
| 518 | | 531 | |
| 519 | const offset = @intCast(u32, reloc.r_address); | 532 | const offset = @intCast(u32, reloc.r_address); |
| 520 | const inst = parser.code.*[offset..][0..4]; | 533 | const inst = parser.code[offset..][0..4]; |
| 521 | | 534 | |
| 522 | var op_kind: Relocation.PageOff.OpKind = undefined; | 535 | var op_kind: Relocation.PageOff.OpKind = undefined; |
| 523 | var parsed_inst: aarch64.Instruction = undefined; | 536 | var parsed_inst: aarch64.Instruction = undefined; |
| ... | @@ -542,7 +555,7 @@ const Parser = struct { | ... | @@ -542,7 +555,7 @@ const Parser = struct { |
| 542 | page_off.* = .{ | 555 | page_off.* = .{ |
| 543 | .base = .{ | 556 | .base = .{ |
| 544 | .@"type" = .page_off, | 557 | .@"type" = .page_off, |
| 545 | .code = parser.code, | 558 | .code = inst, |
| 546 | .offset = offset, | 559 | .offset = offset, |
| 547 | .target = target, | 560 | .target = target, |
| 548 | }, | 561 | }, |
| ... | @@ -551,7 +564,7 @@ const Parser = struct { | ... | @@ -551,7 +564,7 @@ const Parser = struct { |
| 551 | .addend = parser.addend, | 564 | .addend = parser.addend, |
| 552 | }; | 565 | }; |
| 553 | | 566 | |
| 554 | log.debug(" | emitting {}", .{page_off}); | 567 | log.warn(" | emitting {}", .{page_off}); |
| 555 | try parser.parsed.append(&page_off.base); | 568 | try parser.parsed.append(&page_off.base); |
| 556 | } | 569 | } |
| 557 | | 570 | |
| ... | @@ -562,7 +575,7 @@ const Parser = struct { | ... | @@ -562,7 +575,7 @@ const Parser = struct { |
| 562 | assert(reloc.r_length == 2); | 575 | assert(reloc.r_length == 2); |
| 563 | | 576 | |
| 564 | const offset = @intCast(u32, reloc.r_address); | 577 | const offset = @intCast(u32, reloc.r_address); |
| 565 | const inst = parser.code.*[offset..][0..4]; | 578 | const inst = parser.code[offset..][0..4]; |
| 566 | assert(!isArithmeticOp(inst)); | 579 | assert(!isArithmeticOp(inst)); |
| 567 | | 580 | |
| 568 | const parsed_inst = mem.bytesToValue(meta.TagPayload( | 581 | const parsed_inst = mem.bytesToValue(meta.TagPayload( |
| ... | @@ -579,7 +592,7 @@ const Parser = struct { | ... | @@ -579,7 +592,7 @@ const Parser = struct { |
| 579 | page_off.* = .{ | 592 | page_off.* = .{ |
| 580 | .base = .{ | 593 | .base = .{ |
| 581 | .@"type" = .got_page_off, | 594 | .@"type" = .got_page_off, |
| 582 | .code = parser.code, | 595 | .code = inst, |
| 583 | .offset = offset, | 596 | .offset = offset, |
| 584 | .target = target, | 597 | .target = target, |
| 585 | }, | 598 | }, |
| ... | @@ -588,7 +601,7 @@ const Parser = struct { | ... | @@ -588,7 +601,7 @@ const Parser = struct { |
| 588 | }, | 601 | }, |
| 589 | }; | 602 | }; |
| 590 | | 603 | |
| 591 | log.debug(" | emitting {}", .{page_off}); | 604 | log.warn(" | emitting {}", .{page_off}); |
| 592 | try parser.parsed.append(&page_off.base); | 605 | try parser.parsed.append(&page_off.base); |
| 593 | } | 606 | } |
| 594 | | 607 | |
| ... | @@ -605,7 +618,7 @@ const Parser = struct { | ... | @@ -605,7 +618,7 @@ const Parser = struct { |
| 605 | }; | 618 | }; |
| 606 | | 619 | |
| 607 | const offset = @intCast(u32, reloc.r_address); | 620 | const offset = @intCast(u32, reloc.r_address); |
| 608 | const inst = parser.code.*[offset..][0..4]; | 621 | const inst = parser.code[offset..][0..4]; |
| 609 | const parsed: RegInfo = parsed: { | 622 | const parsed: RegInfo = parsed: { |
| 610 | if (isArithmeticOp(inst)) { | 623 | if (isArithmeticOp(inst)) { |
| 611 | const parsed_inst = mem.bytesAsValue(meta.TagPayload( | 624 | const parsed_inst = mem.bytesAsValue(meta.TagPayload( |
| ... | @@ -638,7 +651,7 @@ const Parser = struct { | ... | @@ -638,7 +651,7 @@ const Parser = struct { |
| 638 | page_off.* = .{ | 651 | page_off.* = .{ |
| 639 | .base = .{ | 652 | .base = .{ |
| 640 | .@"type" = .tlvp_page_off, | 653 | .@"type" = .tlvp_page_off, |
| 641 | .code = parser.code, | 654 | .code = inst, |
| 642 | .offset = @intCast(u32, reloc.r_address), | 655 | .offset = @intCast(u32, reloc.r_address), |
| 643 | .target = target, | 656 | .target = target, |
| 644 | }, | 657 | }, |
| ... | @@ -655,7 +668,7 @@ const Parser = struct { | ... | @@ -655,7 +668,7 @@ const Parser = struct { |
| 655 | }, | 668 | }, |
| 656 | }; | 669 | }; |
| 657 | | 670 | |
| 658 | log.debug(" | emitting {}", .{page_off}); | 671 | log.warn(" | emitting {}", .{page_off}); |
| 659 | try parser.parsed.append(&page_off.base); | 672 | try parser.parsed.append(&page_off.base); |
| 660 | } | 673 | } |
| 661 | | 674 | |
| ... | @@ -700,14 +713,14 @@ const Parser = struct { | ... | @@ -700,14 +713,14 @@ const Parser = struct { |
| 700 | }; | 713 | }; |
| 701 | const offset = @intCast(u32, reloc.r_address); | 714 | const offset = @intCast(u32, reloc.r_address); |
| 702 | const addend: i64 = if (is_64bit) | 715 | const addend: i64 = if (is_64bit) |
| 703 | mem.readIntLittle(i64, parser.code.*[offset..][0..8]) | 716 | mem.readIntLittle(i64, parser.code[offset..][0..8]) |
| 704 | else | 717 | else |
| 705 | mem.readIntLittle(i32, parser.code.*[offset..][0..4]); | 718 | mem.readIntLittle(i32, parser.code[offset..][0..4]); |
| 706 | | 719 | |
| 707 | unsigned.* = .{ | 720 | unsigned.* = .{ |
| 708 | .base = .{ | 721 | .base = .{ |
| 709 | .@"type" = .unsigned, | 722 | .@"type" = .unsigned, |
| 710 | .code = parser.code, | 723 | .code = if (is_64bit) parser.code[offset..][0..8] else parser.code[offset..][0..4], |
| 711 | .offset = offset, | 724 | .offset = offset, |
| 712 | .target = target, | 725 | .target = target, |
| 713 | }, | 726 | }, |
| ... | @@ -716,7 +729,7 @@ const Parser = struct { | ... | @@ -716,7 +729,7 @@ const Parser = struct { |
| 716 | .addend = addend, | 729 | .addend = addend, |
| 717 | }; | 730 | }; |
| 718 | | 731 | |
| 719 | log.debug(" | emitting {}", .{unsigned}); | 732 | log.warn(" | emitting {}", .{unsigned}); |
| 720 | try parser.parsed.append(&unsigned.base); | 733 | try parser.parsed.append(&unsigned.base); |
| 721 | } | 734 | } |
| 722 | }; | 735 | }; |