| author | |
| committer | |
| log | 8627858bbc2fee848e2f3e3ca64dc944f39591e5 |
| tree | b4281f9734c65855a9a3f7eb50f1b44a0ef23088 |
| parent | 4f72ac265acac682541f170a1189a06350009431 |
| signature |
Adds a linker tests to verify extern/undefined symbols
representing non-functions are being resolved correctly.5 files changed, 33 insertions(+), 1 deletions(-)
src/arch/wasm/CodeGen.zig+1-1| ... | ... | @@ -2355,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) |
| 2355 | 2355 | |
| 2356 | 2356 | const module = self.bin_file.base.options.module.?; |
| 2357 | 2357 | const decl = module.declPtr(decl_index); |
| 2358 | if (!decl.ty.hasRuntimeBitsIgnoreComptime()) { | |
| 2358 | if (decl.ty.zigTypeTag() != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime()) { | |
| 2359 | 2359 | return WValue{ .imm32 = 0xaaaaaaaa }; |
| 2360 | 2360 | } |
| 2361 | 2361 |
test/link.zig+6| ... | ... | @@ -52,6 +52,12 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { |
| 52 | 52 | .build_modes = true, |
| 53 | 53 | .requires_stage2 = true, |
| 54 | 54 | }); |
| 55 | ||
| 56 | cases.addBuildFile("test/link/wasm/extern/build.zig", .{ | |
| 57 | .build_modes = true, | |
| 58 | .requires_stage2 = true, | |
| 59 | .use_emulation = true, | |
| 60 | }); | |
| 55 | 61 | } |
| 56 | 62 | |
| 57 | 63 | fn addMachOCases(cases: *tests.StandaloneContext) void { |
test/link/wasm/extern/build.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn build(b: *std.build.Builder) void { | |
| 4 | const mode = b.standardReleaseOptions(); | |
| 5 | const exe = b.addExecutable("extern", "main.zig"); | |
| 6 | exe.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); | |
| 7 | exe.setBuildMode(mode); | |
| 8 | exe.addCSourceFile("foo.c", &.{}); | |
| 9 | exe.use_llvm = false; | |
| 10 | exe.use_lld = false; | |
| 11 | ||
| 12 | const run = exe.runEmulatable(); | |
| 13 | run.expectStdOutEqual("Result: 30"); | |
| 14 | ||
| 15 | const test_step = b.step("test", "Run linker test"); | |
| 16 | test_step.dependOn(&run.step); | |
| 17 | } |
test/link/wasm/extern/foo.c created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | int foo = 30; |
test/link/wasm/extern/main.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | extern const foo: u32; | |
| 4 | ||
| 5 | pub fn main() void { | |
| 6 | const std_out = std.io.getStdOut(); | |
| 7 | std_out.writer().print("Result: {d}", .{foo}) catch {}; | |
| 8 | } |