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(
728728 try addBool(gpa, zig_args, "--import-symbols", conf_comp.flags.import_symbols);
729729 try addBool(gpa, zig_args, "--import-table", conf_comp.flags.import_table);
730730 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);
731732 try addBool(gpa, zig_args, "--shared-memory", conf_comp.flags.shared_memory);
732733
733734 {
lib/std/Build/Configuration.zig+1-1
......@@ -953,6 +953,7 @@ pub const Step = extern struct {
953953 import_symbols: bool,
954954 import_table: bool,
955955 export_table: bool,
956 growable_table: bool,
956957 shared_memory: bool,
957958 link_eh_frame_hdr: bool,
958959 link_emit_relocs: bool,
......@@ -968,7 +969,6 @@ pub const Step = extern struct {
968969 force_load_objc: bool,
969970 discard_local_symbols: bool,
970971 mingw_unicode_entry_point: bool,
971 _: u1 = 0,
972972 };
973973
974974 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
133133 .import_symbols = c.import_symbols,
134134 .import_table = c.import_table,
135135 .export_table = c.export_table,
136 .growable_table = c.growable_table,
136137 .shared_memory = c.shared_memory,
137138 .link_eh_frame_hdr = c.link_eh_frame_hdr,
138139 .link_emit_relocs = c.link_emit_relocs,
lib/std/Build/Step/Compile.zig+1
......@@ -45,6 +45,7 @@ import_symbols: bool = false,
4545/// (WebAssembly) import function table from the host environment
4646import_table: bool = false,
4747export_table: bool = false,
48growable_table: bool = false,
4849initial_memory: ?u64 = null,
4950max_memory: ?u64 = null,
5051shared_memory: bool = false,
src/Compilation.zig+3
......@@ -1478,6 +1478,7 @@ pub const CreateOptions = struct {
14781478 linker_import_symbols: bool = false,
14791479 linker_import_table: bool = false,
14801480 linker_export_table: bool = false,
1481 linker_growable_table: bool = false,
14811482 linker_initial_memory: ?u64 = null,
14821483 linker_max_memory: ?u64 = null,
14831484 linker_global_base: ?u64 = null,
......@@ -2183,6 +2184,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21832184 .import_symbols = options.linker_import_symbols,
21842185 .import_table = options.linker_import_table,
21852186 .export_table = options.linker_export_table,
2187 .growable_table = options.linker_growable_table,
21862188 .initial_memory = options.linker_initial_memory,
21872189 .max_memory = options.linker_max_memory,
21882190 .global_base = options.linker_global_base,
......@@ -3434,6 +3436,7 @@ fn addNonIncrementalStuffToCacheManifest(
34343436 man.hash.add(opts.import_symbols);
34353437 man.hash.add(opts.import_table);
34363438 man.hash.add(opts.export_table);
3439 man.hash.add(opts.growable_table);
34373440
34383441 // Mach-O specific stuff
34393442 try link.File.MachO.hashAddFrameworks(man, opts.frameworks);
src/link.zig+1
......@@ -444,6 +444,7 @@ pub const File = struct {
444444 import_symbols: bool,
445445 import_table: bool,
446446 export_table: bool,
447 growable_table: bool,
447448 initial_memory: ?u64,
448449 max_memory: ?u64,
449450 object_host_name: ?[]const u8,
src/link/Lld.zig+7
......@@ -166,6 +166,8 @@ const Wasm = struct {
166166 import_table: bool,
167167 /// When true, will export the function table to the host environment.
168168 export_table: bool,
169 /// When true, remove maximum size from function table, allowing table to grow.
170 growable_table: bool,
169171 /// When defined, sets the initial memory size of the memory.
170172 initial_memory: ?u64,
171173 /// When defined, sets the maximum memory size of the memory.
......@@ -190,6 +192,7 @@ const Wasm = struct {
190192 },
191193 .import_table = options.import_table,
192194 .export_table = options.export_table,
195 .growable_table = options.growable_table,
193196 .initial_memory = options.initial_memory,
194197 .max_memory = options.max_memory,
195198 .global_base = options.global_base,
......@@ -1465,6 +1468,10 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
14651468 try argv.append("--export-table");
14661469 }
14671470
1471 if (wasm.growable_table) {
1472 try argv.append("--growable-table");
1473 }
1474
14681475 // For wasm-ld we only need to specify '--no-gc-sections' when the user explicitly
14691476 // specified it as garbage collection is enabled by default.
14701477 if (!base.gc_sections) {
src/link/Wasm.zig+4-1
......@@ -75,6 +75,8 @@ initial_memory: ?u64,
7575max_memory: ?u64,
7676/// When true, will export the function table to the host environment.
7777export_table: bool,
78/// When true, remove maximum size from function table, allowing table to grow.
79growable_table: bool,
7880/// Output name of the file
7981name: []const u8,
8082/// List of relocatable files to be linked into the final binary.
......@@ -1535,7 +1537,7 @@ pub const TableImport = extern struct {
15351537 return switch (unpack(r)) {
15361538 .unresolved => unreachable,
15371539 .__indirect_function_table => .{
1538 .flags = .{ .has_max = true, .is_shared = false },
1540 .flags = .{ .has_max = !wasm.growable_table, .is_shared = false },
15391541 .min = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),
15401542 .max = @intCast(wasm.flush_buffer.indirect_function_table.entries.len + 1),
15411543 },
......@@ -3381,6 +3383,7 @@ pub fn createEmpty(
33813383 .string_table = .empty,
33823384 .string_bytes = .empty,
33833385 .export_table = options.export_table,
3386 .growable_table = options.growable_table,
33843387 .import_symbols = options.import_symbols,
33853388 .export_symbol_names = options.export_symbol_names,
33863389 .global_base = options.global_base,
src/main.zig+7
......@@ -751,6 +751,7 @@ const usage_build_generic =
751751 \\ --import-symbols (WebAssembly) import missing symbols from the host environment
752752 \\ --import-table (WebAssembly) import function table from the host environment
753753 \\ --export-table (WebAssembly) export function table to the host environment
754 \\ --growable-table (WebAssembly) remove maximum size from function table, allowing table to grow
754755 \\ --initial-memory=[bytes] (WebAssembly) initial size of the linear memory
755756 \\ --max-memory=[bytes] (WebAssembly) maximum size of the linear memory
756757 \\ --shared-memory (WebAssembly) use shared linear memory
......@@ -985,6 +986,7 @@ fn buildOutputType(
985986 var linker_import_symbols: bool = false;
986987 var linker_import_table: bool = false;
987988 var linker_export_table: bool = false;
989 var linker_growable_table: bool = false;
988990 var linker_initial_memory: ?u64 = null;
989991 var linker_max_memory: ?u64 = null;
990992 var linker_global_base: ?u64 = null;
......@@ -1764,6 +1766,8 @@ fn buildOutputType(
17641766 linker_import_table = true;
17651767 } else if (mem.eql(u8, arg, "--export-table")) {
17661768 linker_export_table = true;
1769 } else if (mem.eql(u8, arg, "--growable-table")) {
1770 linker_growable_table = true;
17671771 } else if (prefixedIntArg(arg, "--initial-memory=")) |int| {
17681772 linker_initial_memory = int;
17691773 } else if (prefixedIntArg(arg, "--max-memory=")) |int| {
......@@ -2712,6 +2716,8 @@ fn buildOutputType(
27122716 linker_import_table = true;
27132717 } else if (mem.eql(u8, arg, "--export-table")) {
27142718 linker_export_table = true;
2719 } else if (mem.eql(u8, arg, "--growable-table")) {
2720 linker_growable_table = true;
27152721 } else if (mem.eql(u8, arg, "--no-entry")) {
27162722 entry = .disabled;
27172723 } else if (mem.eql(u8, arg, "--initial-memory")) {
......@@ -3674,6 +3680,7 @@ fn buildOutputType(
36743680 .linker_import_symbols = linker_import_symbols,
36753681 .linker_import_table = linker_import_table,
36763682 .linker_export_table = linker_export_table,
3683 .linker_growable_table = linker_growable_table,
36773684 .linker_initial_memory = linker_initial_memory,
36783685 .linker_max_memory = linker_max_memory,
36793686 .linker_print_gc_sections = linker_print_gc_sections,