authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-26 17:29:43+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-30 18:32:08+02:00
log8627858bbc2fee848e2f3e3ca64dc944f39591e5
treeb4281f9734c65855a9a3f7eb50f1b44a0ef23088
parent4f72ac265acac682541f170a1189a06350009431
signaturelock-open Commit is signed but in an unrecognized format.

test/link: add test for extern resolution

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,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index)
23552355
2356 const module = self.bin_file.base.options.module.?;2356 const module = self.bin_file.base.options.module.?;
2357 const decl = module.declPtr(decl_index);2357 const decl = module.declPtr(decl_index);
2358 if (!decl.ty.hasRuntimeBitsIgnoreComptime()) {2358 if (decl.ty.zigTypeTag() != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime()) {
2359 return WValue{ .imm32 = 0xaaaaaaaa };2359 return WValue{ .imm32 = 0xaaaaaaaa };
2360 }2360 }
23612361
test/link.zig+6
...@@ -52,6 +52,12 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {...@@ -52,6 +52,12 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
52 .build_modes = true,52 .build_modes = true,
53 .requires_stage2 = true,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}
5662
57fn addMachOCases(cases: *tests.StandaloneContext) void {63fn addMachOCases(cases: *tests.StandaloneContext) void {
test/link/wasm/extern/build.zig created+17
...@@ -0,0 +1,17 @@
1const std = @import("std");
2
3pub 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 @@
1int foo = 30;
test/link/wasm/extern/main.zig created+8
...@@ -0,0 +1,8 @@
1const std = @import("std");
2
3extern const foo: u32;
4
5pub fn main() void {
6 const std_out = std.io.getStdOut();
7 std_out.writer().print("Result: {d}", .{foo}) catch {};
8}