diff --git a/test/elf.zig b/test/elf.zig index a63fceeb..0e47516e 100644 --- a/test/elf.zig +++ b/test/elf.zig @@ -10,6 +10,7 @@ pub fn addElfTests(b: *Build, opts: Options) *Step { elf_step.dependOn(testIfuncDynamic(b, opts)); elf_step.dependOn(testHelloDynamic(b, opts)); elf_step.dependOn(testHelloStatic(b, opts)); + elf_step.dependOn(testTlsStatic(b, opts)); } return elf_step; @@ -264,6 +265,42 @@ fn testHelloDynamic(b: *Build, opts: Options) *Step { return test_step; } +fn testTlsStatic(b: *Build, opts: Options) *Step { + const test_step = b.step("test-elf-tls-static", ""); + + if (!opts.has_static) { + skipTestStep(test_step); + return test_step; + } + + const exe = cc(b, null, opts); + exe.addSourceBytes( + \\#include + \\_Thread_local int a = 10; + \\_Thread_local int b; + \\_Thread_local char c = 'a'; + \\int main(int argc, char* argv[]) { + \\ printf("%d %d %c\n", a, b, c); + \\ a += 1; + \\ b += 1; + \\ c += 1; + \\ printf("%d %d %c\n", a, b, c); + \\ return 0; + \\} + , "main.c"); + exe.addArg("-static"); + + const run = exe.run(); + run.expectStdOutEqual( + \\10 0 a + \\11 1 b + \\ + ); + test_step.dependOn(run.step()); + + return test_step; +} + fn cc(b: *Build, name: ?[]const u8, opts: Options) SysCmd { const cmd = Run.create(b, "cc"); cmd.addArgs(&.{ "cc", "-fno-lto" });