mirror of
https://github.com/ziglang/zig.git
synced 2025-12-21 21:53:08 +00:00
wasm linker: change rules about symbol visibility
export by default means export, as expected. if you want hidden visibility then use hidden visibility.
This commit is contained in:
parent
dcb4134835
commit
744bb5d16a
@ -3502,7 +3502,7 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex, override_export: bool) link
|
|||||||
|
|
||||||
if (!is_obj and (override_export or function.flags.isExported(rdynamic))) {
|
if (!is_obj and (override_export or function.flags.isExported(rdynamic))) {
|
||||||
const symbol_name = function.name.unwrap().?;
|
const symbol_name = function.name.unwrap().?;
|
||||||
if (function.flags.visibility_hidden) {
|
if (!override_export and function.flags.visibility_hidden) {
|
||||||
try wasm.hidden_function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
|
try wasm.hidden_function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
|
||||||
} else {
|
} else {
|
||||||
try wasm.function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
|
try wasm.function_exports.put(gpa, symbol_name, @enumFromInt(gop.index));
|
||||||
|
|||||||
@ -210,9 +210,8 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
|
|||||||
const function_index = Wasm.FunctionIndex.fromIpNav(wasm, nav_export.nav_index).?;
|
const function_index = Wasm.FunctionIndex.fromIpNav(wasm, nav_export.nav_index).?;
|
||||||
const explicit = f.missing_exports.swapRemove(nav_export.name);
|
const explicit = f.missing_exports.swapRemove(nav_export.name);
|
||||||
const is_hidden = !explicit and switch (export_index.ptr(zcu).opts.visibility) {
|
const is_hidden = !explicit and switch (export_index.ptr(zcu).opts.visibility) {
|
||||||
.protected => false,
|
|
||||||
.hidden => true,
|
.hidden => true,
|
||||||
.default => !comp.config.rdynamic,
|
.default, .protected => false,
|
||||||
};
|
};
|
||||||
if (is_hidden) {
|
if (is_hidden) {
|
||||||
try wasm.hidden_function_exports.put(gpa, nav_export.name, function_index);
|
try wasm.hidden_function_exports.put(gpa, nav_export.name, function_index);
|
||||||
|
|||||||
@ -11,7 +11,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
|
|||||||
const no_export = b.addExecutable(.{
|
const no_export = b.addExecutable(.{
|
||||||
.name = "no-export",
|
.name = "no-export",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path("main.zig"),
|
.root_source_file = b.path("main-hidden.zig"),
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
||||||
}),
|
}),
|
||||||
@ -36,7 +36,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
|
|||||||
const force_export = b.addExecutable(.{
|
const force_export = b.addExecutable(.{
|
||||||
.name = "force",
|
.name = "force",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path("main.zig"),
|
.root_source_file = b.path("main-hidden.zig"),
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
||||||
}),
|
}),
|
||||||
|
|||||||
4
test/link/wasm/export/main-hidden.zig
Normal file
4
test/link/wasm/export/main-hidden.zig
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn foo() callconv(.c) void {}
|
||||||
|
comptime {
|
||||||
|
@export(&foo, .{ .name = "foo", .visibility = .hidden });
|
||||||
|
}
|
||||||
@ -40,7 +40,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
|
|||||||
|
|
||||||
check_export.checkInHeaders();
|
check_export.checkInHeaders();
|
||||||
check_export.checkExact("Section export");
|
check_export.checkExact("Section export");
|
||||||
check_export.checkExact("entries 2");
|
check_export.checkExact("entries 3");
|
||||||
check_export.checkExact("name __indirect_function_table"); // as per linker specification
|
check_export.checkExact("name __indirect_function_table"); // as per linker specification
|
||||||
check_export.checkExact("kind table");
|
check_export.checkExact("kind table");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user