diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.zig | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index f9263c2a69..83d0215cfa 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -984,22 +984,24 @@ fn genDeclRef( } return GenResult.mcv(.{ .load_symbol = sym.esym_index }); } else if (lf.cast(link.File.MachO)) |macho_file| { - _ = macho_file; if (is_extern) { - // TODO make this part of getGlobalSymbol - // const name = zcu.intern_pool.stringToSlice(decl.name); - // const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name}); - // defer gpa.free(sym_name); - // const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true }); - // return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index }); + const name = zcu.intern_pool.stringToSlice(decl.name); + const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name}); + defer gpa.free(sym_name); + const lib_name = if (decl.getOwnedVariable(zcu)) |ov| + zcu.intern_pool.stringToSliceUnwrap(ov.lib_name) + 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 sym_index = try macho_file.getZigObject().?.getOrCreateMetadataForDecl(macho_file, decl_index); + const sym = macho_file.getSymbol(sym_index); + if (is_threadlocal) { + return GenResult.mcv(.{ .load_tlv = sym.nlist_idx }); } - // const atom_index = try macho_file.getOrCreateAtomForDecl(decl_index); - // const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; - // if (is_threadlocal) { - // return GenResult.mcv(.{ .load_tlv = sym_index }); - // } - // return GenResult.mcv(.{ .load_got = sym_index }); - @panic("TODO genDeclRef"); + return GenResult.mcv(.{ .load_symbol = sym.nlist_idx }); } else if (lf.cast(link.File.Coff)) |coff_file| { if (is_extern) { const name = zcu.intern_pool.stringToSlice(decl.name); |
