authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-29 15:42:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-08 19:37:29-07:00
log2c317b2cbafe4f91fca66ee20f45197bbbd26353
tree6bece787765a43382efc03849234ef0e9ec9670c
parentb018f2bae189cbcf2476b4147b108b815af149bc

libcxx, libtsan, libunwind: fix error reporting

use a consistent error set to avoid failure when bootstrapping from zig1

3 files changed, 139 insertions(+), 31 deletions(-)

src/libcxx.zig+84-16
...@@ -107,7 +107,13 @@ const libcxx_files = [_][]const u8{...@@ -107,7 +107,13 @@ const libcxx_files = [_][]const u8{
107 "src/verbose_abort.cpp",107 "src/verbose_abort.cpp",
108};108};
109109
110pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {110pub const BuildError = error{
111 OutOfMemory,
112 SubCompilationFailed,
113 ZigCompilerNotBuiltWithLLVMExtensions,
114};
115
116pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
111 if (!build_options.have_llvm) {117 if (!build_options.have_llvm) {
112 return error.ZigCompilerNotBuiltWithLLVMExtensions;118 return error.ZigCompilerNotBuiltWithLLVMExtensions;
113 }119 }
...@@ -148,7 +154,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -148,7 +154,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
148 const optimize_mode = comp.compilerRtOptMode();154 const optimize_mode = comp.compilerRtOptMode();
149 const strip = comp.compilerRtStrip();155 const strip = comp.compilerRtStrip();
150156
151 const config = try Compilation.Config.resolve(.{157 const config = Compilation.Config.resolve(.{
152 .output_mode = output_mode,158 .output_mode = output_mode,
153 .link_mode = link_mode,159 .link_mode = link_mode,
154 .resolved_target = comp.root_mod.resolved_target,160 .resolved_target = comp.root_mod.resolved_target,
...@@ -160,9 +166,16 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -160,9 +166,16 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
160 .link_libc = true,166 .link_libc = true,
161 .lto = comp.config.lto,167 .lto = comp.config.lto,
162 .any_sanitize_thread = comp.config.any_sanitize_thread,168 .any_sanitize_thread = comp.config.any_sanitize_thread,
163 });169 }) catch |err| {
170 comp.setMiscFailure(
171 .libcxx,
172 "unable to build libc++: resolving configuration failed: {s}",
173 .{@errorName(err)},
174 );
175 return error.SubCompilationFailed;
176 };
164177
165 const root_mod = try Module.create(arena, .{178 const root_mod = Module.create(arena, .{
166 .global_cache_directory = comp.global_cache_directory,179 .global_cache_directory = comp.global_cache_directory,
167 .paths = .{180 .paths = .{
168 .root = .{ .root_dir = comp.zig_lib_directory },181 .root = .{ .root_dir = comp.zig_lib_directory },
...@@ -188,7 +201,14 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -188,7 +201,14 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
188 .parent = null,201 .parent = null,
189 .builtin_mod = null,202 .builtin_mod = null,
190 .builtin_modules = null, // there is only one module in this compilation203 .builtin_modules = null, // there is only one module in this compilation
191 });204 }) catch |err| {
205 comp.setMiscFailure(
206 .libcxx,
207 "unable to build libc++: creating module failed: {s}",
208 .{@errorName(err)},
209 );
210 return error.SubCompilationFailed;
211 };
192212
193 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);213 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);
194214
...@@ -288,7 +308,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -288,7 +308,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
288 });308 });
289 }309 }
290310
291 const sub_compilation = try Compilation.create(comp.gpa, arena, .{311 const sub_compilation = Compilation.create(comp.gpa, arena, .{
292 .local_cache_directory = comp.global_cache_directory,312 .local_cache_directory = comp.global_cache_directory,
293 .global_cache_directory = comp.global_cache_directory,313 .global_cache_directory = comp.global_cache_directory,
294 .zig_lib_directory = comp.zig_lib_directory,314 .zig_lib_directory = comp.zig_lib_directory,
...@@ -311,16 +331,33 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -311,16 +331,33 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
311 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,331 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
312 .clang_passthrough_mode = comp.clang_passthrough_mode,332 .clang_passthrough_mode = comp.clang_passthrough_mode,
313 .skip_linker_dependencies = true,333 .skip_linker_dependencies = true,
314 });334 }) catch |err| {
335 comp.setMiscFailure(
336 .libcxx,
337 "unable to build libc++: create compilation failed: {s}",
338 .{@errorName(err)},
339 );
340 return error.SubCompilationFailed;
341 };
315 defer sub_compilation.destroy();342 defer sub_compilation.destroy();
316343
317 try comp.updateSubCompilation(sub_compilation, .libcxx, prog_node);344 comp.updateSubCompilation(sub_compilation, .libcxx, prog_node) catch |err| switch (err) {
345 error.SubCompilationFailed => return error.SubCompilationFailed,
346 else => |e| {
347 comp.setMiscFailure(
348 .libcxx,
349 "unable to build libc++: compilation failed: {s}",
350 .{@errorName(e)},
351 );
352 return error.SubCompilationFailed;
353 },
354 };
318355
319 assert(comp.libcxx_static_lib == null);356 assert(comp.libcxx_static_lib == null);
320 comp.libcxx_static_lib = try sub_compilation.toCrtFile();357 comp.libcxx_static_lib = try sub_compilation.toCrtFile();
321}358}
322359
323pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {360pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
324 if (!build_options.have_llvm) {361 if (!build_options.have_llvm) {
325 return error.ZigCompilerNotBuiltWithLLVMExtensions;362 return error.ZigCompilerNotBuiltWithLLVMExtensions;
326 }363 }
...@@ -362,7 +399,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -362,7 +399,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
362 const strip = comp.compilerRtStrip();399 const strip = comp.compilerRtStrip();
363 const unwind_tables = true;400 const unwind_tables = true;
364401
365 const config = try Compilation.Config.resolve(.{402 const config = Compilation.Config.resolve(.{
366 .output_mode = output_mode,403 .output_mode = output_mode,
367 .link_mode = link_mode,404 .link_mode = link_mode,
368 .resolved_target = comp.root_mod.resolved_target,405 .resolved_target = comp.root_mod.resolved_target,
...@@ -375,9 +412,16 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -375,9 +412,16 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
375 .any_unwind_tables = unwind_tables,412 .any_unwind_tables = unwind_tables,
376 .lto = comp.config.lto,413 .lto = comp.config.lto,
377 .any_sanitize_thread = comp.config.any_sanitize_thread,414 .any_sanitize_thread = comp.config.any_sanitize_thread,
378 });415 }) catch |err| {
416 comp.setMiscFailure(
417 .libcxxabi,
418 "unable to build libc++abi: resolving configuration failed: {s}",
419 .{@errorName(err)},
420 );
421 return error.SubCompilationFailed;
422 };
379423
380 const root_mod = try Module.create(arena, .{424 const root_mod = Module.create(arena, .{
381 .global_cache_directory = comp.global_cache_directory,425 .global_cache_directory = comp.global_cache_directory,
382 .paths = .{426 .paths = .{
383 .root = .{ .root_dir = comp.zig_lib_directory },427 .root = .{ .root_dir = comp.zig_lib_directory },
...@@ -404,7 +448,14 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -404,7 +448,14 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
404 .parent = null,448 .parent = null,
405 .builtin_mod = null,449 .builtin_mod = null,
406 .builtin_modules = null, // there is only one module in this compilation450 .builtin_modules = null, // there is only one module in this compilation
407 });451 }) catch |err| {
452 comp.setMiscFailure(
453 .libcxxabi,
454 "unable to build libc++abi: creating module failed: {s}",
455 .{@errorName(err)},
456 );
457 return error.SubCompilationFailed;
458 };
408459
409 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);460 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);
410461
...@@ -487,7 +538,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -487,7 +538,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
487 });538 });
488 }539 }
489540
490 const sub_compilation = try Compilation.create(comp.gpa, arena, .{541 const sub_compilation = Compilation.create(comp.gpa, arena, .{
491 .local_cache_directory = comp.global_cache_directory,542 .local_cache_directory = comp.global_cache_directory,
492 .global_cache_directory = comp.global_cache_directory,543 .global_cache_directory = comp.global_cache_directory,
493 .zig_lib_directory = comp.zig_lib_directory,544 .zig_lib_directory = comp.zig_lib_directory,
...@@ -510,10 +561,27 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -510,10 +561,27 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
510 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,561 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
511 .clang_passthrough_mode = comp.clang_passthrough_mode,562 .clang_passthrough_mode = comp.clang_passthrough_mode,
512 .skip_linker_dependencies = true,563 .skip_linker_dependencies = true,
513 });564 }) catch |err| {
565 comp.setMiscFailure(
566 .libcxxabi,
567 "unable to build libc++abi: create compilation failed: {s}",
568 .{@errorName(err)},
569 );
570 return error.SubCompilationFailed;
571 };
514 defer sub_compilation.destroy();572 defer sub_compilation.destroy();
515573
516 try comp.updateSubCompilation(sub_compilation, .libcxxabi, prog_node);574 comp.updateSubCompilation(sub_compilation, .libcxxabi, prog_node) catch |err| switch (err) {
575 error.SubCompilationFailed => return error.SubCompilationFailed,
576 else => |e| {
577 comp.setMiscFailure(
578 .libcxxabi,
579 "unable to build libc++abi: compilation failed: {s}",
580 .{@errorName(e)},
581 );
582 return error.SubCompilationFailed;
583 },
584 };
517585
518 assert(comp.libcxxabi_static_lib == null);586 assert(comp.libcxxabi_static_lib == null);
519 comp.libcxxabi_static_lib = try sub_compilation.toCrtFile();587 comp.libcxxabi_static_lib = try sub_compilation.toCrtFile();
src/libtsan.zig+10-7
...@@ -305,13 +305,16 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!v...@@ -305,13 +305,16 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!v
305 };305 };
306 defer sub_compilation.destroy();306 defer sub_compilation.destroy();
307307
308 comp.updateSubCompilation(sub_compilation, .libtsan, prog_node) catch |err| {308 comp.updateSubCompilation(sub_compilation, .libtsan, prog_node) catch |err| switch (err) {
309 comp.setMiscFailure(309 error.SubCompilationFailed => return error.SubCompilationFailed,
310 .libtsan,310 else => |e| {
311 "unable to build thread sanitizer runtime: compilation failed: {s}",311 comp.setMiscFailure(
312 .{@errorName(err)},312 .libtsan,
313 );313 "unable to build thread sanitizer runtime: compilation failed: {s}",
314 return error.SubCompilationFailed;314 .{@errorName(e)},
315 );
316 return error.SubCompilationFailed;
317 },
315 };318 };
316319
317 assert(comp.tsan_static_lib == null);320 assert(comp.tsan_static_lib == null);
src/libunwind.zig+45-8
...@@ -8,7 +8,13 @@ const Module = @import("Package/Module.zig");...@@ -8,7 +8,13 @@ const Module = @import("Package/Module.zig");
8const build_options = @import("build_options");8const build_options = @import("build_options");
9const trace = @import("tracy.zig").trace;9const trace = @import("tracy.zig").trace;
1010
11pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {11pub const BuildError = error{
12 OutOfMemory,
13 SubCompilationFailed,
14 ZigCompilerNotBuiltWithLLVMExtensions,
15};
16
17pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
12 if (!build_options.have_llvm) {18 if (!build_options.have_llvm) {
13 return error.ZigCompilerNotBuiltWithLLVMExtensions;19 return error.ZigCompilerNotBuiltWithLLVMExtensions;
14 }20 }
...@@ -21,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -21,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
21 const arena = arena_allocator.allocator();27 const arena = arena_allocator.allocator();
2228
23 const output_mode = .Lib;29 const output_mode = .Lib;
24 const config = try Compilation.Config.resolve(.{30 const config = Compilation.Config.resolve(.{
25 .output_mode = .Lib,31 .output_mode = .Lib,
26 .resolved_target = comp.root_mod.resolved_target,32 .resolved_target = comp.root_mod.resolved_target,
27 .is_test = false,33 .is_test = false,
...@@ -32,8 +38,15 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -32,8 +38,15 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
32 .link_libc = true,38 .link_libc = true,
33 // Disable LTO to avoid https://github.com/llvm/llvm-project/issues/5682539 // Disable LTO to avoid https://github.com/llvm/llvm-project/issues/56825
34 .lto = false,40 .lto = false,
35 });41 }) catch |err| {
36 const root_mod = try Module.create(arena, .{42 comp.setMiscFailure(
43 .libunwind,
44 "unable to build libunwind: resolving configuration failed: {s}",
45 .{@errorName(err)},
46 );
47 return error.SubCompilationFailed;
48 };
49 const root_mod = Module.create(arena, .{
37 .global_cache_directory = comp.global_cache_directory,50 .global_cache_directory = comp.global_cache_directory,
38 .paths = .{51 .paths = .{
39 .root = .{ .root_dir = comp.zig_lib_directory },52 .root = .{ .root_dir = comp.zig_lib_directory },
...@@ -59,7 +72,14 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -59,7 +72,14 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
59 .parent = null,72 .parent = null,
60 .builtin_mod = null,73 .builtin_mod = null,
61 .builtin_modules = null, // there is only one module in this compilation74 .builtin_modules = null, // there is only one module in this compilation
62 });75 }) catch |err| {
76 comp.setMiscFailure(
77 .libunwind,
78 "unable to build libunwind: creating module failed: {s}",
79 .{@errorName(err)},
80 );
81 return error.SubCompilationFailed;
82 };
6383
64 const root_name = "unwind";84 const root_name = "unwind";
65 const link_mode = .static;85 const link_mode = .static;
...@@ -124,7 +144,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -124,7 +144,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
124 .owner = root_mod,144 .owner = root_mod,
125 };145 };
126 }146 }
127 const sub_compilation = try Compilation.create(comp.gpa, arena, .{147 const sub_compilation = Compilation.create(comp.gpa, arena, .{
128 .self_exe_path = comp.self_exe_path,148 .self_exe_path = comp.self_exe_path,
129 .local_cache_directory = comp.global_cache_directory,149 .local_cache_directory = comp.global_cache_directory,
130 .global_cache_directory = comp.global_cache_directory,150 .global_cache_directory = comp.global_cache_directory,
...@@ -148,10 +168,27 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -148,10 +168,27 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
148 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,168 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
149 .clang_passthrough_mode = comp.clang_passthrough_mode,169 .clang_passthrough_mode = comp.clang_passthrough_mode,
150 .skip_linker_dependencies = true,170 .skip_linker_dependencies = true,
151 });171 }) catch |err| {
172 comp.setMiscFailure(
173 .libunwind,
174 "unable to build libunwind: create compilation failed: {s}",
175 .{@errorName(err)},
176 );
177 return error.SubCompilationFailed;
178 };
152 defer sub_compilation.destroy();179 defer sub_compilation.destroy();
153180
154 try comp.updateSubCompilation(sub_compilation, .libunwind, prog_node);181 comp.updateSubCompilation(sub_compilation, .libunwind, prog_node) catch |err| switch (err) {
182 error.SubCompilationFailed => return error.SubCompilationFailed,
183 else => |e| {
184 comp.setMiscFailure(
185 .libunwind,
186 "unable to build libunwind: compilation failed: {s}",
187 .{@errorName(e)},
188 );
189 return error.SubCompilationFailed;
190 },
191 };
155192
156 assert(comp.libunwind_static_lib == null);193 assert(comp.libunwind_static_lib == null);
157 comp.libunwind_static_lib = try sub_compilation.toCrtFile();194 comp.libunwind_static_lib = try sub_compilation.toCrtFile();