aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/link/elf.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig
index a16d012b91..93a3642868 100644
--- a/test/link/elf.zig
+++ b/test/link/elf.zig
@@ -21,6 +21,9 @@ pub fn build(b: *Build) void {
.abi = .gnu,
};
+ // Exercise linker in ar mode
+ elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target }));
+
// Exercise linker with self-hosted backend (no LLVM)
elf_step.dependOn(testGcSectionsZig(b, .{ .use_llvm = false, .target = default_target }));
elf_step.dependOn(testLinkingObj(b, .{ .use_llvm = false, .target = default_target }));
@@ -626,6 +629,65 @@ fn testDsoUndef(b: *Build, opts: Options) *Step {
return test_step;
}
+fn testEmitStaticLib(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "emit-static-lib", opts);
+
+ const obj1 = addObject(b, "obj1", opts);
+ addCSourceBytes(obj1,
+ \\int foo = 0;
+ \\int bar = 2;
+ \\int fooBar() {
+ \\ return foo + bar;
+ \\}
+ , &.{});
+
+ const obj2 = addObject(b, "obj2", opts);
+ addCSourceBytes(obj2, "int tentative;", &.{"-fcommon"});
+
+ const obj3 = addObject(b, "a_very_long_file_name_so_that_it_ends_up_in_strtab", opts);
+ addZigSourceBytes(obj3,
+ \\fn weakFoo() callconv(.C) usize {
+ \\ return 42;
+ \\}
+ \\export var strongBar: usize = 100;
+ \\comptime {
+ \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak });
+ \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong });
+ \\}
+ );
+
+ const lib = addStaticLibrary(b, "lib", opts);
+ lib.addObject(obj1);
+ lib.addObject(obj2);
+ lib.addObject(obj3);
+
+ const check = lib.checkObject();
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj1.getEmittedBin());
+ check.checkExact("foo");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj1.getEmittedBin());
+ check.checkExact("bar");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj1.getEmittedBin());
+ check.checkExact("fooBar");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj2.getEmittedBin());
+ check.checkExact("tentative");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj3.getEmittedBin());
+ check.checkExact("weakFoo");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj3.getEmittedBin());
+ check.checkExact("strongBar");
+ check.checkInArchiveSymtab();
+ check.checkExactPath("in object", obj3.getEmittedBin());
+ check.checkExact("strongBarAlias");
+ test_step.dependOn(&check.step);
+
+ return test_step;
+}
+
fn testEmptyObject(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "empty-object", opts);