From c9c210a4e74986a2bd1d0576d22ac9458d523d68 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 24 Oct 2023 22:31:25 +0200 Subject: [PATCH] elf: test path errors in ld script parsing --- test/link/elf.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/link/elf.zig b/test/link/elf.zig index fc3581a694..50f6cc07ec 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -76,6 +76,7 @@ pub fn build(b: *Build) void { elf_step.dependOn(testLargeBss(b, .{ .target = glibc_target })); elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target })); elf_step.dependOn(testLdScript(b, .{ .target = glibc_target })); + elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target })); // https://github.com/ziglang/zig/issues/17451 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target })); elf_step.dependOn(testPie(b, .{ .target = glibc_target })); @@ -1602,6 +1603,27 @@ fn testLdScript(b: *Build, opts: Options) *Step { return test_step; } +fn testLdScriptPathErrors(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "ld-script-path-errors", opts); + + const scripts = WriteFile.create(b); + _ = scripts.add("liba.so", "INPUT(libfoo.so)"); + + const exe = addExecutable(b, "main", opts); + addCSourceBytes(exe, "int main() { return 0; }", &.{}); + exe.linkSystemLibrary2("a", .{}); + exe.addLibraryPath(scripts.getDirectory()); + exe.linkLibC(); + + expectLinkErrors(exe, test_step, &.{ + "error: missing library dependency: GNU ld script '/?/liba.so' requires 'libfoo.so', but file not found", + "note: tried libfoo.so", + "note: tried /?/libfoo.so", + }); + + return test_step; +} + fn testLinkingC(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "linking-c", opts);