mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
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:
parent
4f72ac265a
commit
8627858bbc
@ -2355,7 +2355,7 @@ fn lowerDeclRefValue(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index)
|
|||||||
|
|
||||||
const module = self.bin_file.base.options.module.?;
|
const module = self.bin_file.base.options.module.?;
|
||||||
const decl = module.declPtr(decl_index);
|
const decl = module.declPtr(decl_index);
|
||||||
if (!decl.ty.hasRuntimeBitsIgnoreComptime()) {
|
if (decl.ty.zigTypeTag() != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime()) {
|
||||||
return WValue{ .imm32 = 0xaaaaaaaa };
|
return WValue{ .imm32 = 0xaaaaaaaa };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,12 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
|
|||||||
.build_modes = true,
|
.build_modes = true,
|
||||||
.requires_stage2 = 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 {
|
fn addMachOCases(cases: *tests.StandaloneContext) void {
|
||||||
|
|||||||
17
test/link/wasm/extern/build.zig
vendored
Normal file
17
test/link/wasm/extern/build.zig
vendored
Normal 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
1
test/link/wasm/extern/foo.c
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
int foo = 30;
|
||||||
8
test/link/wasm/extern/main.zig
vendored
Normal file
8
test/link/wasm/extern/main.zig
vendored
Normal 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 {};
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user