authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-07-16 16:07:20+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-07-19 17:22:45+02:00
log388589987c104354c072d04128327e9823c87497
tree013db486a5b4334a355f4d8fdbb220477263bb93
parent70c71935c7c9f20353dc2a50b497b752d70d3452
signaturelock-open Commit is signed but in an unrecognized format.

wasm-linker: allow explicit memory exports

Rather than verifying if importing memory is false, we now rely on the option that was passed to the CLI (where export is defaulted to `true` unless only import-memory is given).

1 files changed, 4 insertions(+), 3 deletions(-)

src/link/Wasm.zig+4-3
......@@ -3519,6 +3519,7 @@ fn writeToFile(
35193519
35203520 // Import section
35213521 const import_memory = wasm.base.options.import_memory or is_obj;
3522 const export_memory = wasm.base.options.export_memory;
35223523 if (wasm.imports.count() != 0 or import_memory) {
35233524 const header_offset = try reserveVecSectionHeader(&binary_bytes);
35243525
......@@ -3621,7 +3622,7 @@ fn writeToFile(
36213622 }
36223623
36233624 // Export section
3624 if (wasm.exports.items.len != 0 or !import_memory) {
3625 if (wasm.exports.items.len != 0 or export_memory) {
36253626 const header_offset = try reserveVecSectionHeader(&binary_bytes);
36263627
36273628 for (wasm.exports.items) |exp| {
......@@ -3632,7 +3633,7 @@ fn writeToFile(
36323633 try leb.writeULEB128(binary_writer, exp.index);
36333634 }
36343635
3635 if (!import_memory) {
3636 if (export_memory) {
36363637 try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len)));
36373638 try binary_writer.writeAll("memory");
36383639 try binary_writer.writeByte(std.wasm.externalKind(.memory));
......@@ -3644,7 +3645,7 @@ fn writeToFile(
36443645 header_offset,
36453646 .@"export",
36463647 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),
3647 @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(!import_memory),
3648 @as(u32, @intCast(wasm.exports.items.len)) + @intFromBool(export_memory),
36483649 );
36493650 section_count += 1;
36503651 }