authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-10 09:30:24-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-10 09:30:24-08:00
log71e7bef2a2731dbffc6a3673538bb4c678be4757
treee840d617af906f6a02158f2967216c1ba357bf86
parent798c68d5a5bb2ac971093306212950bcb7043c78

tsan: use explicit error set

Fixes fail to build from source when LLVM not linked.

1 files changed, 43 insertions(+), 8 deletions(-)

src/libtsan.zig+43-8
......@@ -6,7 +6,14 @@ const build_options = @import("build_options");
66const trace = @import("tracy.zig").trace;
77const Module = @import("Package/Module.zig");
88
9pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
9pub const BuildError = error{
10 OutOfMemory,
11 SubCompilationFailed,
12 ZigCompilerNotBuiltWithLLVMExtensions,
13 TSANUnsupportedCPUArchitecture,
14};
15
16pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
1017 if (!build_options.have_llvm) {
1118 return error.ZigCompilerNotBuiltWithLLVMExtensions;
1219 }
......@@ -37,7 +44,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
3744 const optimize_mode = comp.compilerRtOptMode();
3845 const strip = comp.compilerRtStrip();
3946
40 const config = try Compilation.Config.resolve(.{
47 const config = Compilation.Config.resolve(.{
4148 .output_mode = output_mode,
4249 .link_mode = link_mode,
4350 .resolved_target = comp.root_mod.resolved_target,
......@@ -47,13 +54,20 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
4754 .root_optimize_mode = optimize_mode,
4855 .root_strip = strip,
4956 .link_libc = true,
50 });
57 }) catch |err| {
58 comp.setMiscFailure(
59 .libtsan,
60 "unable to build thread sanitizer runtime: resolving configuration failed: {s}",
61 .{@errorName(err)},
62 );
63 return error.SubCompilationFailed;
64 };
5165
5266 const common_flags = [_][]const u8{
5367 "-DTSAN_CONTAINS_UBSAN=0",
5468 };
5569
56 const root_mod = try Module.create(arena, .{
70 const root_mod = Module.create(arena, .{
5771 .global_cache_directory = comp.global_cache_directory,
5872 .paths = .{
5973 .root = .{ .root_dir = comp.zig_lib_directory },
......@@ -78,7 +92,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
7892 .cc_argv = &common_flags,
7993 .parent = null,
8094 .builtin_mod = null,
81 });
95 }) catch |err| {
96 comp.setMiscFailure(
97 .libtsan,
98 "unable to build thread sanitizer runtime: creating module failed: {s}",
99 .{@errorName(err)},
100 );
101 return error.SubCompilationFailed;
102 };
82103
83104 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
84105 try c_source_files.ensureUnusedCapacity(tsan_sources.len);
......@@ -250,7 +271,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
250271 });
251272 }
252273
253 const sub_compilation = try Compilation.create(comp.gpa, arena, .{
274 const sub_compilation = Compilation.create(comp.gpa, arena, .{
254275 .local_cache_directory = comp.global_cache_directory,
255276 .global_cache_directory = comp.global_cache_directory,
256277 .zig_lib_directory = comp.zig_lib_directory,
......@@ -273,10 +294,24 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
273294 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
274295 .clang_passthrough_mode = comp.clang_passthrough_mode,
275296 .skip_linker_dependencies = true,
276 });
297 }) catch |err| {
298 comp.setMiscFailure(
299 .libtsan,
300 "unable to build thread sanitizer runtime: create compilation failed: {s}",
301 .{@errorName(err)},
302 );
303 return error.SubCompilationFailed;
304 };
277305 defer sub_compilation.destroy();
278306
279 try comp.updateSubCompilation(sub_compilation, .libtsan, prog_node);
307 comp.updateSubCompilation(sub_compilation, .libtsan, prog_node) catch |err| {
308 comp.setMiscFailure(
309 .libtsan,
310 "unable to build thread sanitizer runtime: compilation failed: {s}",
311 .{@errorName(err)},
312 );
313 return error.SubCompilationFailed;
314 };
280315
281316 assert(comp.tsan_static_lib == null);
282317 comp.tsan_static_lib = try sub_compilation.toCrtFile();