diff options
Diffstat (limited to 'src/link/MachO/dyld_info/bind.zig')
| -rw-r--r-- | src/link/MachO/dyld_info/bind.zig | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/link/MachO/dyld_info/bind.zig b/src/link/MachO/dyld_info/bind.zig index 8684c66bac..94e7c7ef29 100644 --- a/src/link/MachO/dyld_info/bind.zig +++ b/src/link/MachO/dyld_info/bind.zig @@ -1,17 +1,19 @@ pub const Entry = struct { - target: Symbol.Index, + target: MachO.Ref, offset: u64, segment_id: u8, addend: i64, pub fn lessThan(ctx: *MachO, entry: Entry, other: Entry) bool { + _ = ctx; if (entry.segment_id == other.segment_id) { - if (entry.target == other.target) { + if (entry.target.eql(other.target)) { return entry.offset < other.offset; } - const entry_name = ctx.getSymbol(entry.target).getName(ctx); - const other_name = ctx.getSymbol(other.target).getName(ctx); - return std.mem.lessThan(u8, entry_name, other_name); + if (entry.target.file == other.target.file) { + return entry.target.index < other.target.index; + } + return entry.target.file < other.target.file; } return entry.segment_id < other.segment_id; } @@ -44,7 +46,7 @@ pub const Bind = struct { for (objects.items) |index| { const file = macho_file.getFile(index).?; for (file.getAtoms()) |atom_index| { - const atom = macho_file.getAtom(atom_index) orelse continue; + const atom = file.getAtom(atom_index) orelse continue; if (!atom.flags.alive) continue; if (atom.getInputSection(macho_file).isZerofill()) continue; const atom_addr = atom.getAddress(macho_file); @@ -55,10 +57,10 @@ pub const Bind = struct { if (rel.type != .unsigned or rel.meta.length != 3 or rel.tag != .@"extern") continue; const rel_offset = rel.offset - atom.off; const addend = rel.addend + rel.getRelocAddend(cpu_arch); - const sym = rel.getTargetSymbol(macho_file); + const sym = rel.getTargetSymbol(atom.*, macho_file); if (sym.isTlvInit(macho_file)) continue; const entry = Entry{ - .target = rel.target, + .target = rel.getTargetSymbolRef(atom.*, macho_file), .offset = atom_addr + rel_offset - seg.vmaddr, .segment_id = seg_id, .addend = addend, @@ -74,7 +76,7 @@ pub const Bind = struct { const seg_id = macho_file.sections.items(.segment_id)[sid]; const seg = macho_file.segments.items[seg_id]; for (macho_file.got.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = macho_file.got.getAddress(@intCast(idx), macho_file); const entry = Entry{ .target = ref, @@ -93,7 +95,7 @@ pub const Bind = struct { const seg_id = macho_file.sections.items(.segment_id)[sid]; const seg = macho_file.segments.items[seg_id]; for (macho_file.stubs.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = sect.addr + idx * @sizeOf(u64); const bind_entry = Entry{ .target = ref, @@ -112,7 +114,7 @@ pub const Bind = struct { const seg = macho_file.segments.items[seg_id]; for (macho_file.tlv_ptr.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = macho_file.tlv_ptr.getAddress(@intCast(idx), macho_file); const entry = Entry{ .target = ref, @@ -162,7 +164,7 @@ pub const Bind = struct { var addend: i64 = 0; var count: usize = 0; var skip: u64 = 0; - var target: ?Symbol.Index = null; + var target: ?MachO.Ref = null; var state: enum { start, @@ -173,7 +175,7 @@ pub const Bind = struct { var i: usize = 0; while (i < entries.len) : (i += 1) { const current = entries[i]; - if (target == null or target.? != current.target) { + if (target == null or !target.?.eql(current.target)) { switch (state) { .start => {}, .bind_single => try doBind(writer), @@ -182,7 +184,7 @@ pub const Bind = struct { state = .start; target = current.target; - const sym = ctx.getSymbol(current.target); + const sym = current.target.getSymbol(ctx).?; const name = sym.getName(ctx); const flags: u8 = if (sym.weakRef(ctx)) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0; const ordinal: i16 = ord: { @@ -296,7 +298,7 @@ pub const WeakBind = struct { for (objects.items) |index| { const file = macho_file.getFile(index).?; for (file.getAtoms()) |atom_index| { - const atom = macho_file.getAtom(atom_index) orelse continue; + const atom = file.getAtom(atom_index) orelse continue; if (!atom.flags.alive) continue; if (atom.getInputSection(macho_file).isZerofill()) continue; const atom_addr = atom.getAddress(macho_file); @@ -307,10 +309,10 @@ pub const WeakBind = struct { if (rel.type != .unsigned or rel.meta.length != 3 or rel.tag != .@"extern") continue; const rel_offset = rel.offset - atom.off; const addend = rel.addend + rel.getRelocAddend(cpu_arch); - const sym = rel.getTargetSymbol(macho_file); + const sym = rel.getTargetSymbol(atom.*, macho_file); if (sym.isTlvInit(macho_file)) continue; const entry = Entry{ - .target = rel.target, + .target = rel.getTargetSymbolRef(atom.*, macho_file), .offset = atom_addr + rel_offset - seg.vmaddr, .segment_id = seg_id, .addend = addend, @@ -326,7 +328,7 @@ pub const WeakBind = struct { const seg_id = macho_file.sections.items(.segment_id)[sid]; const seg = macho_file.segments.items[seg_id]; for (macho_file.got.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = macho_file.got.getAddress(@intCast(idx), macho_file); const entry = Entry{ .target = ref, @@ -346,7 +348,7 @@ pub const WeakBind = struct { const seg = macho_file.segments.items[seg_id]; for (macho_file.stubs.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = sect.addr + idx * @sizeOf(u64); const bind_entry = Entry{ .target = ref, @@ -365,7 +367,7 @@ pub const WeakBind = struct { const seg = macho_file.segments.items[seg_id]; for (macho_file.tlv_ptr.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = macho_file.tlv_ptr.getAddress(@intCast(idx), macho_file); const entry = Entry{ .target = ref, @@ -415,7 +417,7 @@ pub const WeakBind = struct { var addend: i64 = 0; var count: usize = 0; var skip: u64 = 0; - var target: ?Symbol.Index = null; + var target: ?MachO.Ref = null; var state: enum { start, @@ -426,7 +428,7 @@ pub const WeakBind = struct { var i: usize = 0; while (i < entries.len) : (i += 1) { const current = entries[i]; - if (target == null or target.? != current.target) { + if (target == null or !target.?.eql(current.target)) { switch (state) { .start => {}, .bind_single => try doBind(writer), @@ -435,7 +437,7 @@ pub const WeakBind = struct { state = .start; target = current.target; - const sym = ctx.getSymbol(current.target); + const sym = current.target.getSymbol(ctx).?; const name = sym.getName(ctx); const flags: u8 = 0; // TODO NON_WEAK_DEFINITION @@ -536,7 +538,7 @@ pub const LazyBind = struct { const seg = macho_file.segments.items[seg_id]; for (macho_file.stubs.symbols.items, 0..) |ref, idx| { - const sym = macho_file.getSymbol(ref); + const sym = ref.getSymbol(macho_file).?; const addr = sect.addr + idx * @sizeOf(u64); const bind_entry = Entry{ .target = ref, @@ -565,7 +567,7 @@ pub const LazyBind = struct { for (self.entries.items) |entry| { self.offsets.appendAssumeCapacity(@intCast(self.buffer.items.len)); - const sym = ctx.getSymbol(entry.target); + const sym = entry.target.getSymbol(ctx).?; const name = sym.getName(ctx); const flags: u8 = if (sym.weakRef(ctx)) macho.BIND_SYMBOL_FLAGS_WEAK_IMPORT else 0; const ordinal: i16 = ord: { |
