Commit 8627858bbc
Changed files (5)
src
arch
wasm
src/arch/wasm/CodeGen.zig
@@ -2355,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index)
const module = self.bin_file.base.options.module.?;
const decl = module.declPtr(decl_index);
- if (!decl.ty.hasRuntimeBitsIgnoreComptime()) {
+ if (decl.ty.zigTypeTag() != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime()) {
return WValue{ .imm32 = 0xaaaaaaaa };
}
test/link/wasm/extern/build.zig
@@ -0,0 +1,17 @@
+const std = @import("std");
+
+pub fn build(b: *std.build.Builder) void {
+ const mode = b.standardReleaseOptions();
+ const exe = b.addExecutable("extern", "main.zig");
+ exe.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .wasi });
+ exe.setBuildMode(mode);
+ exe.addCSourceFile("foo.c", &.{});
+ exe.use_llvm = false;
+ exe.use_lld = false;
+
+ const run = exe.runEmulatable();
+ run.expectStdOutEqual("Result: 30");
+
+ const test_step = b.step("test", "Run linker test");
+ test_step.dependOn(&run.step);
+}
test/link/wasm/extern/foo.c
@@ -0,0 +1,1 @@
+int foo = 30;
test/link/wasm/extern/main.zig
@@ -0,0 +1,8 @@
+const std = @import("std");
+
+extern const foo: u32;
+
+pub fn main() void {
+ const std_out = std.io.getStdOut();
+ std_out.writer().print("Result: {d}", .{foo}) catch {};
+}
test/link.zig
@@ -52,6 +52,12 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
.build_modes = true,
.requires_stage2 = true,
});
+
+ cases.addBuildFile("test/link/wasm/extern/build.zig", .{
+ .build_modes = true,
+ .requires_stage2 = true,
+ .use_emulation = true,
+ });
}
fn addMachOCases(cases: *tests.StandaloneContext) void {