| ... | ... | @@ -984,22 +984,24 @@ fn genDeclRef( |
| 984 | 984 | } |
| 985 | 985 | return GenResult.mcv(.{ .load_symbol = sym.esym_index }); |
| 986 | 986 | } else if (lf.cast(link.File.MachO)) |macho_file| { |
| 987 | | _ = macho_file; |
| 988 | 987 | 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 }); |
| 995 | 1003 | } |
| 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 }); |
| 1003 | 1005 | } else if (lf.cast(link.File.Coff)) |coff_file| { |
| 1004 | 1006 | if (is_extern) { |
| 1005 | 1007 | const name = zcu.intern_pool.stringToSlice(decl.name); |