Skip to content

Commit

Permalink
x86_64+macho: emit .got instead of .got_load relocs
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 31, 2024
1 parent 1ee628a commit d496651
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/arch/x86_64/Emit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn emitMir(emit: *Emit) Error!void {
.pcrel = true,
.has_subtractor = false,
.length = 2,
.symbolnum = 0,
.symbolnum = @intCast(symbol.sym_index),
},
});
} else if (emit.lower.bin_file.cast(link.File.Coff)) |coff_file| {
Expand Down Expand Up @@ -165,7 +165,9 @@ pub fn emitMir(emit: *Emit) Error!void {
const @"type": link.File.MachO.Relocation.Type = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
.zig_got_load
else if (sym.flags.needs_got)
.got_load
// TODO: it is possible to emit .got_load here that can potentially be relaxed
// however this requires always to use a MOVQ mnemonic
.got
else if (sym.flags.tlv)
.tlv
else
Expand All @@ -180,7 +182,7 @@ pub fn emitMir(emit: *Emit) Error!void {
.pcrel = true,
.has_subtractor = false,
.length = 2,
.symbolnum = 0,
.symbolnum = @intCast(data.sym_index),
},
});
} else unreachable,
Expand Down
15 changes: 6 additions & 9 deletions src/link/MachO/ZigObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub fn getDeclVAddr(
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(sym.nlist_idx),
},
});
return vaddr;
Expand All @@ -416,7 +416,7 @@ pub fn getAnonDeclVAddr(
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(sym.nlist_idx),
},
});
return vaddr;
Expand Down Expand Up @@ -856,21 +856,18 @@ fn createTlvDescriptor(
atom.alignment = alignment;
atom.size = size;

const tlv_bootstrap_index = blk: {
const index = try self.getGlobalSymbol(macho_file, "_tlv_bootstrap", null);
break :blk self.symbols.items[index];
};
const tlv_bootstrap_index = try self.getGlobalSymbol(macho_file, "_tlv_bootstrap", null);
try atom.addReloc(macho_file, .{
.tag = .@"extern",
.offset = 0,
.target = tlv_bootstrap_index,
.target = self.symbols.items[tlv_bootstrap_index],
.addend = 0,
.type = .unsigned,
.meta = .{
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(tlv_bootstrap_index),
},
});
try atom.addReloc(macho_file, .{
Expand All @@ -883,7 +880,7 @@ fn createTlvDescriptor(
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(macho_file.getSymbol(init_sym_index).nlist_idx),
},
});

Expand Down

0 comments on commit d496651

Please sign in to comment.