| ... | ... | @@ -656,7 +656,7 @@ pub const Indsymtab = struct { |
| 656 | 656 | }; |
| 657 | 657 | |
| 658 | 658 | pub const DataInCode = struct { |
| 659 | | entries: std.ArrayListUnmanaged(macho.data_in_code_entry) = .{}, |
| 659 | entries: std.ArrayListUnmanaged(Entry) = .{}, |
| 660 | 660 | |
| 661 | 661 | pub fn deinit(dice: *DataInCode, allocator: Allocator) void { |
| 662 | 662 | dice.entries.deinit(allocator); |
| ... | ... | @@ -668,10 +668,6 @@ pub const DataInCode = struct { |
| 668 | 668 | |
| 669 | 669 | pub fn updateSize(dice: *DataInCode, macho_file: *MachO) !void { |
| 670 | 670 | const gpa = macho_file.base.comp.gpa; |
| 671 | | const base_address = if (!macho_file.base.isRelocatable()) |
| 672 | | macho_file.getTextSegment().vmaddr |
| 673 | | else |
| 674 | | 0; |
| 675 | 671 | |
| 676 | 672 | for (macho_file.objects.items) |index| { |
| 677 | 673 | const object = macho_file.getFile(index).?.object; |
| ... | ... | @@ -683,7 +679,6 @@ pub const DataInCode = struct { |
| 683 | 679 | for (object.getAtoms()) |atom_index| { |
| 684 | 680 | if (next_dice >= dices.len) break; |
| 685 | 681 | const atom = object.getAtom(atom_index) orelse continue; |
| 686 | | if (!atom.flags.alive) continue; |
| 687 | 682 | const start_off = atom.getInputAddress(macho_file); |
| 688 | 683 | const end_off = start_off + atom.size; |
| 689 | 684 | const start_dice = next_dice; |
| ... | ... | @@ -696,7 +691,8 @@ pub const DataInCode = struct { |
| 696 | 691 | |
| 697 | 692 | if (atom.flags.alive) for (dices[start_dice..next_dice]) |d| { |
| 698 | 693 | dice.entries.appendAssumeCapacity(.{ |
| 699 | | .offset = @intCast(atom.getAddress(macho_file) + d.offset - start_off - base_address), |
| 694 | .atom_ref = .{ .index = atom_index, .file = index }, |
| 695 | .offset = @intCast(d.offset - start_off), |
| 700 | 696 | .length = d.length, |
| 701 | 697 | .kind = d.kind, |
| 702 | 698 | }); |
| ... | ... | @@ -706,6 +702,29 @@ pub const DataInCode = struct { |
| 706 | 702 | |
| 707 | 703 | macho_file.data_in_code_cmd.datasize = math.cast(u32, dice.size()) orelse return error.Overflow; |
| 708 | 704 | } |
| 705 | |
| 706 | pub fn write(dice: DataInCode, macho_file: *MachO, writer: anytype) !void { |
| 707 | const base_address = if (!macho_file.base.isRelocatable()) |
| 708 | macho_file.getTextSegment().vmaddr |
| 709 | else |
| 710 | 0; |
| 711 | for (dice.entries.items) |entry| { |
| 712 | const atom_address = entry.atom_ref.getAtom(macho_file).?.getAddress(macho_file); |
| 713 | const offset = atom_address + entry.offset - base_address; |
| 714 | try writer.writeStruct(macho.data_in_code_entry{ |
| 715 | .offset = @intCast(offset), |
| 716 | .length = entry.length, |
| 717 | .kind = entry.kind, |
| 718 | }); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | const Entry = struct { |
| 723 | atom_ref: MachO.Ref, |
| 724 | offset: u32, |
| 725 | length: u16, |
| 726 | kind: u16, |
| 727 | }; |
| 709 | 728 | }; |
| 710 | 729 | |
| 711 | 730 | const aarch64 = @import("../aarch64.zig"); |