Skip to content

Commit 14ec9e4

Browse files
committed
test: check that zig cc passes -l/-L like Clang/GCC for ELF
This test follows the example from #19699.
1 parent 5b78bfc commit 14ec9e4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/link/elf.zig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
8282

8383
// glibc tests
8484
elf_step.dependOn(testAsNeeded(b, .{ .target = gnu_target }));
85+
elf_step.dependOn(testLibraryPathsCompatibility(b, .{ .target = gnu_target, .use_lld = true }));
8586
// https://github.com/ziglang/zig/issues/17430
8687
// elf_step.dependOn(testCanonicalPlt(b, .{ .target = gnu_target }));
8788
elf_step.dependOn(testCommentString(b, .{ .target = gnu_target }));
@@ -309,6 +310,53 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {
309310
return test_step;
310311
}
311312

313+
fn testLibraryPathsCompatibility(b: *Build, opts: Options) *Step {
314+
const test_step = addTestStep(b, "library-paths-compatibility", opts);
315+
316+
const main_o = addObject(b, opts, .{
317+
.name = "main",
318+
.c_source_bytes =
319+
\\#include <stdio.h>
320+
\\int foo();
321+
\\int main() {
322+
\\ printf("%d\n", foo());
323+
\\ return 0;
324+
\\}
325+
\\
326+
,
327+
});
328+
main_o.linkLibC();
329+
330+
const libfoo = addSharedLibrary(b, opts, .{ .name = "foo", .soname = .no });
331+
addCSourceBytes(libfoo, "int foo() { return 42; }", &.{});
332+
333+
{
334+
const scripts = WriteFile.create(b);
335+
const path = scripts.addCopyFile(libfoo.getEmittedBin(), "foo/libfoo.so");
336+
337+
const exe = addExecutable(b, opts, .{ .name = "test" });
338+
exe.addObject(main_o);
339+
340+
exe.addLibraryPath(.{ .generated = .{ .file = &scripts.generated_directory, .sub_path = "foo" } });
341+
exe.addRPath(path.dirname());
342+
343+
exe.linkSystemLibrary2("foo", .{ .needed = false });
344+
exe.linkLibC();
345+
346+
const run = addRunArtifact(exe);
347+
run.expectStdOutEqual("42\n");
348+
test_step.dependOn(&run.step);
349+
350+
const check = exe.checkObject();
351+
check.checkInDynamicSection();
352+
check.checkExact("NEEDED libfoo.so");
353+
check.checkNotPresent("NEEDED foo/libfoo.so");
354+
test_step.dependOn(&check.step);
355+
}
356+
357+
return test_step;
358+
}
359+
312360
fn testCanonicalPlt(b: *Build, opts: Options) *Step {
313361
const test_step = addTestStep(b, "canonical-plt", opts);
314362

0 commit comments

Comments
 (0)