Skip to content

Commit 5dffd8c

Browse files
committed
Wasm: handle ref to an extern in getDeclVAddr
1 parent 62fad66 commit 5dffd8c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/link/Wasm/ZigObject.zig

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,22 @@ pub fn getDeclVAddr(
790790
reloc_info: link.File.RelocInfo,
791791
) !u64 {
792792
const target = wasm_file.base.comp.root_mod.resolved_target.result;
793-
const gpa = pt.zcu.gpa;
794-
const decl = pt.zcu.declPtr(decl_index);
793+
const zcu = pt.zcu;
794+
const ip = &zcu.intern_pool;
795+
const gpa = zcu.gpa;
796+
const decl = zcu.declPtr(decl_index);
795797

796798
const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index);
797-
const target_symbol_index = @intFromEnum(wasm_file.getAtom(target_atom_index).sym_index);
799+
const target_atom = wasm_file.getAtom(target_atom_index);
800+
const target_symbol_index = @intFromEnum(target_atom.sym_index);
801+
if (decl.isExtern(zcu)) {
802+
const name = decl.name.toSlice(ip);
803+
const lib_name = if (decl.getOwnedExternFunc(zcu)) |ext_fn|
804+
ext_fn.lib_name.toSlice(ip)
805+
else
806+
decl.getOwnedVariable(zcu).?.lib_name.toSlice(ip);
807+
try zig_object.addOrUpdateImport(wasm_file, name, target_atom.sym_index, lib_name, null);
808+
}
798809

799810
std.debug.assert(reloc_info.parent_atom_index != 0);
800811
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;

0 commit comments

Comments
 (0)