authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-15 07:38:29+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
logf9fbd6302f0f4d1ef5ed1c1d2fc63eabb313978d
tree7e3633121d8c70db2e4206e545fa6ea58e3a4467
parent234aa86802ececa8450d84e4cb16da7ce8a5cf79

macho: test TLS in Zig with x86_64 backend


1 files changed, 28 insertions(+), 0 deletions(-)

test/link/macho.zig+28
...@@ -25,6 +25,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -25,6 +25,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
25 macho_step.dependOn(testLinkingStaticLib(b, .{ .use_llvm = false, .target = x86_64_target }));25 macho_step.dependOn(testLinkingStaticLib(b, .{ .use_llvm = false, .target = x86_64_target }));
26 macho_step.dependOn(testReexportsZig(b, .{ .use_llvm = false, .target = x86_64_target }));26 macho_step.dependOn(testReexportsZig(b, .{ .use_llvm = false, .target = x86_64_target }));
27 macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .target = x86_64_target }));27 macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .target = x86_64_target }));
28 macho_step.dependOn(testTlsZig(b, .{ .use_llvm = false, .target = x86_64_target }));
2829
29 // Exercise linker with LLVM backend30 // Exercise linker with LLVM backend
30 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));31 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
...@@ -56,6 +57,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -56,6 +57,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
56 macho_step.dependOn(testTentative(b, .{ .target = default_target }));57 macho_step.dependOn(testTentative(b, .{ .target = default_target }));
57 macho_step.dependOn(testThunks(b, .{ .target = aarch64_target }));58 macho_step.dependOn(testThunks(b, .{ .target = aarch64_target }));
58 macho_step.dependOn(testTlsLargeTbss(b, .{ .target = default_target }));59 macho_step.dependOn(testTlsLargeTbss(b, .{ .target = default_target }));
60 macho_step.dependOn(testTlsZig(b, .{ .target = default_target }));
59 macho_step.dependOn(testUndefinedFlag(b, .{ .target = default_target }));61 macho_step.dependOn(testUndefinedFlag(b, .{ .target = default_target }));
60 macho_step.dependOn(testUnwindInfo(b, .{ .target = default_target }));62 macho_step.dependOn(testUnwindInfo(b, .{ .target = default_target }));
61 macho_step.dependOn(testUnwindInfoNoSubsectionsX64(b, .{ .target = x86_64_target }));63 macho_step.dependOn(testUnwindInfoNoSubsectionsX64(b, .{ .target = x86_64_target }));
...@@ -2274,6 +2276,32 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {...@@ -2274,6 +2276,32 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
2274 return test_step;2276 return test_step;
2275}2277}
22762278
2279fn testTlsZig(b: *Build, opts: Options) *Step {
2280 const test_step = addTestStep(b, "tls-zig", opts);
2281
2282 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
2283 \\const std = @import("std");
2284 \\threadlocal var x: i32 = 0;
2285 \\threadlocal var y: i32 = -1;
2286 \\pub fn main() void {
2287 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2288 \\ x -= 1;
2289 \\ y += 1;
2290 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2291 \\}
2292 });
2293
2294 const run = addRunArtifact(exe);
2295 run.expectStdOutEqual(
2296 \\0 -1
2297 \\-1 0
2298 \\
2299 );
2300 test_step.dependOn(&run.step);
2301
2302 return test_step;
2303}
2304
2277fn testTwoLevelNamespace(b: *Build, opts: Options) *Step {2305fn testTwoLevelNamespace(b: *Build, opts: Options) *Step {
2278 const test_step = addTestStep(b, "two-level-namespace", opts);2306 const test_step = addTestStep(b, "two-level-namespace", opts);
22792307