diff options
| author | Carl Åstholm <carl@astholm.se> | 2024-01-08 18:36:42 +0100 |
|---|---|---|
| committer | Carl Åstholm <carl@astholm.se> | 2024-01-09 17:26:10 +0100 |
| commit | 3cd646869b1791b8833134294d3f415cb6fddcf7 (patch) | |
| tree | 05b34adb494618881a6b2bb428de7346d531eb93 /test | |
| parent | 9bb643031864c8c3c2d4ac52aecb175283e335e3 (diff) | |
| download | zig-3cd646869b1791b8833134294d3f415cb6fddcf7.tar.gz zig-3cd646869b1791b8833134294d3f415cb6fddcf7.zip | |
Add tests for `--undefined-version`
Diffstat (limited to 'test')
| -rw-r--r-- | test/link/elf.zig | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index dafbf867ed..92aba4f352 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -94,6 +94,8 @@ pub fn testAll(b: *Build) *Step { elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target })); elf_step.dependOn(testLdScript(b, .{ .target = glibc_target })); elf_step.dependOn(testLdScriptPathError(b, .{ .target = glibc_target })); + elf_step.dependOn(testLdScriptAllowUndefinedVersion(b, .{ .target = glibc_target, .use_lld = true })); + elf_step.dependOn(testLdScriptDisallowUndefinedVersion(b, .{ .target = glibc_target, .use_lld = true })); elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target })); // https://github.com/ziglang/zig/issues/17451 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target })); @@ -2008,6 +2010,67 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { return test_step; } +fn testLdScriptAllowUndefinedVersion(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "ld-script-allow-undefined-version", opts); + + const so = addSharedLibrary(b, opts, .{ + .name = "add", + .zig_source_bytes = + \\export fn add(a: i32, b: i32) i32 { + \\ return a + b; + \\} + , + }); + const ld = b.addWriteFiles().add("add.ld", "VERSION { ADD_1.0 { global: add; sub; local: *; }; }"); + so.setLinkerScript(ld); + so.linker_allow_undefined_version = true; + + const exe = addExecutable(b, opts, .{ + .name = "main", + .zig_source_bytes = + \\const std = @import("std"); + \\extern fn add(a: i32, b: i32) i32; + \\pub fn main() void { + \\ std.debug.print("{d}\n", .{add(1, 2)}); + \\} + , + }); + exe.linkLibrary(so); + exe.linkLibC(); + + const run = addRunArtifact(exe); + run.expectStdErrEqual("3\n"); + test_step.dependOn(&run.step); + + return test_step; +} + +fn testLdScriptDisallowUndefinedVersion(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "ld-script-disallow-undefined-version", opts); + + const so = addSharedLibrary(b, opts, .{ + .name = "add", + .zig_source_bytes = + \\export fn add(a: i32, b: i32) i32 { + \\ return a + b; + \\} + , + }); + const ld = b.addWriteFiles().add("add.ld", "VERSION { ADD_1.0 { global: add; sub; local: *; }; }"); + so.setLinkerScript(ld); + so.linker_allow_undefined_version = false; + + expectLinkErrors( + so, + test_step, + .{ + .contains = "error: ld.lld: version script assignment of 'ADD_1.0' to symbol 'sub' failed: symbol not defined", + }, + ); + + return test_step; +} + fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts); |
