authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-13 08:57:52+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-13 08:57:52+02:00
log662303d7e74b93c0169c84dcd64b9f7da51ece3a
tree18362931d00f8817a62a67a041ec3522ea984601
parentdd4e25cf4410017cb113c0cb1c85c6e5c75729e3
parent20486c4a8155499db8a26651bb2b1d2886003c33
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24734 from Rexicon226/tsan-fix


7 files changed, 76 insertions(+), 28 deletions(-)

lib/libtsan/sanitizer_common/sanitizer_common_interceptors_ioctl.inc-8
......@@ -338,17 +338,9 @@ static void ioctl_table_fill() {
338338 _(SOUND_PCM_WRITE_CHANNELS, WRITE, sizeof(int));
339339 _(SOUND_PCM_WRITE_FILTER, WRITE, sizeof(int));
340340 _(TCFLSH, NONE, 0);
341#if SANITIZER_GLIBC
342 _(TCGETA, WRITE, struct_termio_sz);
343#endif
344341 _(TCGETS, WRITE, struct_termios_sz);
345342 _(TCSBRK, NONE, 0);
346343 _(TCSBRKP, NONE, 0);
347#if SANITIZER_GLIBC
348 _(TCSETA, READ, struct_termio_sz);
349 _(TCSETAF, READ, struct_termio_sz);
350 _(TCSETAW, READ, struct_termio_sz);
351#endif
352344 _(TCSETS, READ, struct_termios_sz);
353345 _(TCSETSF, READ, struct_termios_sz);
354346 _(TCSETSW, READ, struct_termios_sz);
lib/libtsan/sanitizer_common/sanitizer_platform_limits_posix.cpp-3
......@@ -485,9 +485,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
485485 unsigned struct_input_id_sz = sizeof(struct input_id);
486486 unsigned struct_mtpos_sz = sizeof(struct mtpos);
487487 unsigned struct_rtentry_sz = sizeof(struct rtentry);
488#if SANITIZER_GLIBC || SANITIZER_ANDROID
489 unsigned struct_termio_sz = sizeof(struct termio);
490#endif
491488 unsigned struct_vt_consize_sz = sizeof(struct vt_consize);
492489 unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes);
493490 unsigned struct_vt_stat_sz = sizeof(struct vt_stat);
lib/libtsan/sanitizer_common/sanitizer_platform_limits_posix.h-1
......@@ -1043,7 +1043,6 @@ extern unsigned struct_hd_geometry_sz;
10431043extern unsigned struct_input_absinfo_sz;
10441044extern unsigned struct_input_id_sz;
10451045extern unsigned struct_mtpos_sz;
1046extern unsigned struct_termio_sz;
10471046extern unsigned struct_vt_consize_sz;
10481047extern unsigned struct_vt_sizes_sz;
10491048extern unsigned struct_vt_stat_sz;
src/link/Elf/synthetic_sections.zig+11-16
......@@ -384,7 +384,7 @@ pub const GotSection = struct {
384384 try writeInt(value, elf_file, writer);
385385 },
386386 .tlsld => {
387 try writeInt(if (is_dyn_lib) @as(u64, 0) else 1, elf_file, writer);
387 try writeInt(if (is_dyn_lib) @as(i64, 0) else 1, elf_file, writer);
388388 try writeInt(0, elf_file, writer);
389389 },
390390 .tlsgd => {
......@@ -392,7 +392,7 @@ pub const GotSection = struct {
392392 try writeInt(0, elf_file, writer);
393393 try writeInt(0, elf_file, writer);
394394 } else {
395 try writeInt(if (is_dyn_lib) @as(u64, 0) else 1, elf_file, writer);
395 try writeInt(if (is_dyn_lib) @as(i64, 0) else 1, elf_file, writer);
396396 const offset = symbol.?.address(.{}, elf_file) - elf_file.dtpAddress();
397397 try writeInt(offset, elf_file, writer);
398398 }
......@@ -412,17 +412,12 @@ pub const GotSection = struct {
412412 }
413413 },
414414 .tlsdesc => {
415 if (symbol.?.flags.import) {
416 try writeInt(0, elf_file, writer);
417 try writeInt(0, elf_file, writer);
418 } else {
419 try writeInt(0, elf_file, writer);
420 const offset = if (apply_relocs)
421 symbol.?.address(.{}, elf_file) - elf_file.tlsAddress()
422 else
423 0;
424 try writeInt(offset, elf_file, writer);
425 }
415 try writeInt(0, elf_file, writer);
416 const offset: i64 = if (apply_relocs and !symbol.?.flags.import)
417 symbol.?.address(.{}, elf_file) - elf_file.tlsAddress()
418 else
419 0;
420 try writeInt(offset, elf_file, writer);
426421 },
427422 }
428423 }
......@@ -1505,9 +1500,9 @@ fn writeInt(value: anytype, elf_file: *Elf, writer: anytype) !void {
15051500 const target = elf_file.getTarget();
15061501 const endian = target.cpu.arch.endian();
15071502 switch (entry_size) {
1508 2 => try writer.writeInt(u16, @intCast(value), endian),
1509 4 => try writer.writeInt(u32, @intCast(value), endian),
1510 8 => try writer.writeInt(u64, @intCast(value), endian),
1503 2 => try writer.writeInt(i16, @intCast(value), endian),
1504 4 => try writer.writeInt(i32, @intCast(value), endian),
1505 8 => try writer.writeInt(i64, value, endian),
15111506 else => unreachable,
15121507 }
15131508}
test/standalone/build.zig.zon+3
......@@ -208,6 +208,9 @@
208208 .run_cwd = .{
209209 .path = "run_cwd",
210210 },
211 .tsan = .{
212 .path = "tsan",
213 },
211214 },
212215 .paths = .{
213216 "build.zig",
test/standalone/tsan/build.zig created+59
......@@ -0,0 +1,59 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) !void {
4 const test_step = b.step("test", "Test the program");
5 b.default_step = test_step;
6
7 const is_macos = b.graph.host.result.os.tag == .macos;
8
9 for ([_]struct { std.Target.Os.Tag, []const std.Target.Cpu.Arch }{
10 // .s390x and mips64(el) fail to build
11 .{ .linux, &.{ .aarch64, .aarch64_be, .loongarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
12 .{ .macos, &.{ .x86_64, .aarch64 } },
13
14 // Missing system headers
15 // https://github.com/ziglang/zig/issues/24736
16 // .{ .freebsd, &.{ .aarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
17 // https://github.com/ziglang/zig/issues/24737
18 // .{ .netbsd, &.{ .aarch64, .aarch64_be, .x86_64 } },
19
20 // TSan doesn't have full support for windows yet.
21 // .{ .windows, &.{ .aarch64, .x86_64 } },
22 }) |entry| {
23 switch (entry[0]) {
24 // compiling tsan on macos requires system headers that aren't present during cross-compilation
25 .macos => {
26 if (!is_macos) continue;
27 const target = b.resolveTargetQuery(.{});
28 const exe = b.addExecutable(.{
29 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(target.result.cpu.arch) }),
30 .root_module = b.createModule(.{
31 .root_source_file = b.path("main.zig"),
32 .target = target,
33 .optimize = .Debug,
34 .sanitize_thread = true,
35 }),
36 });
37 const install_exe = b.addInstallArtifact(exe, .{});
38 test_step.dependOn(&install_exe.step);
39 },
40 else => for (entry[1]) |arch| {
41 const target = b.resolveTargetQuery(.{
42 .os_tag = entry[0],
43 .cpu_arch = arch,
44 });
45 const exe = b.addExecutable(.{
46 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }),
47 .root_module = b.createModule(.{
48 .root_source_file = b.path("main.zig"),
49 .target = target,
50 .optimize = .Debug,
51 .sanitize_thread = true,
52 }),
53 });
54 const install_exe = b.addInstallArtifact(exe, .{});
55 test_step.dependOn(&install_exe.step);
56 },
57 }
58 }
59}
test/standalone/tsan/main.zig created+3
......@@ -0,0 +1,3 @@
1const std = @import("std");
2
3pub fn main() !void {}