aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-02-08 23:51:01 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-02-08 23:51:30 +0100
commit738853459062ccfa9fdea7434b7746e6fe172e3a (patch)
tree8373bc0332daa9638db22fe27aa77f244b65c182
parent3bfda3d791c5315712f4c4c2fd0e83c8518d089a (diff)
downloadzig-738853459062ccfa9fdea7434b7746e6fe172e3a.tar.gz
zig-738853459062ccfa9fdea7434b7746e6fe172e3a.zip
test/link/macho: more self-hosted tests
-rw-r--r--test/link/macho.zig51
1 files changed, 43 insertions, 8 deletions
diff --git a/test/link/macho.zig b/test/link/macho.zig
index 58a391daae..9bd34f18cf 100644
--- a/test/link/macho.zig
+++ b/test/link/macho.zig
@@ -16,7 +16,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
});
// Exercise linker with self-hosted backend (no LLVM)
+ macho_step.dependOn(testEmptyZig(b, .{ .use_llvm = false, .target = x86_64_target }));
macho_step.dependOn(testHelloZig(b, .{ .use_llvm = false, .target = x86_64_target }));
+ macho_step.dependOn(testLinkingStaticLib(b, .{ .use_llvm = false, .target = x86_64_target }));
+ macho_step.dependOn(testReexportsZig(b, .{ .use_llvm = false, .target = x86_64_target }));
macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .target = x86_64_target }));
// Exercise linker with LLVM backend
@@ -29,6 +32,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
macho_step.dependOn(testHelloZig(b, .{ .target = default_target }));
macho_step.dependOn(testLargeBss(b, .{ .target = default_target }));
macho_step.dependOn(testLayout(b, .{ .target = default_target }));
+ macho_step.dependOn(testLinkingStaticLib(b, .{ .target = default_target }));
macho_step.dependOn(testLinksection(b, .{ .target = default_target }));
macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target }));
macho_step.dependOn(testNoDeadStrip(b, .{ .target = default_target }));
@@ -839,6 +843,44 @@ fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
return test_step;
}
+fn testLinkingStaticLib(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "linking-static-lib", opts);
+
+ const obj = addObject(b, opts, .{
+ .name = "bobj",
+ .zig_source_bytes = "export var bar: i32 = -42;",
+ });
+
+ const lib = addStaticLibrary(b, opts, .{
+ .name = "alib",
+ .zig_source_bytes =
+ \\export fn foo() i32 {
+ \\ return 42;
+ \\}
+ ,
+ });
+ lib.addObject(obj);
+
+ const exe = addExecutable(b, opts, .{
+ .name = "testlib",
+ .zig_source_bytes =
+ \\const std = @import("std");
+ \\extern fn foo() i32;
+ \\extern var bar: i32;
+ \\pub fn main() void {
+ \\ std.debug.print("{d}\n", .{foo() + bar});
+ \\}
+ ,
+ });
+ exe.linkLibrary(lib);
+
+ const run = addRunArtifact(exe);
+ run.expectStdErrEqual("0\n");
+ test_step.dependOn(&run.step);
+
+ return test_step;
+}
+
fn testLinksection(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "macho-linksection", opts);
@@ -1239,14 +1281,7 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step {
const run = addRunArtifact(exe);
run.addCheck(.{ .expect_stderr_match = b.dupe("incrFoo=1") });
run.addCheck(.{ .expect_stderr_match = b.dupe("decrFoo=0") });
- if (opts.use_llvm) {
- // TODO: enable this once self-hosted can print panics and stack traces
- run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
- }
- if (builtin.os.tag == .macos) {
- const signal: u32 = if (opts.use_llvm) std.os.darwin.SIG.ABRT else std.os.darwin.SIG.TRAP;
- run.addCheck(.{ .expect_term = .{ .Signal = signal } });
- }
+ run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
test_step.dependOn(&run.step);
return test_step;