Skip to content

Commit b7656de

Browse files
a-khabarovchrisirhc
authored andcommitted
test: check that zig cc passes -l/-L like Clang/GCC for ELF
This test follows the example from #19699.
1 parent 867c6e7 commit b7656de

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/link/elf.zig

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ 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 }));
86+
elf_step.dependOn(testLibraryPathsCompatibility(b, .{ .target = gnu_target, .use_lld = false }));
8587
// https://github.com/ziglang/zig/issues/17430
8688
// elf_step.dependOn(testCanonicalPlt(b, .{ .target = gnu_target }));
8789
elf_step.dependOn(testCommentString(b, .{ .target = gnu_target }));
@@ -309,6 +311,53 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {
309311
return test_step;
310312
}
311313

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

0 commit comments

Comments
 (0)