| ... | @@ -6,7 +6,14 @@ const build_options = @import("build_options"); | ... | @@ -6,7 +6,14 @@ const build_options = @import("build_options"); |
| 6 | const trace = @import("tracy.zig").trace; | 6 | const trace = @import("tracy.zig").trace; |
| 7 | const Module = @import("Package/Module.zig"); | 7 | const Module = @import("Package/Module.zig"); |
| 8 | | 8 | |
| 9 | pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | 9 | pub const BuildError = error{ |
| | 10 | OutOfMemory, |
| | 11 | SubCompilationFailed, |
| | 12 | ZigCompilerNotBuiltWithLLVMExtensions, |
| | 13 | TSANUnsupportedCPUArchitecture, |
| | 14 | }; |
| | 15 | |
| | 16 | pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void { |
| 10 | if (!build_options.have_llvm) { | 17 | if (!build_options.have_llvm) { |
| 11 | return error.ZigCompilerNotBuiltWithLLVMExtensions; | 18 | return error.ZigCompilerNotBuiltWithLLVMExtensions; |
| 12 | } | 19 | } |
| ... | @@ -37,7 +44,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | ... | @@ -37,7 +44,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 37 | const optimize_mode = comp.compilerRtOptMode(); | 44 | const optimize_mode = comp.compilerRtOptMode(); |
| 38 | const strip = comp.compilerRtStrip(); | 45 | const strip = comp.compilerRtStrip(); |
| 39 | | 46 | |
| 40 | const config = try Compilation.Config.resolve(.{ | 47 | const config = Compilation.Config.resolve(.{ |
| 41 | .output_mode = output_mode, | 48 | .output_mode = output_mode, |
| 42 | .link_mode = link_mode, | 49 | .link_mode = link_mode, |
| 43 | .resolved_target = comp.root_mod.resolved_target, | 50 | .resolved_target = comp.root_mod.resolved_target, |
| ... | @@ -47,13 +54,20 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | ... | @@ -47,13 +54,20 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 47 | .root_optimize_mode = optimize_mode, | 54 | .root_optimize_mode = optimize_mode, |
| 48 | .root_strip = strip, | 55 | .root_strip = strip, |
| 49 | .link_libc = true, | 56 | .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 | }; |
| 51 | | 65 | |
| 52 | const common_flags = [_][]const u8{ | 66 | const common_flags = [_][]const u8{ |
| 53 | "-DTSAN_CONTAINS_UBSAN=0", | 67 | "-DTSAN_CONTAINS_UBSAN=0", |
| 54 | }; | 68 | }; |
| 55 | | 69 | |
| 56 | const root_mod = try Module.create(arena, .{ | 70 | const root_mod = Module.create(arena, .{ |
| 57 | .global_cache_directory = comp.global_cache_directory, | 71 | .global_cache_directory = comp.global_cache_directory, |
| 58 | .paths = .{ | 72 | .paths = .{ |
| 59 | .root = .{ .root_dir = comp.zig_lib_directory }, | 73 | .root = .{ .root_dir = comp.zig_lib_directory }, |
| ... | @@ -78,7 +92,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | ... | @@ -78,7 +92,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 78 | .cc_argv = &common_flags, | 92 | .cc_argv = &common_flags, |
| 79 | .parent = null, | 93 | .parent = null, |
| 80 | .builtin_mod = null, | 94 | .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 | }; |
| 82 | | 103 | |
| 83 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); | 104 | var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 84 | try c_source_files.ensureUnusedCapacity(tsan_sources.len); | 105 | try c_source_files.ensureUnusedCapacity(tsan_sources.len); |
| ... | @@ -250,7 +271,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | ... | @@ -250,7 +271,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 250 | }); | 271 | }); |
| 251 | } | 272 | } |
| 252 | | 273 | |
| 253 | const sub_compilation = try Compilation.create(comp.gpa, arena, .{ | 274 | const sub_compilation = Compilation.create(comp.gpa, arena, .{ |
| 254 | .local_cache_directory = comp.global_cache_directory, | 275 | .local_cache_directory = comp.global_cache_directory, |
| 255 | .global_cache_directory = comp.global_cache_directory, | 276 | .global_cache_directory = comp.global_cache_directory, |
| 256 | .zig_lib_directory = comp.zig_lib_directory, | 277 | .zig_lib_directory = comp.zig_lib_directory, |
| ... | @@ -273,10 +294,24 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { | ... | @@ -273,10 +294,24 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 273 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, | 294 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 274 | .clang_passthrough_mode = comp.clang_passthrough_mode, | 295 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 275 | .skip_linker_dependencies = true, | 296 | .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 | }; |
| 277 | defer sub_compilation.destroy(); | 305 | defer sub_compilation.destroy(); |
| 278 | | 306 | |
| 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 | }; |
| 280 | | 315 | |
| 281 | assert(comp.tsan_static_lib == null); | 316 | assert(comp.tsan_static_lib == null); |
| 282 | comp.tsan_static_lib = try sub_compilation.toCrtFile(); | 317 | comp.tsan_static_lib = try sub_compilation.toCrtFile(); |