x86_64+macho: emit .got instead of .got_load relocs

This commit is contained in:
Jakub Konka 2024-01-29 21:12:56 +01:00
parent 1ee628a3e0
commit d4966517f6
2 changed files with 11 additions and 12 deletions

View File

@ -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| {
@ -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
@ -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,

View File

@ -390,7 +390,7 @@ pub fn getDeclVAddr(
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(sym.nlist_idx),
},
});
return vaddr;
@ -416,7 +416,7 @@ pub fn getAnonDeclVAddr(
.pcrel = false,
.has_subtractor = false,
.length = 3,
.symbolnum = 0,
.symbolnum = @intCast(sym.nlist_idx),
},
});
return vaddr;
@ -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, .{
@ -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),
},
});