authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-08-18 05:54:15+02:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-08-18 17:43:59+02:00
log7051f8e73b875aca52cc2e56a8f296d847f8dfa8
treeacb491f8d2ea6ea83da894b133ef492e569e1dc3
parent5ec479a179e24a2124e25dc3ae6560a74574526f

wasm: add --growable-table


9 files changed, 26 insertions(+), 2 deletions(-)

lib/compiler/Maker/Step/Compile.zig+1
...@@ -728,6 +728,7 @@ fn lowerZigArgs(...@@ -728,6 +728,7 @@ fn lowerZigArgs(
728 try addBool(gpa, zig_args, "--import-symbols", conf_comp.flags.import_symbols);728 try addBool(gpa, zig_args, "--import-symbols", conf_comp.flags.import_symbols);
729 try addBool(gpa, zig_args, "--import-table", conf_comp.flags.import_table);729 try addBool(gpa, zig_args, "--import-table", conf_comp.flags.import_table);
730 try addBool(gpa, zig_args, "--export-table", conf_comp.flags.export_table);730 try addBool(gpa, zig_args, "--export-table", conf_comp.flags.export_table);
731 try addBool(gpa, zig_args, "--growable-table", conf_comp.flags.growable_table);
731 try addBool(gpa, zig_args, "--shared-memory", conf_comp.flags.shared_memory);732 try addBool(gpa, zig_args, "--shared-memory", conf_comp.flags.shared_memory);
732733
733 {734 {
lib/std/Build/Configuration.zig+1-1
...@@ -953,6 +953,7 @@ pub const Step = extern struct {...@@ -953,6 +953,7 @@ pub const Step = extern struct {
953 import_symbols: bool,953 import_symbols: bool,
954 import_table: bool,954 import_table: bool,
955 export_table: bool,955 export_table: bool,
956 growable_table: bool,
956 shared_memory: bool,957 shared_memory: bool,
957 link_eh_frame_hdr: bool,958 link_eh_frame_hdr: bool,
958 link_emit_relocs: bool,959 link_emit_relocs: bool,
...@@ -968,7 +969,6 @@ pub const Step = extern struct {...@@ -968,7 +969,6 @@ pub const Step = extern struct {
968 force_load_objc: bool,969 force_load_objc: bool,
969 discard_local_symbols: bool,970 discard_local_symbols: bool,
970 mingw_unicode_entry_point: bool,971 mingw_unicode_entry_point: bool,
971 _: u1 = 0,
972 };972 };
973973
974 pub const Flags2 = packed struct(u32) {974 pub const Flags2 = packed struct(u32) {
lib/std/Build/Serialize.zig+1
...@@ -133,6 +133,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi...@@ -133,6 +133,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
133 .import_symbols = c.import_symbols,133 .import_symbols = c.import_symbols,
134 .import_table = c.import_table,134 .import_table = c.import_table,
135 .export_table = c.export_table,135 .export_table = c.export_table,
136 .growable_table = c.growable_table,
136 .shared_memory = c.shared_memory,137 .shared_memory = c.shared_memory,
137 .link_eh_frame_hdr = c.link_eh_frame_hdr,138 .link_eh_frame_hdr = c.link_eh_frame_hdr,
138 .link_emit_relocs = c.link_emit_relocs,139 .link_emit_relocs = c.link_emit_relocs,
lib/std/Build/Step/Compile.zig+1
...@@ -45,6 +45,7 @@ import_symbols: bool = false,...@@ -45,6 +45,7 @@ import_symbols: bool = false,
45/// (WebAssembly) import function table from the host environment45/// (WebAssembly) import function table from the host environment
46import_table: bool = false,46import_table: bool = false,
47export_table: bool = false,47export_table: bool = false,
48growable_table: bool = false,
48initial_memory: ?u64 = null,49initial_memory: ?u64 = null,
49max_memory: ?u64 = null,50max_memory: ?u64 = null,
50shared_memory: bool = false,51shared_memory: bool = false,
src/Compilation.zig+3
...@@ -1478,6 +1478,7 @@ pub const CreateOptions = struct {...@@ -1478,6 +1478,7 @@ pub const CreateOptions = struct {
1478 linker_import_symbols: bool = false,1478 linker_import_symbols: bool = false,
1479 linker_import_table: bool = false,1479 linker_import_table: bool = false,
1480 linker_export_table: bool = false,1480 linker_export_table: bool = false,
1481 linker_growable_table: bool = false,
1481 linker_initial_memory: ?u64 = null,1482 linker_initial_memory: ?u64 = null,
1482 linker_max_memory: ?u64 = null,1483 linker_max_memory: ?u64 = null,
1483 linker_global_base: ?u64 = null,1484 linker_global_base: ?u64 = null,
...@@ -2183,6 +2184,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2183,6 +2184,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2183 .import_symbols = options.linker_import_symbols,2184 .import_symbols = options.linker_import_symbols,
2184 .import_table = options.linker_import_table,2185 .import_table = options.linker_import_table,
2185 .export_table = options.linker_export_table,2186 .export_table = options.linker_export_table,
2187 .growable_table = options.linker_growable_table,
2186 .initial_memory = options.linker_initial_memory,2188 .initial_memory = options.linker_initial_memory,
2187 .max_memory = options.linker_max_memory,2189 .max_memory = options.linker_max_memory,
2188 .global_base = options.linker_global_base,2190 .global_base = options.linker_global_base,
...@@ -3434,6 +3436,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -3434,6 +3436,7 @@ fn addNonIncrementalStuffToCacheManifest(
3434 man.hash.add(opts.import_symbols);3436 man.hash.add(opts.import_symbols);
3435 man.hash.add(opts.import_table);3437 man.hash.add(opts.import_table);
3436 man.hash.add(opts.export_table);3438 man.hash.add(opts.export_table);
3439 man.hash.add(opts.growable_table);
34373440
3438 // Mach-O specific stuff3441 // Mach-O specific stuff
3439 try link.File.MachO.hashAddFrameworks(man, opts.frameworks);3442 try link.File.MachO.hashAddFrameworks(man, opts.frameworks);
src/link.zig+1
...@@ -444,6 +444,7 @@ pub const File = struct {...@@ -444,6 +444,7 @@ pub const File = struct {
444 import_symbols: bool,444 import_symbols: bool,
445 import_table: bool,445 import_table: bool,
446 export_table: bool,446 export_table: bool,
447 growable_table: bool,
447 initial_memory: ?u64,448 initial_memory: ?u64,
448 max_memory: ?u64,449 max_memory: ?u64,
449 object_host_name: ?[]const u8,450 object_host_name: ?[]const u8,
src/link/Lld.zig+7
...@@ -166,6 +166,8 @@ const Wasm = struct {...@@ -166,6 +166,8 @@ const Wasm = struct {
166 import_table: bool,166 import_table: bool,
167 /// When true, will export the function table to the host environment.167 /// When true, will export the function table to the host environment.
168 export_table: bool,168 export_table: bool,
169 /// When true, remove maximum size from function table, allowing table to grow.
170 growable_table: bool,
169 /// When defined, sets the initial memory size of the memory.171 /// When defined, sets the initial memory size of the memory.
170 initial_memory: ?u64,172 initial_memory: ?u64,
171 /// When defined, sets the maximum memory size of the memory.173 /// When defined, sets the maximum memory size of the memory.
...@@ -190,6 +192,7 @@ const Wasm = struct {...@@ -190,6 +192,7 @@ const Wasm = struct {
190 },192 },
191 .import_table = options.import_table,193 .import_table = options.import_table,
192 .export_table = options.export_table,194 .export_table = options.export_table,
195 .growable_table = options.growable_table,
193 .initial_memory = options.initial_memory,196 .initial_memory = options.initial_memory,
194 .max_memory = options.max_memory,197 .max_memory = options.max_memory,
195 .global_base = options.global_base,198 .global_base = options.global_base,
...@@ -1465,6 +1468,10 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {...@@ -1465,6 +1468,10 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
1465 try argv.append("--export-table");1468 try argv.append("--export-table");
1466 }1469 }
14671470
1471 if (wasm.growable_table) {
1472 try argv.append("--growable-table");
1473 }
1474
1468 // For wasm-ld we only need to specify '--no-gc-sections' when the user explicitly1475 // For wasm-ld we only need to specify '--no-gc-sections' when the user explicitly
1469 // specified it as garbage collection is enabled by default.1476 // specified it as garbage collection is enabled by default.
1470 if (!base.gc_sections) {1477 if (!base.gc_sections) {
src/link/Wasm.zig+4-1
...@@ -75,6 +75,8 @@ initial_memory: ?u64,...@@ -75,6 +75,8 @@ initial_memory: ?u64,
75max_memory: ?u64,75max_memory: ?u64,
76/// When true, will export the function table to the host environment.76/// When true, will export the function table to the host environment.
77export_table: bool,77export_table: bool,
78/// When true, remove maximum size from function table, allowing table to grow.
79growable_table: bool,
78/// Output name of the file80/// Output name of the file
79name: []const u8,81name: []const u8,
80/// List of relocatable files to be linked into the final binary.82/// List of relocatable files to be linked into the final binary.
...@@ -1535,7 +1537,7 @@ pub const TableImport = extern struct {...@@ -1535,7 +1537,7 @@ pub const TableImport = extern struct {
1535 return switch (unpack(r)) {1537 return switch (unpack(r)) {
1536 .unresolved => unreachable,1538 .unresolved => unreachable,
1537 .__indirect_function_table => .{1539 .__indirect_function_table => .{
1538 .flags = .{ .has_max = true, .is_shared = false },1540 .flags = .{ .has_max = !wasm.growable_table, .is_shared = false },
1539 .min = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),1541 .min = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),
1540 .max = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),1542 .max = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),
1541 },1543 },
...@@ -3381,6 +3383,7 @@ pub fn createEmpty(...@@ -3381,6 +3383,7 @@ pub fn createEmpty(
3381 .string_table = .empty,3383 .string_table = .empty,
3382 .string_bytes = .empty,3384 .string_bytes = .empty,
3383 .export_table = options.export_table,3385 .export_table = options.export_table,
3386 .growable_table = options.growable_table,
3384 .import_symbols = options.import_symbols,3387 .import_symbols = options.import_symbols,
3385 .export_symbol_names = options.export_symbol_names,3388 .export_symbol_names = options.export_symbol_names,
3386 .global_base = options.global_base,3389 .global_base = options.global_base,
src/main.zig+7
...@@ -751,6 +751,7 @@ const usage_build_generic =...@@ -751,6 +751,7 @@ const usage_build_generic =
751 \\ --import-symbols (WebAssembly) import missing symbols from the host environment751 \\ --import-symbols (WebAssembly) import missing symbols from the host environment
752 \\ --import-table (WebAssembly) import function table from the host environment752 \\ --import-table (WebAssembly) import function table from the host environment
753 \\ --export-table (WebAssembly) export function table to the host environment753 \\ --export-table (WebAssembly) export function table to the host environment
754 \\ --growable-table (WebAssembly) remove maximum size from function table, allowing table to grow
754 \\ --initial-memory=[bytes] (WebAssembly) initial size of the linear memory755 \\ --initial-memory=[bytes] (WebAssembly) initial size of the linear memory
755 \\ --max-memory=[bytes] (WebAssembly) maximum size of the linear memory756 \\ --max-memory=[bytes] (WebAssembly) maximum size of the linear memory
756 \\ --shared-memory (WebAssembly) use shared linear memory757 \\ --shared-memory (WebAssembly) use shared linear memory
...@@ -985,6 +986,7 @@ fn buildOutputType(...@@ -985,6 +986,7 @@ fn buildOutputType(
985 var linker_import_symbols: bool = false;986 var linker_import_symbols: bool = false;
986 var linker_import_table: bool = false;987 var linker_import_table: bool = false;
987 var linker_export_table: bool = false;988 var linker_export_table: bool = false;
989 var linker_growable_table: bool = false;
988 var linker_initial_memory: ?u64 = null;990 var linker_initial_memory: ?u64 = null;
989 var linker_max_memory: ?u64 = null;991 var linker_max_memory: ?u64 = null;
990 var linker_global_base: ?u64 = null;992 var linker_global_base: ?u64 = null;
...@@ -1764,6 +1766,8 @@ fn buildOutputType(...@@ -1764,6 +1766,8 @@ fn buildOutputType(
1764 linker_import_table = true;1766 linker_import_table = true;
1765 } else if (mem.eql(u8, arg, "--export-table")) {1767 } else if (mem.eql(u8, arg, "--export-table")) {
1766 linker_export_table = true;1768 linker_export_table = true;
1769 } else if (mem.eql(u8, arg, "--growable-table")) {
1770 linker_growable_table = true;
1767 } else if (prefixedIntArg(arg, "--initial-memory=")) |int| {1771 } else if (prefixedIntArg(arg, "--initial-memory=")) |int| {
1768 linker_initial_memory = int;1772 linker_initial_memory = int;
1769 } else if (prefixedIntArg(arg, "--max-memory=")) |int| {1773 } else if (prefixedIntArg(arg, "--max-memory=")) |int| {
...@@ -2712,6 +2716,8 @@ fn buildOutputType(...@@ -2712,6 +2716,8 @@ fn buildOutputType(
2712 linker_import_table = true;2716 linker_import_table = true;
2713 } else if (mem.eql(u8, arg, "--export-table")) {2717 } else if (mem.eql(u8, arg, "--export-table")) {
2714 linker_export_table = true;2718 linker_export_table = true;
2719 } else if (mem.eql(u8, arg, "--growable-table")) {
2720 linker_growable_table = true;
2715 } else if (mem.eql(u8, arg, "--no-entry")) {2721 } else if (mem.eql(u8, arg, "--no-entry")) {
2716 entry = .disabled;2722 entry = .disabled;
2717 } else if (mem.eql(u8, arg, "--initial-memory")) {2723 } else if (mem.eql(u8, arg, "--initial-memory")) {
...@@ -3674,6 +3680,7 @@ fn buildOutputType(...@@ -3674,6 +3680,7 @@ fn buildOutputType(
3674 .linker_import_symbols = linker_import_symbols,3680 .linker_import_symbols = linker_import_symbols,
3675 .linker_import_table = linker_import_table,3681 .linker_import_table = linker_import_table,
3676 .linker_export_table = linker_export_table,3682 .linker_export_table = linker_export_table,
3683 .linker_growable_table = linker_growable_table,
3677 .linker_initial_memory = linker_initial_memory,3684 .linker_initial_memory = linker_initial_memory,
3678 .linker_max_memory = linker_max_memory,3685 .linker_max_memory = linker_max_memory,
3679 .linker_print_gc_sections = linker_print_gc_sections,3686 .linker_print_gc_sections = linker_print_gc_sections,