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(...@@ -3519,6 +3519,7 @@ fn writeToFile(
35193519
3520 // Import section3520 // Import section
3521 const import_memory = wasm.base.options.import_memory or is_obj;3521 const import_memory = wasm.base.options.import_memory or is_obj;
3522 const export_memory = wasm.base.options.export_memory;
3522 if (wasm.imports.count() != 0 or import_memory) {3523 if (wasm.imports.count() != 0 or import_memory) {
3523 const header_offset = try reserveVecSectionHeader(&binary_bytes);3524 const header_offset = try reserveVecSectionHeader(&binary_bytes);
35243525
...@@ -3621,7 +3622,7 @@ fn writeToFile(...@@ -3621,7 +3622,7 @@ fn writeToFile(
3621 }3622 }
36223623
3623 // Export section3624 // Export section
3624 if (wasm.exports.items.len != 0 or !import_memory) {3625 if (wasm.exports.items.len != 0 or export_memory) {
3625 const header_offset = try reserveVecSectionHeader(&binary_bytes);3626 const header_offset = try reserveVecSectionHeader(&binary_bytes);
36263627
3627 for (wasm.exports.items) |exp| {3628 for (wasm.exports.items) |exp| {
...@@ -3632,7 +3633,7 @@ fn writeToFile(...@@ -3632,7 +3633,7 @@ fn writeToFile(
3632 try leb.writeULEB128(binary_writer, exp.index);3633 try leb.writeULEB128(binary_writer, exp.index);
3633 }3634 }
36343635
3635 if (!import_memory) {3636 if (export_memory) {
3636 try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len)));3637 try leb.writeULEB128(binary_writer, @as(u32, @intCast("memory".len)));
3637 try binary_writer.writeAll("memory");3638 try binary_writer.writeAll("memory");
3638 try binary_writer.writeByte(std.wasm.externalKind(.memory));3639 try binary_writer.writeByte(std.wasm.externalKind(.memory));
...@@ -3644,7 +3645,7 @@ fn writeToFile(...@@ -3644,7 +3645,7 @@ fn writeToFile(
3644 header_offset,3645 header_offset,
3645 .@"export",3646 .@"export",
3646 @as(u32, @intCast(binary_bytes.items.len - header_offset - header_size)),3647 @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),
3648 );3649 );
3649 section_count += 1;3650 section_count += 1;
3650 }3651 }