aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-10-30 00:09:32 +0100
committerJakub Konka <kubkon@jakubkonka.com>2023-10-30 00:09:32 +0100
commit2e690f5c74cbfd16757cc301ac0d899caa8b2fb3 (patch)
treead622a039430932b24f69d968d73c3e4fb8c8ed8 /src/codegen.zig
parent71dfea1f174b0531139e33e8aa4fe86ccd9f23dd (diff)
downloadzig-2e690f5c74cbfd16757cc301ac0d899caa8b2fb3.tar.gz
zig-2e690f5c74cbfd16757cc301ac0d899caa8b2fb3.zip
macho: implement enough of extern handling to pass comptime export tests
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 4db32df16f..cb7c2df55a 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -721,6 +721,7 @@ fn lowerAnonDeclRef(
const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
const decl_val = anon_decl.val;
const decl_ty = mod.intern_pool.typeOf(decl_val).toType();
+ log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(mod)});
const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
if (!is_fn_body and !decl_ty.hasRuntimeBits(mod)) {
try code.appendNTimes(0xaa, ptr_width_bytes);
@@ -911,6 +912,14 @@ fn genDeclRef(
_ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
return GenResult.mcv(.{ .load_symbol = sym.esym_index });
} else if (bin_file.cast(link.File.MachO)) |macho_file| {
+ if (is_extern) {
+ // TODO make this part of getGlobalSymbol
+ const name = mod.intern_pool.stringToSlice(decl.name);
+ const sym_name = try std.fmt.allocPrint(bin_file.allocator, "_{s}", .{name});
+ defer bin_file.allocator.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 atom_index = try macho_file.getOrCreateAtomForDecl(decl_index);
const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;
if (is_threadlocal) {