Skip to content

Commit 662303d

Browse files
authored
Merge pull request #24734 from Rexicon226/tsan-fix
2 parents dd4e25c + 20486c4 commit 662303d

File tree

7 files changed

+76
-28
lines changed

7 files changed

+76
-28
lines changed

lib/libtsan/sanitizer_common/sanitizer_common_interceptors_ioctl.inc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ extern unsigned struct_hd_geometry_sz;
10431043
extern unsigned struct_input_absinfo_sz;
10441044
extern unsigned struct_input_id_sz;
10451045
extern unsigned struct_mtpos_sz;
1046-
extern unsigned struct_termio_sz;
10471046
extern unsigned struct_vt_consize_sz;
10481047
extern unsigned struct_vt_sizes_sz;
10491048
extern unsigned struct_vt_stat_sz;

src/link/Elf/synthetic_sections.zig

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ 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 => {
391391
if (symbol.?.flags.import) {
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const std = @import("std");
2+
3+
pub 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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {}

0 commit comments

Comments
 (0)