authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-01-08 18:36:42+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-01-09 17:26:10+01:00
log3cd646869b1791b8833134294d3f415cb6fddcf7
tree05b34adb494618881a6b2bb428de7346d531eb93
parent9bb643031864c8c3c2d4ac52aecb175283e335e3

Add tests for `--undefined-version`


1 files changed, 63 insertions(+), 0 deletions(-)

test/link/elf.zig+63
......@@ -94,6 +94,8 @@ pub fn testAll(b: *Build) *Step {
9494 elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));
9595 elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));
9696 elf_step.dependOn(testLdScriptPathError(b, .{ .target = glibc_target }));
97 elf_step.dependOn(testLdScriptAllowUndefinedVersion(b, .{ .target = glibc_target, .use_lld = true }));
98 elf_step.dependOn(testLdScriptDisallowUndefinedVersion(b, .{ .target = glibc_target, .use_lld = true }));
9799 elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target }));
98100 // https://github.com/ziglang/zig/issues/17451
99101 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));
......@@ -2008,6 +2010,67 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step {
20082010 return test_step;
20092011}
20102012
2013fn testLdScriptAllowUndefinedVersion(b: *Build, opts: Options) *Step {
2014 const test_step = addTestStep(b, "ld-script-allow-undefined-version", opts);
2015
2016 const so = addSharedLibrary(b, opts, .{
2017 .name = "add",
2018 .zig_source_bytes =
2019 \\export fn add(a: i32, b: i32) i32 {
2020 \\ return a + b;
2021 \\}
2022 ,
2023 });
2024 const ld = b.addWriteFiles().add("add.ld", "VERSION { ADD_1.0 { global: add; sub; local: *; }; }");
2025 so.setLinkerScript(ld);
2026 so.linker_allow_undefined_version = true;
2027
2028 const exe = addExecutable(b, opts, .{
2029 .name = "main",
2030 .zig_source_bytes =
2031 \\const std = @import("std");
2032 \\extern fn add(a: i32, b: i32) i32;
2033 \\pub fn main() void {
2034 \\ std.debug.print("{d}\n", .{add(1, 2)});
2035 \\}
2036 ,
2037 });
2038 exe.linkLibrary(so);
2039 exe.linkLibC();
2040
2041 const run = addRunArtifact(exe);
2042 run.expectStdErrEqual("3\n");
2043 test_step.dependOn(&run.step);
2044
2045 return test_step;
2046}
2047
2048fn testLdScriptDisallowUndefinedVersion(b: *Build, opts: Options) *Step {
2049 const test_step = addTestStep(b, "ld-script-disallow-undefined-version", opts);
2050
2051 const so = addSharedLibrary(b, opts, .{
2052 .name = "add",
2053 .zig_source_bytes =
2054 \\export fn add(a: i32, b: i32) i32 {
2055 \\ return a + b;
2056 \\}
2057 ,
2058 });
2059 const ld = b.addWriteFiles().add("add.ld", "VERSION { ADD_1.0 { global: add; sub; local: *; }; }");
2060 so.setLinkerScript(ld);
2061 so.linker_allow_undefined_version = false;
2062
2063 expectLinkErrors(
2064 so,
2065 test_step,
2066 .{
2067 .contains = "error: ld.lld: version script assignment of 'ADD_1.0' to symbol 'sub' failed: symbol not defined",
2068 },
2069 );
2070
2071 return test_step;
2072}
2073
20112074fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step {
20122075 const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts);
20132076