Commit c9c210a4e7

Jakub Konka <kubkon@jakubkonka.com>
2023-10-24 22:31:25
elf: test path errors in ld script parsing
1 parent 403e539
Changed files (1)
test
link
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);