diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-30 08:43:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-30 08:43:33 +0200 |
| commit | 873c695c41dffd89ba7ef1b3ed6662e429bfa00d (patch) | |
| tree | b2131a824259cf307d2e626b0f38941336af97a8 /test | |
| parent | 101df768a06ef85753efdd6dc558bca68d50d1a5 (diff) | |
| parent | e72fd185e01aac14d7962f2eeb718653dc0c8e68 (diff) | |
| download | zig-873c695c41dffd89ba7ef1b3ed6662e429bfa00d.tar.gz zig-873c695c41dffd89ba7ef1b3ed6662e429bfa00d.zip | |
Merge pull request #17319 from ziglang/elf-tls
elf: add basic TLS segment handling
Diffstat (limited to 'test')
| -rw-r--r-- | test/link/elf.zig | 45 | ||||
| -rw-r--r-- | test/tests.zig | 13 |
2 files changed, 53 insertions, 5 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index a5b57e7b93..4748746cc9 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -18,7 +18,8 @@ pub fn build(b: *Build) void { // Exercise linker with LLVM backend elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target })); elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); - elf_step.dependOn(testLinkingZig(b, .{})); + elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); + elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); } fn testEmptyObject(b: *Build, opts: Options) *Step { @@ -91,6 +92,37 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { return test_step; } +fn testTlsStatic(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "tls-static", opts); + + const exe = addExecutable(b, opts); + addCSourceBytes(exe, + \\#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; + \\} + ); + exe.is_linking_libc = true; + + const run = addRunArtifact(exe); + run.expectStdOutEqual( + \\10 0 a + \\11 1 b + \\ + ); + test_step.dependOn(&run.step); + + return test_step; +} + const Options = struct { target: CrossTarget = .{ .cpu_arch = .x86_64, .os_tag = .linux }, optimize: std.builtin.OptimizeMode = .Debug, @@ -114,7 +146,6 @@ fn addExecutable(b: *Build, opts: Options) *Compile { .name = "test", .target = opts.target, .optimize = opts.optimize, - .single_threaded = true, // TODO temp until we teach linker how to handle TLS .use_llvm = opts.use_llvm, .use_lld = false, }); @@ -127,19 +158,25 @@ fn addRunArtifact(comp: *Compile) *Run { return run; } -fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { +fn addZigSourceBytes(comp: *Compile, comptime bytes: []const u8) void { const b = comp.step.owner; const file = WriteFile.create(b).add("a.zig", bytes); file.addStepDependencies(&comp.step); comp.root_src = file; } -fn addCSourceBytes(comp: *Compile, bytes: []const u8) void { +fn addCSourceBytes(comp: *Compile, comptime bytes: []const u8) void { const b = comp.step.owner; const file = WriteFile.create(b).add("a.c", bytes); comp.addCSourceFile(.{ .file = file, .flags = &.{} }); } +fn addAsmSourceBytes(comp: *Compile, comptime bytes: []const u8) void { + const b = comp.step.owner; + const file = WriteFile.create(b).add("a.s", bytes ++ "\n"); + comp.addAssemblyFile(file); +} + const std = @import("std"); const Build = std.Build; diff --git a/test/tests.zig b/test/tests.zig index 03a5c67895..cc0d8e9b6a 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -196,6 +196,15 @@ const test_targets = blk: { }, .link_libc = true, }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + .use_lld = false, + }, .{ .target = .{ @@ -1031,6 +1040,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { "-selfhosted" else ""; + const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; these_tests.addIncludePath(.{ .path = "test" }); @@ -1039,13 +1049,14 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { these_tests.stack_size = 2 * 1024 * 1024; } - const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}", .{ + const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}", .{ options.name, triple_txt, @tagName(test_target.optimize_mode), libc_suffix, single_threaded_suffix, backend_suffix, + use_lld, }); if (test_target.target.ofmt == std.Target.ObjectFormat.c) { |
