authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-18 17:55:49+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:41+01:00
log76dc305d4e71a9a4c9de92e6dde40a53eac1e328
treebb9a922590552d367d7a9dbc763355c344ca700f
parent82e92fe5f605a0ef8fa53e8434458bf18deadb5f

codegen: re-enable MachO support in genDeclRef


1 files changed, 16 insertions(+), 14 deletions(-)

src/codegen.zig+16-14
......@@ -984,22 +984,24 @@ fn genDeclRef(
984984 }
985985 return GenResult.mcv(.{ .load_symbol = sym.esym_index });
986986 } else if (lf.cast(link.File.MachO)) |macho_file| {
987 _ = macho_file;
988987 if (is_extern) {
989 // TODO make this part of getGlobalSymbol
990 // const name = zcu.intern_pool.stringToSlice(decl.name);
991 // const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name});
992 // defer gpa.free(sym_name);
993 // const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true });
994 // return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index });
988 const name = zcu.intern_pool.stringToSlice(decl.name);
989 const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name});
990 defer gpa.free(sym_name);
991 const lib_name = if (decl.getOwnedVariable(zcu)) |ov|
992 zcu.intern_pool.stringToSliceUnwrap(ov.lib_name)
993 else
994 null;
995 const sym_index = try macho_file.getGlobalSymbol(sym_name, lib_name);
996 macho_file.getSymbol(sym_index).flags.needs_got = true;
997 return GenResult.mcv(.{ .load_symbol = sym_index });
998 }
999 const sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index);
1000 const sym = macho_file.getSymbol(sym_index);
1001 if (is_threadlocal) {
1002 return GenResult.mcv(.{ .load_tlv = sym.nlist_idx });
9951003 }
996 // const atom_index = try macho_file.getOrCreateAtomForDecl(decl_index);
997 // const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;
998 // if (is_threadlocal) {
999 // return GenResult.mcv(.{ .load_tlv = sym_index });
1000 // }
1001 // return GenResult.mcv(.{ .load_got = sym_index });
1002 @panic("TODO genDeclRef");
1004 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
10031005 } else if (lf.cast(link.File.Coff)) |coff_file| {
10041006 if (is_extern) {
10051007 const name = zcu.intern_pool.stringToSlice(decl.name);