| ... | @@ -72,6 +72,57 @@ pub fn addCases(ctx: *LinkContext) void { | ... | @@ -72,6 +72,57 @@ pub fn addCases(ctx: *LinkContext) void { |
| 72 | run.addCheck(.{ .expect_term = .{ .exited = 0 } }); | 72 | run.addCheck(.{ .expect_term = .{ .exited = 0 } }); |
| 73 | } | 73 | } |
| 74 | | 74 | |
| | 75 | if (ctx.includeTest("tls")) |case| { |
| | 76 | const obj = case.addObject(.{ |
| | 77 | .name = "obj", |
| | 78 | .zig_source_bytes = |
| | 79 | \\threadlocal var threadlocal_var: u32 = 1234; |
| | 80 | \\threadlocal var threadlocal_arr: [4]u16 = .{ 0x1111, 0x2222, 0x3333, 0x4444, }; |
| | 81 | \\export fn threadlocal_read(a: *u32, b: *u16) void { |
| | 82 | \\ a.* = threadlocal_var; |
| | 83 | \\ b.* = threadlocal_arr[3]; |
| | 84 | \\} |
| | 85 | \\export fn threadlocal_write(a: u32, b: u16) void { |
| | 86 | \\ threadlocal_var = a; |
| | 87 | \\ threadlocal_arr[3] = b; |
| | 88 | \\} |
| | 89 | , |
| | 90 | }); |
| | 91 | |
| | 92 | case.verifyObjdump(obj.getEmittedBin(), &.{ |
| | 93 | "-s", |
| | 94 | "--symbols", |
| | 95 | "--only-symbol=threadlocal", |
| | 96 | "--only-symbol=tls", |
| | 97 | }, .{}); |
| | 98 | |
| | 99 | const exe = case.addExecutable(.{ |
| | 100 | .name = "test", |
| | 101 | .zig_source_bytes = |
| | 102 | \\extern fn threadlocal_read(a: *u32, b: *u16) void; |
| | 103 | \\extern fn threadlocal_write(a: u32, b: u16) void; |
| | 104 | \\threadlocal var threadlocal_foo: u64 = 0xcafecafecafecafe; |
| | 105 | \\pub fn main() !u8 { |
| | 106 | \\ var a: u32 = undefined; |
| | 107 | \\ var b: u16 = undefined; |
| | 108 | \\ threadlocal_read(&a, &b); |
| | 109 | \\ if (a != 1234 or b != 0x4444) return 1; |
| | 110 | \\ if (threadlocal_foo != 0xcafecafecafecafe) return 2; |
| | 111 | \\ threadlocal_write(0xabcdabcd, 0x5555); |
| | 112 | \\ threadlocal_foo = 1; |
| | 113 | \\ threadlocal_read(&a, &b); |
| | 114 | \\ if (a != 0xabcdabcd or b != 0x5555) return 3; |
| | 115 | \\ if (threadlocal_foo != 1) return 4; |
| | 116 | \\ return 0; |
| | 117 | \\} |
| | 118 | , |
| | 119 | }); |
| | 120 | exe.root_module.addObject(obj); |
| | 121 | |
| | 122 | const run = case.addRunArtifact(exe); |
| | 123 | run.addCheck(.{ .expect_term = .{ .exited = 0 } }); |
| | 124 | } |
| | 125 | |
| 75 | if (ctx.includeTest("dynamic-lib-code")) |case| { | 126 | if (ctx.includeTest("dynamic-lib-code")) |case| { |
| 76 | const lib = case.addLibrary(.dynamic, .{ | 127 | const lib = case.addLibrary(.dynamic, .{ |
| 77 | .name = "lib", | 128 | .name = "lib", |