authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 18:31:44-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 18:31:44-08:00
log744bb5d16a1acdabb7c078f7a1a30eefeac733cc
treeba6e043f65776159680f703dd48b63da7e94a37e
parentdcb4134835e0c0bb0c130731efec741b41aba522

wasm linker: change rules about symbol visibility

export by default means export, as expected. if you want hidden visibility then use hidden visibility.

5 files changed, 9 insertions(+), 6 deletions(-)

src/link/Wasm.zig+1-1
......@@ -3502,7 +3502,7 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex, override_export: bool) link
35023502
35033503 if (!is_obj and (override_export or function.flags.isExported(rdynamic))) {
35043504 const symbol_name = function.name.unwrap().?;
3505 if (function.flags.visibility_hidden) {
3505 if (!override_export and function.flags.visibility_hidden) {
35063506 try wasm.hidden_function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
35073507 } else {
35083508 try wasm.function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
src/link/Wasm/Flush.zig+1-2
......@@ -210,9 +210,8 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
210210 const function_index = Wasm.FunctionIndex.fromIpNav(wasm, nav_export.nav_index).?;
211211 const explicit = f.missing_exports.swapRemove(nav_export.name);
212212 const is_hidden = !explicit and switch (export_index.ptr(zcu).opts.visibility) {
213 .protected => false,
214213 .hidden => true,
215 .default => !comp.config.rdynamic,
214 .default, .protected => false,
216215 };
217216 if (is_hidden) {
218217 try wasm.hidden_function_exports.put(gpa, nav_export.name, function_index);
test/link/wasm/export/build.zig+2-2
......@@ -11,7 +11,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1111 const no_export = b.addExecutable(.{
1212 .name = "no-export",
1313 .root_module = b.createModule(.{
14 .root_source_file = b.path("main.zig"),
14 .root_source_file = b.path("main-hidden.zig"),
1515 .optimize = optimize,
1616 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
1717 }),
......@@ -36,7 +36,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3636 const force_export = b.addExecutable(.{
3737 .name = "force",
3838 .root_module = b.createModule(.{
39 .root_source_file = b.path("main.zig"),
39 .root_source_file = b.path("main-hidden.zig"),
4040 .optimize = optimize,
4141 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
4242 }),
test/link/wasm/export/main-hidden.zig created+4
......@@ -0,0 +1,4 @@
1fn foo() callconv(.c) void {}
2comptime {
3 @export(&foo, .{ .name = "foo", .visibility = .hidden });
4}
test/link/wasm/function-table/build.zig+1-1
......@@ -40,7 +40,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4040
4141 check_export.checkInHeaders();
4242 check_export.checkExact("Section export");
43 check_export.checkExact("entries 2");
43 check_export.checkExact("entries 3");
4444 check_export.checkExact("name __indirect_function_table"); // as per linker specification
4545 check_export.checkExact("kind table");
4646