commit 5423778f6f9d1ec424bf74d40c16c433f20681b2 (tree)
parent 7b2cbcf0fe6dcaea7ee108c13422f6d00ed4bc8e
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Sun, 15 Oct 2023 15:38:32 +0200
elf: add self-hosted tests
Diffstat:
| M | test/link/elf.zig | | | 68 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
1 file changed, 67 insertions(+), 1 deletion(-)
diff --git a/test/link/elf.zig b/test/link/elf.zig
@@ -18,7 +18,9 @@ pub fn build(b: *Build) void {
};
// Exercise linker with self-hosted backend (no LLVM)
- // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
+ elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
+ elf_step.dependOn(testImportingDataDynamic(b, .{ .use_llvm = false, .target = glibc_target }));
+ elf_step.dependOn(testImportingDataStatic(b, .{ .use_llvm = false, .target = musl_target }));
// Exercise linker with LLVM backend
// musl tests
@@ -1223,6 +1225,70 @@ fn testImageBase(b: *Build, opts: Options) *Step {
return test_step;
}
+fn testImportingDataDynamic(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "importing-data-dynamic", opts);
+
+ const dso = addSharedLibrary(b, "a", .{
+ .target = opts.target,
+ .optimize = opts.optimize,
+ .use_llvm = true,
+ });
+ addCSourceBytes(dso, "int foo = 42;", &.{});
+
+ const main = addExecutable(b, "main", opts);
+ addZigSourceBytes(main,
+ \\extern var foo: i32;
+ \\pub fn main() void {
+ \\ @import("std").debug.print("{d}\n", .{foo});
+ \\}
+ );
+ main.pie = true;
+ main.strip = true; // TODO temp hack
+ main.linkLibrary(dso);
+ main.linkLibC();
+
+ const run = addRunArtifact(main);
+ run.expectStdErrEqual("42\n");
+ test_step.dependOn(&run.step);
+
+ return test_step;
+}
+
+fn testImportingDataStatic(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "importing-data-static", opts);
+
+ const obj = addObject(b, "a", .{
+ .target = opts.target,
+ .optimize = opts.optimize,
+ .use_llvm = true,
+ });
+ addCSourceBytes(obj, "int foo = 42;", &.{});
+
+ const lib = addStaticLibrary(b, "a", .{
+ .target = opts.target,
+ .optimize = opts.optimize,
+ .use_llvm = true,
+ });
+ lib.addObject(obj);
+
+ const main = addExecutable(b, "main", opts);
+ addZigSourceBytes(main,
+ \\extern var foo: i32;
+ \\pub fn main() void {
+ \\ @import("std").debug.print("{d}\n", .{foo});
+ \\}
+ );
+ main.strip = true; // TODO temp hack
+ main.linkLibrary(lib);
+ main.linkLibC();
+
+ const run = addRunArtifact(main);
+ run.expectStdErrEqual("42\n");
+ test_step.dependOn(&run.step);
+
+ return test_step;
+}
+
fn testInitArrayOrder(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "init-array-order", opts);