From acec06cfaf9a82ec8037a23993ff36fa72eb6e82 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Mon, 21 Feb 2022 21:43:38 +0100 Subject: wasm-linker: Implement `updateDeclExports` We now correctly implement exporting decls. This means it is possible to export a decl with a different name than the decl that is doing the export. This also sets the symbols with the correct flags, so when we emit a relocatable object file, a linker can correctly resolve symbols and/or export the symbol to the host environment. This commit also includes fixes to ensure relocations have the correct offset to how other linkers will expect the offset, rather than what we use internally. Other linkers accept the offset, relative to the section. Internally we use an offset relative to the atom. --- src/arch/wasm/CodeGen.zig | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/arch/wasm/CodeGen.zig') diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index b776f30346..1fb7fc0e2f 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1320,14 +1320,18 @@ pub const DeclGen = struct { } decl.markAlive(); - try writer.writeIntLittle(u32, try self.bin_file.getDeclVAddr( - self.decl, // The decl containing the source symbol index - decl.ty, // type we generate the address of - self.symbol_index, // source symbol index - decl.link.wasm.sym_index, // target symbol index - @intCast(u32, self.code.items.len), // offset - @intCast(u32, offset), // addend - )); + if (decl.link.wasm.sym_index == 0) { + try writer.writeIntLittle(u32, 0); + } else { + try writer.writeIntLittle(u32, try self.bin_file.getDeclVAddr( + self.decl, // The decl containing the source symbol index + decl.ty, // type we generate the address of + self.symbol_index, // source symbol index + decl.link.wasm.sym_index, // target symbol index + @intCast(u32, self.code.items.len), // offset + @intCast(u32, offset), // addend + )); + } return Result{ .appended = {} }; } }; -- cgit v1.2.3