zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 5dffd8cb7b5bfa68c9c0cbc1c7dc3590a6e0a42f (tree)
parent 62fad66d648f8eb9d734a8d8aa36ea56f398c0f2
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sat, 10 Aug 2024 22:22:09 +0200

Wasm: handle ref to an extern in getDeclVAddr

Diffstat:
Msrc/link/Wasm/ZigObject.zig | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig @@ -790,11 +790,22 @@ pub fn getDeclVAddr( reloc_info: link.File.RelocInfo, ) !u64 { const target = wasm_file.base.comp.root_mod.resolved_target.result; - const gpa = pt.zcu.gpa; - const decl = pt.zcu.declPtr(decl_index); + const zcu = pt.zcu; + const ip = &zcu.intern_pool; + const gpa = zcu.gpa; + const decl = zcu.declPtr(decl_index); const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); - const target_symbol_index = @intFromEnum(wasm_file.getAtom(target_atom_index).sym_index); + const target_atom = wasm_file.getAtom(target_atom_index); + const target_symbol_index = @intFromEnum(target_atom.sym_index); + if (decl.isExtern(zcu)) { + const name = decl.name.toSlice(ip); + const lib_name = if (decl.getOwnedExternFunc(zcu)) |ext_fn| + ext_fn.lib_name.toSlice(ip) + else + decl.getOwnedVariable(zcu).?.lib_name.toSlice(ip); + try zig_object.addOrUpdateImport(wasm_file, name, target_atom.sym_index, lib_name, null); + } std.debug.assert(reloc_info.parent_atom_index != 0); const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;