| ... | @@ -315,7 +315,7 @@ pub const StubsSection = struct { | ... | @@ -315,7 +315,7 @@ pub const StubsSection = struct { |
| 315 | pub const StubsHelperSection = struct { | 315 | pub const StubsHelperSection = struct { |
| 316 | pub inline fn preambleSize(cpu_arch: std.Target.Cpu.Arch) usize { | 316 | pub inline fn preambleSize(cpu_arch: std.Target.Cpu.Arch) usize { |
| 317 | return switch (cpu_arch) { | 317 | return switch (cpu_arch) { |
| 318 | .x86_64 => 15, | 318 | .x86_64 => 16, |
| 319 | .aarch64 => 6 * @sizeOf(u32), | 319 | .aarch64 => 6 * @sizeOf(u32), |
| 320 | else => 0, | 320 | else => 0, |
| 321 | }; | 321 | }; |
| ... | @@ -408,6 +408,7 @@ pub const StubsHelperSection = struct { | ... | @@ -408,6 +408,7 @@ pub const StubsHelperSection = struct { |
| 408 | try writer.writeInt(i32, @intCast(dyld_private_addr - sect.addr - 3 - 4), .little); | 408 | try writer.writeInt(i32, @intCast(dyld_private_addr - sect.addr - 3 - 4), .little); |
| 409 | try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); | 409 | try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); |
| 410 | try writer.writeInt(i32, @intCast(dyld_stub_binder_addr - sect.addr - 11 - 4), .little); | 410 | try writer.writeInt(i32, @intCast(dyld_stub_binder_addr - sect.addr - 11 - 4), .little); |
| | 411 | try writer.writeByte(0x90); |
| 411 | }, | 412 | }, |
| 412 | .aarch64 => { | 413 | .aarch64 => { |
| 413 | { | 414 | { |
| ... | @@ -460,7 +461,11 @@ pub const LaSymbolPtrSection = struct { | ... | @@ -460,7 +461,11 @@ pub const LaSymbolPtrSection = struct { |
| 460 | for (macho_file.stubs.symbols.items, 0..) |sym_index, idx| { | 461 | for (macho_file.stubs.symbols.items, 0..) |sym_index, idx| { |
| 461 | const sym = macho_file.getSymbol(sym_index); | 462 | const sym = macho_file.getSymbol(sym_index); |
| 462 | const addr = sect.addr + idx * @sizeOf(u64); | 463 | const addr = sect.addr + idx * @sizeOf(u64); |
| 463 | const entry = bind.Entry{ | 464 | const rebase_entry = Rebase.Entry{ |
| | 465 | .offset = addr - seg.vmaddr, |
| | 466 | .segment_id = seg_id, |
| | 467 | }; |
| | 468 | const bind_entry = bind.Entry{ |
| 464 | .target = sym_index, | 469 | .target = sym_index, |
| 465 | .offset = addr - seg.vmaddr, | 470 | .offset = addr - seg.vmaddr, |
| 466 | .segment_id = seg_id, | 471 | .segment_id = seg_id, |
| ... | @@ -468,20 +473,19 @@ pub const LaSymbolPtrSection = struct { | ... | @@ -468,20 +473,19 @@ pub const LaSymbolPtrSection = struct { |
| 468 | }; | 473 | }; |
| 469 | if (sym.flags.import) { | 474 | if (sym.flags.import) { |
| 470 | if (sym.flags.weak) { | 475 | if (sym.flags.weak) { |
| 471 | try macho_file.bind.entries.append(gpa, entry); | 476 | try macho_file.bind.entries.append(gpa, bind_entry); |
| 472 | try macho_file.weak_bind.entries.append(gpa, entry); | 477 | try macho_file.weak_bind.entries.append(gpa, bind_entry); |
| 473 | } else { | 478 | } else { |
| 474 | try macho_file.lazy_bind.entries.append(gpa, entry); | 479 | try macho_file.lazy_bind.entries.append(gpa, bind_entry); |
| | 480 | try macho_file.rebase.entries.append(gpa, rebase_entry); |
| 475 | } | 481 | } |
| 476 | } else { | 482 | } else { |
| 477 | if (sym.flags.weak) { | 483 | if (sym.flags.weak) { |
| 478 | try macho_file.rebase.entries.append(gpa, .{ | 484 | try macho_file.rebase.entries.append(gpa, rebase_entry); |
| 479 | .offset = addr - seg.vmaddr, | 485 | try macho_file.weak_bind.entries.append(gpa, bind_entry); |
| 480 | .segment_id = seg_id, | | |
| 481 | }); | | |
| 482 | try macho_file.weak_bind.entries.append(gpa, entry); | | |
| 483 | } else if (sym.flags.interposable) { | 486 | } else if (sym.flags.interposable) { |
| 484 | try macho_file.lazy_bind.entries.append(gpa, entry); | 487 | try macho_file.lazy_bind.entries.append(gpa, bind_entry); |
| | 488 | try macho_file.rebase.entries.append(gpa, rebase_entry); |
| 485 | } | 489 | } |
| 486 | } | 490 | } |
| 487 | } | 491 | } |
| ... | @@ -493,15 +497,19 @@ pub const LaSymbolPtrSection = struct { | ... | @@ -493,15 +497,19 @@ pub const LaSymbolPtrSection = struct { |
| 493 | _ = laptr; | 497 | _ = laptr; |
| 494 | const cpu_arch = macho_file.getTarget().cpu.arch; | 498 | const cpu_arch = macho_file.getTarget().cpu.arch; |
| 495 | const sect = macho_file.sections.items(.header)[macho_file.stubs_helper_sect_index.?]; | 499 | const sect = macho_file.sections.items(.header)[macho_file.stubs_helper_sect_index.?]; |
| 496 | for (macho_file.stubs.symbols.items, 0..) |sym_index, idx| { | 500 | var stub_helper_idx: u32 = 0; |
| | 501 | for (macho_file.stubs.symbols.items) |sym_index| { |
| 497 | const sym = macho_file.getSymbol(sym_index); | 502 | const sym = macho_file.getSymbol(sym_index); |
| 498 | const value: u64 = if (sym.flags.@"export") | 503 | const value: u64 = if (sym.flags.@"export") |
| 499 | sym.getAddress(.{ .stubs = false }, macho_file) | 504 | sym.getAddress(.{ .stubs = false }, macho_file) |
| 500 | else if (sym.flags.weak) | 505 | else if (sym.flags.weak) |
| 501 | @as(u64, 0) | 506 | @as(u64, 0) |
| 502 | else | 507 | else value: { |
| 503 | sect.addr + StubsHelperSection.preambleSize(cpu_arch) + | 508 | const value = sect.addr + StubsHelperSection.preambleSize(cpu_arch) + |
| 504 | StubsHelperSection.entrySize(cpu_arch) * idx; | 509 | StubsHelperSection.entrySize(cpu_arch) * stub_helper_idx; |
| | 510 | stub_helper_idx += 1; |
| | 511 | break :value value; |
| | 512 | }; |
| 505 | try writer.writeInt(u64, @intCast(value), .little); | 513 | try writer.writeInt(u64, @intCast(value), .little); |
| 506 | } | 514 | } |
| 507 | } | 515 | } |