test/link: add test for extern resolution

Adds a linker tests to verify extern/undefined symbols
representing non-functions are being resolved correctly.
This commit is contained in:
Luuk de Gram 2022-08-26 17:29:43 +02:00
parent 4f72ac265a
commit 8627858bbc
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
5 changed files with 33 additions and 1 deletions

View File

@ -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 };
}

View File

@ -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 {

17
test/link/wasm/extern/build.zig vendored Normal file
View File

@ -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);
}

1
test/link/wasm/extern/foo.c vendored Normal file
View File

@ -0,0 +1 @@
int foo = 30;

8
test/link/wasm/extern/main.zig vendored Normal file
View File

@ -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 {};
}