authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-11 17:50:17-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:36-08:00
logfbdcb2289b3fed28792474579625a977feca0ed1
tree0d1a71aecb870f00948a211f8bee5412e68191ec
parent0dd0ebb6e2b9030b30a4333b3e79b88500fa6aff

wasm linker: don't pretend it's possible to export data symbols


3 files changed, 32 insertions(+), 10 deletions(-)

src/link/Wasm/Flush.zig+7-6
......@@ -154,14 +154,15 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
154154 if (nav_export.name.toOptional() == entry_name)
155155 wasm.entry_resolution = .fromIpNav(wasm, nav_export.nav_index);
156156 } else {
157 try wasm.global_exports.append(gpa, .{
158 .name = nav_export.name,
159 .global_index = Wasm.GlobalIndex.fromIpNav(wasm, nav_export.nav_index).?,
160 });
157 // This is a data export because Zcu currently has no way to
158 // export wasm globals.
161159 _ = f.missing_exports.swapRemove(nav_export.name);
162160 _ = f.data_imports.swapRemove(nav_export.name);
163 // `f.global_imports` is ignored because Zcu has no way to
164 // export wasm globals.
161 if (!is_obj) {
162 diags.addError("unable to export data symbol '{s}'; not emitting a relocatable", .{
163 nav_export.name.slice(wasm),
164 });
165 }
165166 }
166167 }
167168
test/behavior.zig+10-3
......@@ -31,8 +31,6 @@ test {
3131 _ = @import("behavior/error.zig");
3232 _ = @import("behavior/eval.zig");
3333 _ = @import("behavior/export_builtin.zig");
34 _ = @import("behavior/export_self_referential_type_info.zig");
35 _ = @import("behavior/extern.zig");
3634 _ = @import("behavior/field_parent_ptr.zig");
3735 _ = @import("behavior/floatop.zig");
3836 _ = @import("behavior/fn.zig");
......@@ -45,7 +43,6 @@ test {
4543 _ = @import("behavior/hasfield.zig");
4644 _ = @import("behavior/if.zig");
4745 _ = @import("behavior/import.zig");
48 _ = @import("behavior/import_c_keywords.zig");
4946 _ = @import("behavior/incomplete_struct_param_tld.zig");
5047 _ = @import("behavior/inline_switch.zig");
5148 _ = @import("behavior/int128.zig");
......@@ -127,6 +124,16 @@ test {
127124 {
128125 _ = @import("behavior/export_keyword.zig");
129126 }
127
128 if (!builtin.cpu.arch.isWasm()) {
129 // Due to lack of import/export of global support
130 // (https://github.com/ziglang/zig/issues/4866), these tests correctly
131 // cause linker errors, since a data symbol cannot be exported when
132 // building an executable.
133 _ = @import("behavior/export_self_referential_type_info.zig");
134 _ = @import("behavior/extern.zig");
135 _ = @import("behavior/import_c_keywords.zig");
136 }
130137}
131138
132139// This bug only repros in the root file
test/behavior/export_builtin.zig+15-1
......@@ -6,6 +6,11 @@ test "exporting enum value" {
66 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
77 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
88
9 if (builtin.cpu.arch.isWasm()) {
10 // https://github.com/ziglang/zig/issues/4866
11 return error.SkipZigTest;
12 }
13
914 const S = struct {
1015 const E = enum(c_int) { one, two };
1116 const e: E = .two;
......@@ -33,6 +38,11 @@ test "exporting using namespace access" {
3338 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
3439 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
3540
41 if (builtin.cpu.arch.isWasm()) {
42 // https://github.com/ziglang/zig/issues/4866
43 return error.SkipZigTest;
44 }
45
3646 const S = struct {
3747 const Inner = struct {
3848 const x: u32 = 5;
......@@ -46,7 +56,6 @@ test "exporting using namespace access" {
4656}
4757
4858test "exporting comptime-known value" {
49 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
5059 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
5160 if (builtin.zig_backend == .stage2_x86_64 and
5261 (builtin.target.ofmt != .elf and
......@@ -56,6 +65,11 @@ test "exporting comptime-known value" {
5665 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
5766 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
5867
68 if (builtin.cpu.arch.isWasm()) {
69 // https://github.com/ziglang/zig/issues/4866
70 return error.SkipZigTest;
71 }
72
5973 const x: u32 = 10;
6074 @export(&x, .{ .name = "exporting_comptime_known_value_foo" });
6175 const S = struct {