Skip to content

Commit

Permalink
elf: add static TLS test
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 10, 2023
1 parent da9cc0c commit 38d59fb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <stdio.h>
\\_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" });
Expand Down

0 comments on commit 38d59fb

Please sign in to comment.