codegen: re-enable MachO support in genDeclRef

This commit is contained in:
Jakub Konka 2024-01-18 17:55:49 +01:00
parent 82e92fe5f6
commit 76dc305d4e

View File

@ -984,22 +984,24 @@ fn genDeclRef(
} }
return GenResult.mcv(.{ .load_symbol = sym.esym_index }); return GenResult.mcv(.{ .load_symbol = sym.esym_index });
} else if (lf.cast(link.File.MachO)) |macho_file| { } else if (lf.cast(link.File.MachO)) |macho_file| {
_ = macho_file;
if (is_extern) { if (is_extern) {
// TODO make this part of getGlobalSymbol const name = zcu.intern_pool.stringToSlice(decl.name);
// const name = zcu.intern_pool.stringToSlice(decl.name); const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name});
// const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name}); defer gpa.free(sym_name);
// defer gpa.free(sym_name); const lib_name = if (decl.getOwnedVariable(zcu)) |ov|
// const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true }); zcu.intern_pool.stringToSliceUnwrap(ov.lib_name)
// return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index }); else
null;
const sym_index = try macho_file.getGlobalSymbol(sym_name, lib_name);
macho_file.getSymbol(sym_index).flags.needs_got = true;
return GenResult.mcv(.{ .load_symbol = sym_index });
} }
// const atom_index = try macho_file.getOrCreateAtomForDecl(decl_index); const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index);
// const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; const sym = macho_file.getSymbol(sym_index);
// if (is_threadlocal) { if (is_threadlocal) {
// return GenResult.mcv(.{ .load_tlv = sym_index }); return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });
// } }
// return GenResult.mcv(.{ .load_got = sym_index }); return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
@panic("TODO genDeclRef");
} else if (lf.cast(link.File.Coff)) |coff_file| { } else if (lf.cast(link.File.Coff)) |coff_file| {
if (is_extern) { if (is_extern) {
const name = zcu.intern_pool.stringToSlice(decl.name); const name = zcu.intern_pool.stringToSlice(decl.name);