| author | |
| committer | |
| log | 49a4b429954826fba3bd9d952ec28a058addf31c |
| tree | 157d28dcda3c3687ae8bffb1e781a62a4eecab2b |
| parent | 9f0e1ab467a2214efb97d340c733fa1da4e708c7 |
5 files changed, 35 insertions(+), 63 deletions(-)
test/link.zig-4| ... | ... | @@ -163,10 +163,6 @@ pub const cases = [_]Case{ |
| 163 | 163 | .build_root = "test/link/macho/tbdv3", |
| 164 | 164 | .import = @import("link/macho/tbdv3/build.zig"), |
| 165 | 165 | }, |
| 166 | .{ | |
| 167 | .build_root = "test/link/macho/tls", | |
| 168 | .import = @import("link/macho/tls/build.zig"), | |
| 169 | }, | |
| 170 | 166 | .{ |
| 171 | 167 | .build_root = "test/link/macho/unwind_info", |
| 172 | 168 | .import = @import("link/macho/unwind_info/build.zig"), |
test/link/macho.zig+35| ... | ... | @@ -34,6 +34,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 34 | 34 | if (build_opts.has_symlinks_windows) { |
| 35 | 35 | macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target })); |
| 36 | 36 | macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target })); |
| 37 | macho_step.dependOn(testTls(b, .{ .target = default_target })); | |
| 37 | 38 | macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target })); |
| 38 | 39 | |
| 39 | 40 | // Tests requiring presence of macOS SDK in system path |
| ... | ... | @@ -673,6 +674,40 @@ fn testThunks(b: *Build, opts: Options) *Step { |
| 673 | 674 | return test_step; |
| 674 | 675 | } |
| 675 | 676 | |
| 677 | fn testTls(b: *Build, opts: Options) *Step { | |
| 678 | const test_step = addTestStep(b, "macho-tls", opts); | |
| 679 | ||
| 680 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | |
| 681 | \\_Thread_local int a; | |
| 682 | \\int getA() { | |
| 683 | \\ return a; | |
| 684 | \\} | |
| 685 | }); | |
| 686 | ||
| 687 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | |
| 688 | \\#include<stdio.h> | |
| 689 | \\extern _Thread_local int a; | |
| 690 | \\extern int getA(); | |
| 691 | \\int getA2() { | |
| 692 | \\ return a; | |
| 693 | \\} | |
| 694 | \\int main() { | |
| 695 | \\ a = 2; | |
| 696 | \\ printf("%d %d %d", a, getA(), getA2()); | |
| 697 | \\ return 0; | |
| 698 | \\} | |
| 699 | }); | |
| 700 | exe.root_module.linkSystemLibrary("a", .{}); | |
| 701 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | |
| 702 | exe.addRPath(dylib.getEmittedBinDirectory()); | |
| 703 | ||
| 704 | const run = addRunArtifact(exe); | |
| 705 | run.expectStdOutEqual("2 2 2"); | |
| 706 | test_step.dependOn(&run.step); | |
| 707 | ||
| 708 | return test_step; | |
| 709 | } | |
| 710 | ||
| 676 | 711 | fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 677 | 712 | const test_step = addTestStep(b, "macho-tls-large-tbss", opts); |
| 678 | 713 |
test/link/macho/tls/a.c deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | _Thread_local int a; | |
| 2 | ||
| 3 | int getA() { | |
| 4 | return a; | |
| 5 | } |
test/link/macho/tls/build.zig deleted-39| ... | ... | @@ -1,39 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const requires_symlinks = true; | |
| 4 | ||
| 5 | pub fn build(b: *std.Build) void { | |
| 6 | const test_step = b.step("test", "Test it"); | |
| 7 | b.default_step = test_step; | |
| 8 | ||
| 9 | add(b, test_step, .Debug); | |
| 10 | add(b, test_step, .ReleaseFast); | |
| 11 | add(b, test_step, .ReleaseSmall); | |
| 12 | add(b, test_step, .ReleaseSafe); | |
| 13 | } | |
| 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | ||
| 18 | const lib = b.addSharedLibrary(.{ | |
| 19 | .name = "a", | |
| 20 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | |
| 21 | .optimize = optimize, | |
| 22 | .target = target, | |
| 23 | }); | |
| 24 | lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | |
| 25 | lib.linkLibC(); | |
| 26 | ||
| 27 | const test_exe = b.addTest(.{ | |
| 28 | .root_source_file = .{ .path = "main.zig" }, | |
| 29 | .optimize = optimize, | |
| 30 | .target = target, | |
| 31 | }); | |
| 32 | test_exe.linkLibrary(lib); | |
| 33 | test_exe.linkLibC(); | |
| 34 | ||
| 35 | const run = b.addRunArtifact(test_exe); | |
| 36 | run.skip_foreign_checks = true; | |
| 37 | ||
| 38 | test_step.dependOn(&run.step); | |
| 39 | } |
test/link/macho/tls/main.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | extern threadlocal var a: i32; | |
| 4 | extern fn getA() i32; | |
| 5 | ||
| 6 | fn getA2() i32 { | |
| 7 | return a; | |
| 8 | } | |
| 9 | ||
| 10 | test { | |
| 11 | a = 2; | |
| 12 | try std.testing.expect(getA() == 2); | |
| 13 | try std.testing.expect(2 == getA2()); | |
| 14 | try std.testing.expect(getA() == getA2()); | |
| 15 | } |