@@ -72,6 +72,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
7272 macho_step .dependOn (testSearchStrategy (b , .{ .target = default_target }));
7373 macho_step .dependOn (testTbdv3 (b , .{ .target = default_target }));
7474 macho_step .dependOn (testTls (b , .{ .target = default_target }));
75+ macho_step .dependOn (testTlsPointers (b , .{ .target = default_target }));
7576 macho_step .dependOn (testTwoLevelNamespace (b , .{ .target = default_target }));
7677 macho_step .dependOn (testWeakLibrary (b , .{ .target = default_target }));
7778
@@ -1654,6 +1655,71 @@ fn testTls(b: *Build, opts: Options) *Step {
16541655 return test_step ;
16551656}
16561657
1658+ // https://github.com/ziglang/zig/issues/19221
1659+ fn testTlsPointers (b : * Build , opts : Options ) * Step {
1660+ const test_step = addTestStep (b , "tls-pointers" , opts );
1661+
1662+ const foo_h = foo_h : {
1663+ const wf = WriteFile .create (b );
1664+ break :foo_h wf .add ("foo.h" ,
1665+ \\template<typename just4fun>
1666+ \\struct Foo {
1667+ \\
1668+ \\public:
1669+ \\ static int getVar() {
1670+ \\ static int thread_local var = 0;
1671+ \\ ++var;
1672+ \\ return var;
1673+ \\}
1674+ \\};
1675+ );
1676+ };
1677+
1678+ const bar_o = addObject (b , opts , .{ .name = "bar" , .cpp_source_bytes =
1679+ \\#include "foo.h"
1680+ \\int bar() {
1681+ \\ int v1 = Foo<int>::getVar();
1682+ \\ return v1;
1683+ \\}
1684+ });
1685+ bar_o .root_module .addIncludePath (foo_h .dirname ());
1686+ bar_o .linkLibCpp ();
1687+
1688+ const baz_o = addObject (b , opts , .{ .name = "baz" , .cpp_source_bytes =
1689+ \\#include "foo.h"
1690+ \\int baz() {
1691+ \\ int v1 = Foo<unsigned>::getVar();
1692+ \\ return v1;
1693+ \\}
1694+ });
1695+ baz_o .root_module .addIncludePath (foo_h .dirname ());
1696+ baz_o .linkLibCpp ();
1697+
1698+ const main_o = addObject (b , opts , .{ .name = "main" , .cpp_source_bytes =
1699+ \\extern int bar();
1700+ \\extern int baz();
1701+ \\int main() {
1702+ \\ int v1 = bar();
1703+ \\ int v2 = baz();
1704+ \\ return v1 != v2;
1705+ \\}
1706+ });
1707+ main_o .root_module .addIncludePath (foo_h .dirname ());
1708+ main_o .linkLibCpp ();
1709+
1710+ const exe = addExecutable (b , opts , .{ .name = "main" });
1711+ exe .addObject (bar_o );
1712+ exe .addObject (baz_o );
1713+ exe .addObject (main_o );
1714+ exe .linkLibCpp ();
1715+
1716+ const run = addRunArtifact (exe );
1717+ run .expectExitCode (0 );
1718+ test_step .dependOn (& run .step );
1719+
1720+ return test_step ;
1721+ }
1722+
16571723fn testTlsLargeTbss (b : * Build , opts : Options ) * Step {
16581724 const test_step = addTestStep (b , "tls-large-tbss" , opts );
16591725
0 commit comments